Page 1 of 1

nagios cgi-bin

Posted: Tue Oct 08, 2019 2:21 pm
by gad314
Hello,

I was trying to access nagios cgi-bin throw https://nagios-ip/nagios/cgi-bin/statusjson.cgi?
by providing credentials, sometimes it works others doesn't work.
it's weird .
can anyone help?

Re: nagios cgi-bin

Posted: Tue Oct 08, 2019 2:42 pm
by benjaminsmith
Hello,

If you're using Nagios XI, I would recommend using the Backend API. Go to Help > API Docs for documentation.

Re: nagios cgi-bin

Posted: Wed Oct 09, 2019 9:00 am
by gad314
Thanks Benjamin for your reply.

So how can I get a list of down host in a specific host_group using API. this is the main point.

this is what I was using (but it's not reliable way, as you said it's better using API)

curl -u nagiosadm:$(cat /path-to-password) "http://nagios_IP/nagios/cgi-bin/statusjson.cgi?query=hostlist&formatoptions=duration&details=true&hostgroup=specific_host_group&hoststatus=down"

Re: nagios cgi-bin

Posted: Wed Oct 09, 2019 10:47 am
by scottwilkerson
You can get them from the XI API
Help -> Objects Reference -> objects/hostgroupmembers

The call would look something like this

Code: Select all

http://xxx.xxx.xxx.xxx/nagiosxi/api/v1/objects/hostgroupmembers?apikey=APIKEY&pretty=1&hostgroup_name=HOSTGROUP

Re: nagios cgi-bin

Posted: Wed Oct 09, 2019 2:49 pm
by gad314
Thanks scott,

but this will give me all hostgroup members.

I only need the host in down state only in that hostgroup.

Thanks and regards.

Re: nagios cgi-bin

Posted: Wed Oct 09, 2019 2:56 pm
by scottwilkerson
You would then need to make another call to objects/hoststatus with something like the following extracting the host names from the previous call

Code: Select all

http://xxx.xxx.xxx.xxx/nagiosxi/api/v1/objects/hoststatus?apikey=APIKEY&pretty=1&current_state=nin:0&name=in:HOST1,HOST2,HOST3

current_state=nin:0 means NOT 0 (not UP)

name=in:HOST1,HOST2,HOST3 means only show the hosts in the comma separated list

Re: nagios cgi-bin

Posted: Thu Oct 10, 2019 8:38 am
by gad314
Thanks very much Scott for those valuable info.

but how could we gather the two conditions. I still need host list in specific host_group and their status is down.

Regards.

Re: nagios cgi-bin

Posted: Thu Oct 10, 2019 9:33 am
by scottwilkerson
gad314 wrote:Thanks very much Scott for those valuable info.

but how could we gather the two conditions. I still need host list in specific host_group and their status is down.

Regards.
You would need to make a call to the objects/hostgroupmembers API end-point, parse the JSON results in your script, and then use that to make the second call.