瀏覽代碼

Doc config.go

Brendan Abolivier 7 年之前
父節點
當前提交
65ad79b5cb
簽署人: Brendan Abolivier <contact@brendanabolivier.com> GPG 金鑰 ID: 8EF1500759F70623
共有 1 個文件被更改,包括 29 次插入19 次删除
  1. 29
    19
      src/metrics-alerting/config/config.go

+ 29
- 19
src/metrics-alerting/config/config.go 查看文件

@@ -10,13 +10,15 @@ import (
10 10
 	"gopkg.in/yaml.v2"
11 11
 )
12 12
 
13
+// MailSettings represent the settings used to send email alerts
13 14
 type MailSettings struct {
14
-	// Sender of the alert emails
15
+	// Sender of the email alerts
15 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 18
 	SMTP SMTPSettings `yaml:"smtp"`
18 19
 }
19 20
 
21
+// SMTPSettings represent the settings needed to connect to the mail server
20 22
 type SMTPSettings struct {
21 23
 	// Host of the mail server
22 24
 	Host string `yaml:"host"`
@@ -28,6 +30,8 @@ type SMTPSettings struct {
28 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 35
 type ScriptDataSource struct {
32 36
 	// Type of the data source (either "plain" or "file")
33 37
 	Source string `yaml:"source"`
@@ -38,41 +42,47 @@ type ScriptDataSource struct {
38 42
 	Value []string `yaml:"value"`
39 43
 }
40 44
 
45
+// Script represents an instance of a script.
41 46
 type Script struct {
42
-	// An identifying key for the script
47
+	// Key is an identifying key for the script
43 48
 	Key string `yaml:"key"`
44
-	// The script to run on Warp10
49
+	// Script is the script to run on Warp10
45 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 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 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 57
 	Action string `yaml:"action"`
53
-	// The action's target
58
+	// Target is the action's target
54 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 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 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 67
 	ScriptData map[string][]string
62 68
 }
63 69
 
70
+// Config represents the global configuration of the app.
64 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 76
 	Warp10Exec string `yaml:"warp10_exec"`
70
-	// Warp10 read token
77
+	// ReadToken represents Warp10's read token
71 78
 	ReadToken string `yaml:"token"`
72
-	// WarpScripts to run, with an identifier as its key
79
+	// Script represents the WarpScripts to run
73 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 86
 func (cfg *Config) Load(filePath string) (err error) {
77 87
 	content, err := ioutil.ReadFile(filePath)
78 88
 	if err != nil {