-
Notifications
You must be signed in to change notification settings - Fork 29
/
parser.go
61 lines (47 loc) · 1.28 KB
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// nmon2influxdb
// author: adejoux@djouxtech.net
package nmon2influxdblib
import (
"fmt"
"regexp"
"strings"
)
//Tags array
type Tags []Tag
// Tag is a struct to store additional tags
type Tag struct {
Name string
Value string
Regexp *regexp.Regexp `toml:",skip"`
}
// TagParsers access struct : TagParsers[mesurement][tag name]
type TagParsers map[string]map[string]Tags
// ParseInputs process user inputs and compile regular expressions
func ParseInputs(inputs Inputs) TagParsers {
tagParsers := make(TagParsers)
for _, input := range inputs {
tagRegexp, RegCompErr := regexp.Compile(input.Match)
if RegCompErr != nil {
fmt.Printf("could not compile Config Input match parameter %s\n", input.Match)
}
var measurements []string
if len(input.Measurement) == 0 {
measurements = []string{"_ALL"}
} else {
measurements = strings.Split(input.Measurement, ",")
}
for _, measurement := range measurements {
// Intialize if empty struct
if _, ok := tagParsers[measurement]; !ok {
tagParsers[measurement] = make(map[string]Tags)
}
tagger := tagParsers[measurement][input.Name]
for _, tag := range input.Tags {
tag.Regexp = tagRegexp
tagger = append(tagger, tag)
}
tagParsers[measurement][input.Name] = tagger
}
}
return tagParsers
}