-
Notifications
You must be signed in to change notification settings - Fork 0
/
icinga.jq
62 lines (55 loc) · 1.55 KB
/
icinga.jq
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
def to_perfdata_line(exit; msg):
["OK", "WARNING", "CRITICAL"][exit] +": " + msg + "|" +
( to_entries | map( .key + "=" + (
.value | [(.value | tostring) + .unit] +
if .warn then [
.warn,
.crit,
if .min then .min else 0 end,
if .max then .max else empty end
] else [] end
| map(tostring) | join(";")
)) | join(" ")
);
def to_perfdata(exit; msg):
exit, to_perfdata_line(exit; msg);
def to_service_check_result(host; service; exit; msg):
"[" + (now | floor | tostring) + "] " + ([
"PROCESS_SERVICE_CHECK_RESULT",
host,
service,
(exit | tostring),
to_perfdata_line(exit; msg)
] | join(";"));
def to_service_check_result_simple(host; service):
. as $me |
[{ key: service, value: . }] | from_entries | to_service_check_result(host; service; $me.state; $me.msg // ($me.value|tostring) + $me.unit);
# Inject success state
def fill_icinga_state_simple:
.state = (if .crit > .warn then
if .value > .crit then
2
else
if .value > .warn then
1
else
0
end
end
else
if .value < .crit then
2
else
if .value < .warn then
1
else
0
end
end
end);
def fill_icinga_state:
map_values(fill_icinga_state_simple);
def service_simple(host; service):
fill_icinga_state_simple | to_service_check_result_simple(host;service);
def format:
fill_icinga_state | to_perfdata(map(.state) | max;to_entries | sort_by(-.value.state) | map(.value.msg[.value.state]? // .value.msg // empty) | join(", "));