forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icinga2_test.go
119 lines (104 loc) · 2.72 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package icinga2
import (
"encoding/json"
"testing"
"time"
"github.com/influxdata/telegraf"
"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",
"host_name": "someserverfqdn.net",
"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)
icinga2 := new(Icinga2)
icinga2.Log = testutil.Logger{}
icinga2.ObjectType = "services"
icinga2.Server = "https://localhost:5665"
var acc testutil.Accumulator
icinga2.GatherStatus(&acc, checks.Results)
expected := []telegraf.Metric{
testutil.MustMetric(
"icinga2_services",
map[string]string{
"display_name": "eq-par.dc2.fr",
"check_command": "check-bgp-juniper-netconf",
"state": "ok",
"source": "someserverfqdn.net",
"server": "localhost",
"port": "5665",
"scheme": "https",
},
map[string]interface{}{
"name": "ef017af8-c684-4f3f-bb20-0dfe9fcd3dbe",
"state_code": 0,
},
time.Unix(0, 0),
),
}
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
}
func TestGatherHostsStatus(t *testing.T) {
s := `{
"results": [
{
"attrs": {
"address": "192.168.1.1",
"check_command": "ping",
"display_name": "apache",
"name": "webserver",
"state": 2.0
},
"joins": {},
"meta": {},
"name": "webserver",
"type": "Host"
}
]
}
`
checks := Result{}
json.Unmarshal([]byte(s), &checks)
var acc testutil.Accumulator
icinga2 := new(Icinga2)
icinga2.Log = testutil.Logger{}
icinga2.ObjectType = "hosts"
icinga2.Server = "https://localhost:5665"
icinga2.GatherStatus(&acc, checks.Results)
expected := []telegraf.Metric{
testutil.MustMetric(
"icinga2_hosts",
map[string]string{
"display_name": "apache",
"check_command": "ping",
"state": "critical",
"source": "webserver",
"server": "localhost",
"port": "5665",
"scheme": "https",
},
map[string]interface{}{
"name": "webserver",
"state_code": 2,
},
time.Unix(0, 0),
),
}
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
}