-
Notifications
You must be signed in to change notification settings - Fork 1
/
i3status-datadog.go
72 lines (61 loc) · 1.21 KB
/
i3status-datadog.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
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"log"
"github.com/zorkian/go-datadog-api"
"fmt"
"flag"
)
const (
Green = "#008000"
Yellow = "#FFFF00"
Grey = "#808080"
Red = "#FF0000"
)
type monitorCounter struct {
Ok int
Warn int
Alert int
NoData int
}
func main() {
apiKey := flag.String("apiKey", "", "Datadog API Key")
appKey := flag.String("appKey", "", "Datadog APP Key")
flag.Parse()
client := datadog.NewClient(*apiKey, *appKey)
monitors, err := client.GetMonitors()
if err != nil {
log.Fatalf("fatal: %s\n", err)
}
monitorCounter := monitorCounter{
Ok: 0,
Warn: 0,
Alert: 0,
NoData: 0,
}
for _, monitor := range monitors {
switch *monitor.OverallState {
case "OK":
monitorCounter.Ok++
case "No Data":
monitorCounter.NoData++
case "Warn":
monitorCounter.Warn++
case "Alert":
monitorCounter.Alert++
}
}
fmt.Printf("%vN %vW %vA %vT", monitorCounter.NoData, monitorCounter.Warn, monitorCounter.Alert, len(monitors))
switch {
case monitorCounter.Alert > 0:
fmt.Printf("\n\n%v", Red)
break
case monitorCounter.Warn > 0:
fmt.Printf("\n\n%v", Yellow)
break
case monitorCounter.NoData > 0:
fmt.Printf("\n\n%v", Grey)
break
default:
fmt.Printf("\n\n%v", Green)
}
}