Page 1 of 1
Report on Host and associated services
Posted: Fri Apr 19, 2019 2:49 pm
by tmattingly
Hi Nagios folks!
Is there an easy way to generate a report of all the hosts that are currently being monitored and all the services related to that specific host in the report?
Tom
Re: Report on Host and associated services
Posted: Fri Apr 19, 2019 3:44 pm
by cdienger
The API can used to this information. Below is bash script do get a list of hosts and all the services. Make sure to replace xiip and apikey with the IP address of the XI machine and the API key of that machine which can be found under Help > REST API Docs > Introduction.
Code: Select all
#!/bin/bash
xi_ip=xiip
api_key=apikey
hosts=($(curl -XGET "http://$xi_ip/nagiosxi/api/v1/objects/host?apikey=$api_key&pretty=1" 2>/dev/null | grep host_name | awk '{print $2}' | sed s/\"//g | sed s/,//))
for i in "${hosts[@]}"
do
echo "Host: $i"
services=($(curl -XGET "http://$xi_ip/nagiosxi/api/v1/objects/service?apikey=$api_key&pretty=1&host_name=$i" 2>/dev/null | grep service_description | awk '{print $2}' | sed s/\"//g | sed s/,//))
printf "\t%s\n" "Services:"
printf "\t%s\n" "Service: ${services[@]}"
done
There are also these interfaces:
https://nagiosxi_ip/nagios/cgi-bin/config.cgi
https://nagiosxi_ip/nagios/jsonquery.html
Re: Report on Host and associated services
Posted: Fri Apr 19, 2019 6:02 pm
by tmattingly
Under help I don't have that under Help > REST API Docs > Introduction.
See attachment.
Re: Report on Host and associated services
Posted: Fri Apr 19, 2019 6:35 pm
by tmattingly
I was able to get the APIkey. (Your interface is fascinating to display it in blue and the examples you supply have references to my Nagios HOST!)
But I get no output. I did test Bash with a "hello world" test and that works so.... Can you hep me with why its not running or displaying any output?
Tom
Re: Report on Host and associated services
Posted: Mon Apr 22, 2019 9:05 am
by cdienger
What version of XI is this for?
Re: Report on Host and associated services
Posted: Mon Apr 22, 2019 10:48 am
by tmattingly
5.6.0 - Upgraded last week.
Re: Report on Host and associated services
Posted: Mon Apr 22, 2019 1:02 pm
by cdienger
Double check the script and try running it with the "-x" option:
You can try running the curl commands from the command line as well:
Code: Select all
curl -XGET "http://$xi_ip/nagiosxi/api/v1/objects/host?apikey=$api_key&pretty=1"
curl -XGET "http://$xi_ip/nagiosxi/api/v1/objects/service?apikey=$api_key&pretty=1&host_name=$i"