Skip to content

Commit d209278

Browse files
committed
use icinga.status.list to collect numbers for command "so"
refs: #21
1 parent 3189a97 commit d209278

1 file changed

Lines changed: 19 additions & 54 deletions

File tree

i2_slack_modules/slack_commands.py

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -311,67 +311,32 @@ def get_icinga_status_overview(config=None, *args, **kwargs):
311311

312312
response = BotResponse(text="Status Overview")
313313

314-
# get icinga host objects
315-
i2_host_response = get_i2_object(config, "Host")
314+
i2_status = get_i2_status(config, "CIB")
316315

317-
if i2_host_response.error:
318-
return slack_error_response(header="Icinga request error", error_message=i2_host_response.error)
319-
320-
# get icinga service objects
321-
i2_service_response = get_i2_object(config, "Service")
316+
if i2_status.error:
317+
return slack_error_response(header="Icinga request error", error_message=i2_status.error)
322318

323-
if i2_service_response.error:
324-
return slack_error_response(header="Icinga request error", error_message=i2_service_response.error)
319+
data = i2_status.response["results"][0]["status"]
325320

326321
host_count = {
327-
"UP": 0,
328-
"DOWN": 0,
329-
"UNREACHABLE": 0,
330-
"UNHANDLED": 0,
331-
"ACKNOWLEDGED": 0,
332-
"IN DOWNTIME": 0
322+
"UP": data.get("num_hosts_up"),
323+
"DOWN": data.get("num_hosts_down"),
324+
"UNREACHABLE": data.get("num_hosts_unreachable"),
325+
"UNHANDLED": int(data.get("num_hosts_problem") - data.get("num_hosts_handled")),
326+
"ACKNOWLEDGED": data.get("num_hosts_acknowledged"),
327+
"IN DOWNTIME": data.get("num_hosts_in_downtime")
333328
}
334329

335330
service_count = {
336-
"OK": 0,
337-
"WARNING": 0,
338-
"CRITICAL": 0,
339-
"UNKNOWN": 0,
340-
"UNHANDLED": 0,
341-
"ACKNOWLEDGED": 0,
342-
"IN DOWNTIME": 0
331+
"OK": data.get("num_services_ok"),
332+
"WARNING": data.get("num_services_warning"),
333+
"CRITICAL": data.get("num_services_critical"),
334+
"UNKNOWN": data.get("num_services_unknown"),
335+
"UNHANDLED": int(data.get("num_services_problem") - data.get("num_services_handled")),
336+
"ACKNOWLEDGED": data.get("num_services_acknowledged"),
337+
"IN DOWNTIME": data.get("num_services_in_downtime")
343338
}
344339

345-
# count all host objects
346-
for host in i2_host_response.response:
347-
host_count[host_states.reverse[int(host.get("state"))]] += 1
348-
349-
if host.get("acknowledgement") > 0:
350-
host_count["ACKNOWLEDGED"] += 1
351-
352-
if host.get("downtime_depth") > 0:
353-
host_count["IN DOWNTIME"] += 1
354-
355-
if host.get("state") > 0 and \
356-
host.get("acknowledgement") == 0 and \
357-
host.get("downtime_depth") == 0:
358-
host_count["UNHANDLED"] += 1
359-
360-
# count all service objects
361-
for service in i2_service_response.response:
362-
service_count[service_states.reverse[int(service.get("state"))]] += 1
363-
364-
if service.get("acknowledgement") > 0:
365-
service_count["ACKNOWLEDGED"] += 1
366-
367-
if service.get("downtime_depth") > 0:
368-
service_count["IN DOWNTIME"] += 1
369-
370-
if service.get("state") > 0 and \
371-
service.get("acknowledgement") == 0 and \
372-
service.get("downtime_depth") == 0:
373-
service_count["UNHANDLED"] += 1
374-
375340
# add block text with number of unhandled problems
376341
problems_unhandled = host_count["UNHANDLED"] + service_count["UNHANDLED"]
377342
response.add_block("*Found %s unhandled problem%s*" %
@@ -385,7 +350,7 @@ def get_icinga_status_overview(config=None, *args, **kwargs):
385350
continue
386351
host_fields.append({
387352
"title": title,
388-
"value": value,
353+
"value": int(value),
389354
"short": True
390355
})
391356

@@ -407,7 +372,7 @@ def get_icinga_status_overview(config=None, *args, **kwargs):
407372
continue
408373
service_fields.append({
409374
"title": title,
410-
"value": value,
375+
"value": int(value),
411376
"short": True
412377
})
413378

0 commit comments

Comments
 (0)