Page 1 of 1
Report for current status of hosts?
Posted: Thu Apr 23, 2015 12:06 pm
by peter.zanetti
When looking at the hosts you can see how many devices are offline and see the list of them. However there is no way to export that list. Is there a way to create an exportable report that shows just the current state of the hosts instead of the % of up and down time?
Re: Report for current status of hosts?
Posted: Thu Apr 23, 2015 2:27 pm
by jolson
Have you looked into the 'Schedule Page' button?
file.png
Using this page, you can schedule a PDF report to be sent out of any page in XI - you are able to choose the delivery interval as well (Daily, Weekly, etc).
Does that work for you?
Re: Report for current status of hosts?
Posted: Fri Apr 24, 2015 7:03 am
by peter.zanetti
That did work to give me the current status, however is there a way to get that as a csv or excel file? I need to be able to grab the data and use it in some custom reporting through excel.
Re: Report for current status of hosts?
Posted: Fri Apr 24, 2015 10:38 am
by jolson
I don't think that getting a .csv of all current host state information is possible.
The closest I know of is the 'state history' report - is this something that could work for you, or does it need to be live?
2015-04-24 10_37_17-Nagios XI - Reports.png
Re: Report for current status of hosts?
Posted: Fri Apr 24, 2015 10:48 am
by peter.zanetti
It would need to be the live host states. I'm thinking maybe a database call?
Re: Report for current status of hosts?
Posted: Fri Apr 24, 2015 11:30 am
by jdalrymple
Here is some junky python that will do what you want.
Use the argument "h" for hosts and "s" for services.
It can't really do both at the same time since services have hosts (an additional column) but not the reverse.
Code: Select all
#!/usr/bin/python
import sys
import re
# lines to not chuck
# servicestatus {
# hoststatus {
# service_description=
# host_name=
# current_state=#
# }
m1 = re.compile('servicestatus {')
m2 = re.compile('hoststatus {')
m3 = re.compile('\\tcurrent_state=[0-3]')
m4 = re.compile('\\thost_name=')
m5 = re.compile('\\tservice_description=')
with open('/usr/local/nagios/var/status.dat') as f:
statusdat = f.read().splitlines()
f.close()
# 1 if we're working on a service 2 if we're working on a host, 0 if we're not working on anything
w = 0
services = []
s = 0
hosts = []
h = 0
for line in statusdat:
if(m1.match(line)):
services.append([])
w = 1
if(m2.match(line)):
hosts.append([])
w = 2
if(m3.match(line)):
if w == 1:
services[s].append(re.sub('^.*=', '', line))
w = 0
s += 1
if w == 2:
hosts[h].append(re.sub('^.*=', '', line))
w = 0
h += 1
if(m4.match(line)):
if w == 1:
services[s].append(re.sub('^.*=', '', line))
if w == 2:
hosts[h].append(re.sub('^.*=', '', line))
if(m5.match(line)):
services[s].append(re.sub('^.*=', '', line))
#for host in hosts:
# print host
#for service in services:
# print service
if sys.argv[1] == "h":
for host in hosts:
if host[1] == "0":
host[1] = "OK"
if host[1] == "1":
host[1] = "WARNING"
if host[1] == "2":
host[1] = "CRITICAL"
if host[1] == "3":
host[1] = "UNKNOWN"
print host[0] + "," + host[1]
if sys.argv[1] == "s":
for service in services:
if service[2] == "0":
service[2] = "OK"
if service[2] == "1":
service[2] = "WARNING"
if service[2] == "2":
service[2] = "CRITICAL"
if service[2] == "3":
service[2] = "UNKNOWN"
print service[0] + "," + service[1] + "," + service[2]