Report on Host and associated services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
tmattingly
Posts: 115
Joined: Thu Oct 23, 2014 12:53 pm

Report on Host and associated services

Post 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
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Report on Host and associated services

Post 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
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

Post by tmattingly »

Under help I don't have that under Help > REST API Docs > Introduction.

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

Post 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
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Report on Host and associated services

Post by cdienger »

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

Post by tmattingly »

5.6.0 - Upgraded last week.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Report on Host and associated services

Post by cdienger »

Double check the script and try running it with the "-x" option:

Code: Select all

bash -x report.sh
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"
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked