forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icinga2_test.go
91 lines (79 loc) · 2.04 KB
/
icinga2_test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package icinga2
import (
"encoding/json"
"testing"
"github.com/influxdata/telegraf/testutil"
)
func TestGatherServicesStatus(t *testing.T) {
s := `{"results":[
{
"attrs": {
"check_command": "check-bgp-juniper-netconf",
"display_name": "eq-par.dc2.fr",
"name": "ef017af8-c684-4f3f-bb20-0dfe9fcd3dbe",
"state": 0
},
"joins": {},
"meta": {},
"name": "eq-par.dc2.fr!ef017af8-c684-4f3f-bb20-0dfe9fcd3dbe",
"type": "Service"
}
]}`
checks := Result{}
json.Unmarshal([]byte(s), &checks)
fields := map[string]interface{}{
"name": "ef017af8-c684-4f3f-bb20-0dfe9fcd3dbe",
"state_code": 0,
}
tags := map[string]string{
"display_name": "eq-par.dc2.fr",
"check_command": "check-bgp-juniper-netconf",
"state": "ok",
"source": "localhost",
"port": "5665",
"scheme": "https",
}
var acc testutil.Accumulator
icinga2 := new(Icinga2)
icinga2.ObjectType = "services"
icinga2.Server = "https://localhost:5665"
icinga2.GatherStatus(&acc, checks.Results)
acc.AssertContainsTaggedFields(t, "icinga2_services", fields, tags)
}
func TestGatherHostsStatus(t *testing.T) {
s := `{"results":[
{
"attrs": {
"name": "webserver",
"address": "192.168.1.1",
"check_command": "ping",
"display_name": "apache",
"state": 2
},
"joins": {},
"meta": {},
"name": "webserver",
"type": "Host"
}
]}`
checks := Result{}
json.Unmarshal([]byte(s), &checks)
fields := map[string]interface{}{
"name": "webserver",
"state_code": 2,
}
tags := map[string]string{
"display_name": "apache",
"check_command": "ping",
"state": "critical",
"source": "localhost",
"port": "5665",
"scheme": "https",
}
var acc testutil.Accumulator
icinga2 := new(Icinga2)
icinga2.ObjectType = "hosts"
icinga2.Server = "https://localhost:5665"
icinga2.GatherStatus(&acc, checks.Results)
acc.AssertContainsTaggedFields(t, "icinga2_hosts", fields, tags)
}