-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprobe.go
More file actions
65 lines (56 loc) · 1.37 KB
/
probe.go
File metadata and controls
65 lines (56 loc) · 1.37 KB
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
62
63
64
65
package main
import (
"time"
"github.com/Knetic/govaluate"
)
// Check holds final informations about a check of a probes.d file
type Check struct {
Index int
Desc string
If *govaluate.EvaluableExpression
Classes []string
NeededFailures int
NeededSuccesses int
}
// Probe is the final form of probes.d files
type Probe struct {
Name string
Filename string
Disabled bool
Script string
Targets []string
Delay time.Duration
Timeout time.Duration
Arguments string
Defaults map[string]interface{}
Checks []*Check
RunIf *govaluate.EvaluableExpression
}
// MissingDefaults return a slice with names of defaults used in Check 'If'
// expressions and Probe script arguments. The slice length is 0 if no
// missing default were found.
func (probe *Probe) MissingDefaults() []string {
missing := make(map[string]bool)
for _, check := range probe.Checks {
for _, name := range check.If.Vars() {
if IsAllUpper(name) {
continue
}
if _, ok := probe.Defaults[name]; ok != true {
missing[name] = true
}
}
}
vars := StringFindVariables(probe.Arguments)
for _, name := range vars {
if _, ok := probe.Defaults[name]; ok != true {
missing[name] = true
}
}
// map to slice:
var missSlice []string
for key := range missing {
missSlice = append(missSlice, key)
}
return missSlice
}