|
@@ -0,0 +1,46 @@
|
|
1
|
+package alert
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "fmt"
|
|
5
|
+
|
|
6
|
+ "metrics-alerting/config"
|
|
7
|
+ "metrics-alerting/warp10"
|
|
8
|
+)
|
|
9
|
+
|
|
10
|
+func ProcessNumber(client warp10.Warp10Client, script config.Script) error {
|
|
11
|
+ value, err := client.ReadNumber(script.Script)
|
|
12
|
+ if err != nil {
|
|
13
|
+ return err
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ if value < script.Threshold {
|
|
17
|
+ // Nothing to alert about
|
|
18
|
+ return nil
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ return alert(script, value)
|
|
22
|
+}
|
|
23
|
+
|
|
24
|
+func ProcessBool(client warp10.Warp10Client, script config.Script) error {
|
|
25
|
+ value, err := client.ReadBool(script.Script)
|
|
26
|
+ if err != nil {
|
|
27
|
+ return err
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ if value {
|
|
31
|
+ return nil
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ return alert(script, value)
|
|
35
|
+}
|
|
36
|
+
|
|
37
|
+func alert(script config.Script, result interface{}) error {
|
|
38
|
+ switch script.Action {
|
|
39
|
+ case "http":
|
|
40
|
+ return alertHttp(script, result)
|
|
41
|
+ case "email":
|
|
42
|
+ return alertEmail(script, result)
|
|
43
|
+ default:
|
|
44
|
+ return fmt.Errorf("invalid action type: %s", script.Action)
|
|
45
|
+ }
|
|
46
|
+}
|