-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_rest_unity_alert.inc.lua
More file actions
49 lines (42 loc) · 1.58 KB
/
check_rest_unity_alert.inc.lua
File metadata and controls
49 lines (42 loc) · 1.58 KB
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
-- data: JSON response table object
-- lc: libcheck table object
-- perfdata: Perfdata table array to fill
-- Assume request filter:
-- isAcknowledged eq false AND state ne 2
-- check data consistency
if not data.entries then
lc.die(lc.UNKNOWN, "data.entries: not found")
end
if type(data.entries) ~= 'table' then
lc.die(lc.UNKNOWN, "data.entries: array expected")
end
-- count alerts by severity
alert2perfdata = {
[0] = { name = 'emergency', value = 0, uom = '', critical = 0 },
[1] = { name = 'alert', value = 0, uom = '', critical = 0 },
[2] = { name = 'critical', value = 0, uom = '', critical = 0 },
[3] = { name = 'error', value = 0, uom = '', critical = 0 },
[4] = { name = 'warning', value = 0, uom = '', warning = 0 },
[5] = { name = 'notice', value = 0, uom = '' },
[6] = { name = 'info', value = 0, uom = '' },
[7] = { name = 'debug', value = 0, uom = '' },
[8] = { name = 'ok', value = 0, uom = '' },
}
for k,v in pairs(data.entries) do
if type(v) ~= 'table' or
type(v.content) ~= 'table' or
type(v.content.severity) ~= 'number' then
lc.die(lc.UNKNOWN, 'Invalid JSON data structure')
end
-- floor because lua/lua-json might represent intergers as float
severity = math.floor(v.content.severity)
if alert2perfdata[severity] == nil then
lc.die(lc.UNKNOWN, 'Unsupported severity in result ('..severity..')')
end
-- increment counter
alert2perfdata[severity].value = alert2perfdata[severity].value + 1
end
-- fill perfdata
for k,v in pairs(alert2perfdata) do
table.insert(perfdata, v)
end