|
|
|
|
10
|
"gopkg.in/yaml.v2"
|
10
|
"gopkg.in/yaml.v2"
|
11
|
)
|
11
|
)
|
12
|
|
12
|
|
|
|
13
|
+// MailSettings represent the settings used to send email alerts
|
13
|
type MailSettings struct {
|
14
|
type MailSettings struct {
|
14
|
- // Sender of the alert emails
|
|
|
|
|
15
|
+ // Sender of the email alerts
|
15
|
Sender string `yaml:"sender"`
|
16
|
Sender string `yaml:"sender"`
|
16
|
- // Settings to connect to the mail server
|
|
|
|
|
17
|
+ // SMTP represent the settings needed to connect to the mail server
|
17
|
SMTP SMTPSettings `yaml:"smtp"`
|
18
|
SMTP SMTPSettings `yaml:"smtp"`
|
18
|
}
|
19
|
}
|
19
|
|
20
|
|
|
|
21
|
+// SMTPSettings represent the settings needed to connect to the mail server
|
20
|
type SMTPSettings struct {
|
22
|
type SMTPSettings struct {
|
21
|
// Host of the mail server
|
23
|
// Host of the mail server
|
22
|
Host string `yaml:"host"`
|
24
|
Host string `yaml:"host"`
|
|
|
|
|
28
|
Password string `yaml:"password"`
|
30
|
Password string `yaml:"password"`
|
29
|
}
|
31
|
}
|
30
|
|
32
|
|
|
|
33
|
+// ScriptDataSource represent the configuration structure for providing external
|
|
|
34
|
+// data to iterate over. Optional.
|
31
|
type ScriptDataSource struct {
|
35
|
type ScriptDataSource struct {
|
32
|
// Type of the data source (either "plain" or "file")
|
36
|
// Type of the data source (either "plain" or "file")
|
33
|
Source string `yaml:"source"`
|
37
|
Source string `yaml:"source"`
|
|
|
|
|
38
|
Value []string `yaml:"value"`
|
42
|
Value []string `yaml:"value"`
|
39
|
}
|
43
|
}
|
40
|
|
44
|
|
|
|
45
|
+// Script represents an instance of a script.
|
41
|
type Script struct {
|
46
|
type Script struct {
|
42
|
- // An identifying key for the script
|
|
|
|
|
47
|
+ // Key is an identifying key for the script
|
43
|
Key string `yaml:"key"`
|
48
|
Key string `yaml:"key"`
|
44
|
- // The script to run on Warp10
|
|
|
|
|
49
|
+ // Script is the script to run on Warp10
|
45
|
Script string `yaml:"script"`
|
50
|
Script string `yaml:"script"`
|
46
|
- // The type of the value returned by the script
|
|
|
|
|
51
|
+ // Type of the value returned by the script
|
47
|
Type string `yaml:"type"`
|
52
|
Type string `yaml:"type"`
|
48
|
- // Value above which an action is required, only required if the type is
|
|
|
49
|
- // "number"
|
|
|
|
|
53
|
+ // Threshold is the value above which an action is required, only required
|
|
|
54
|
+ // if the type is "number"
|
50
|
Threshold float64 `yaml:"threshold,omitempty"`
|
55
|
Threshold float64 `yaml:"threshold,omitempty"`
|
51
|
- // The action to take (either "http" or "email")
|
|
|
|
|
56
|
+ // Action identifies the action to take (either "http" or "email")
|
52
|
Action string `yaml:"action"`
|
57
|
Action string `yaml:"action"`
|
53
|
- // The action's target
|
|
|
|
|
58
|
+ // Target is the action's target
|
54
|
Target string `yaml:"target"`
|
59
|
Target string `yaml:"target"`
|
55
|
- // The labels that will be mentioned in the email subject, only required if
|
|
|
56
|
- // the action is "email"
|
|
|
|
|
60
|
+ // IdentifyingLabels represents a list of labels that will be mentioned in
|
|
|
61
|
+ // the email subject. Optional.
|
57
|
IdentifyingLabels []string `yaml:"identifying_labels,omitempty"`
|
62
|
IdentifyingLabels []string `yaml:"identifying_labels,omitempty"`
|
58
|
- // Source/value of the data to use in the script
|
|
|
|
|
63
|
+ // ScriptDataSource represents the source/value of the data to use in the script
|
59
|
ScriptDataSource ScriptDataSource `yaml:"script_data,omitempty"`
|
64
|
ScriptDataSource ScriptDataSource `yaml:"script_data,omitempty"`
|
60
|
- // Loaded data
|
|
|
|
|
65
|
+ // ScriptData represents loaded data, which isn't directly filled by parsing
|
|
|
66
|
+ // the configuration file, but rather by reading it from ScriptDataSource
|
61
|
ScriptData map[string][]string
|
67
|
ScriptData map[string][]string
|
62
|
}
|
68
|
}
|
63
|
|
69
|
|
|
|
70
|
+// Config represents the global configuration of the app.
|
64
|
type Config struct {
|
71
|
type Config struct {
|
65
|
- // Settings to send email alerts, only required if the action of at least 1
|
|
|
66
|
- // script is "email"
|
|
|
67
|
- Mail MailSettings `yaml:"mail,omitempty"`
|
|
|
68
|
- // Full URL to Warp10's /exec
|
|
|
|
|
72
|
+ // Mail represents the settings needed to send email alerts. Only required
|
|
|
73
|
+ // if the action of at least 1 script is "email"
|
|
|
74
|
+ Mail *MailSettings `yaml:"mail,omitempty"`
|
|
|
75
|
+ // Warp10Exec represents the full URL to Warp10's /exec
|
69
|
Warp10Exec string `yaml:"warp10_exec"`
|
76
|
Warp10Exec string `yaml:"warp10_exec"`
|
70
|
- // Warp10 read token
|
|
|
|
|
77
|
+ // ReadToken represents Warp10's read token
|
71
|
ReadToken string `yaml:"token"`
|
78
|
ReadToken string `yaml:"token"`
|
72
|
- // WarpScripts to run, with an identifier as its key
|
|
|
|
|
79
|
+ // Script represents the WarpScripts to run
|
73
|
Scripts []Script `yaml:"scripts"`
|
80
|
Scripts []Script `yaml:"scripts"`
|
74
|
}
|
81
|
}
|
75
|
|
82
|
|
|
|
83
|
+// Load parses the configuration file and load external data if needed.
|
|
|
84
|
+// Returns an error if something went wrong when reading or parsing the
|
|
|
85
|
+// configuration file, or reading the external data file if any.
|
76
|
func (cfg *Config) Load(filePath string) (err error) {
|
86
|
func (cfg *Config) Load(filePath string) (err error) {
|
77
|
content, err := ioutil.ReadFile(filePath)
|
87
|
content, err := ioutil.ReadFile(filePath)
|
78
|
if err != nil {
|
88
|
if err != nil {
|