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
Report on Host and associated services
Re: Report on Host and associated services
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.
There are also these interfaces:
https://nagiosxi_ip/nagios/cgi-bin/config.cgi
https://nagiosxi_ip/nagios/jsonquery.html
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[@]}"
donehttps://nagiosxi_ip/nagios/cgi-bin/config.cgi
https://nagiosxi_ip/nagios/jsonquery.html
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
-
tmattingly
- Posts: 115
- Joined: Thu Oct 23, 2014 12:53 pm
Re: Report on Host and associated services
Under help I don't have that under Help > REST API Docs > Introduction.
See attachment.
See attachment.
You do not have the required permissions to view the files attached to this post.
-
tmattingly
- Posts: 115
- Joined: Thu Oct 23, 2014 12:53 pm
Re: Report on Host and associated services
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
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
What version of XI is this for?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
-
tmattingly
- Posts: 115
- Joined: Thu Oct 23, 2014 12:53 pm
Re: Report on Host and associated services
5.6.0 - Upgraded last week.
Re: Report on Host and associated services
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
bash -x report.shCode: 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"As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.