Page 1 of 1

Hosts that are down more than 9 days

Posted: Mon Mar 07, 2016 10:44 am
by haile711
Hey guys,

I want to run a query on the nagios mysql database to get the hosts that are down more then 9 days, but I'm not familiar with the database architect. Can someone help me, or give me a suggestion?

Thanks

Re: Hosts that are down more than 9 days

Posted: Mon Mar 07, 2016 2:27 pm
by hsmith
Interacting directly with the database isn't always recommended. What are you trying to accomplish that you would like this information?

Re: Hosts that are down more than 9 days

Posted: Mon Mar 07, 2016 10:10 pm
by Box293
You could use the JSON query generator to get all the hosts down:

Code: Select all

http://xiserver/nagios/jsonquery.html
Selection_001.png

Code: Select all

https://xiserver/nagios/cgi-bin/statusjson.cgi?query=hostlist&details=true&dateformat=%25Y-%25m-%25d+%25H%3A%25M%3A%25S&hoststatus=down
Then you could take that JSON data and parse it to only get the hosts down using the last_time_down field.

Re: Hosts that are down more than 9 days

Posted: Tue Mar 08, 2016 8:44 am
by haile711
hey hsmith and Box

We have an automate way to add new hosts to be monitored with Nagios, whenever a customers provision new environments for testing their codes. After a certain period of times these environments is expired and released, yets these hosts are still active in Nagios. I just want to setup a query and get all the hosts that have been down more then 5-9 days and removed them from Nagios. Thanks

Re: Hosts that are down more than 9 days

Posted: Tue Mar 08, 2016 10:01 am
by snapon_admin
Isn't that what the deadpool is for under Admin > deadpool settings?

Re: Hosts that are down more than 9 days

Posted: Tue Mar 08, 2016 11:03 am
by haile711
hey snapon_admin,

I have tried the deadpool setting, but I dunno why these doesn't work for me. It is because I have all my services in the static directory?

Re: Hosts that are down more than 9 days

Posted: Tue Mar 08, 2016 11:31 am
by tmcdonald
haile711 wrote:I have all my services in the static directory?
This is most likely the case, yes. Anything in the static directory will be ignored by XI basically. You will either need to add these in using the API introduced in XI 5, or use the method that @Box293 suggested.

Re: Hosts that are down more than 9 days

Posted: Fri Mar 11, 2016 10:26 am
by haile711
Hey guys,

I know it's recommend not to touch the nagios db, I just want to see if there is a way to query that.
To Box, the API approach can work for us as well, but we have so many hosts, can you help us in how to parse to get just the hosts that has been down more than 9 days?


Thanks

Re: Hosts that are down more than 9 days

Posted: Fri Mar 11, 2016 3:32 pm
by rkennedy
I was able to pull all down hosts using a curl / grep, I suspect you'll need to write a script to filter out the 9 day thing. This should work though -

Here's the one liner -

Code: Select all

curl -s "http://192.168.4.254/nagiosxi/backend/?cmd=gethoststatus&username=nagiosadmin&ticket=tickettest" | grep "CRITICAL"
As an example, I have -

Code: Select all

[root@suse11 ~]# curl -s "http://192.168.4.254/nagiosxi/backend/?cmd=gethoststatus&username=nagiosadmin&ticket=tickettest" | grep "CRITICAL"
    <status_text>CRITICAL - 192.168.3.243: Host unreachable @ 192.168.4.254. rta nan, lost 100%</status_text>
    <status_text>CRITICAL - 1.1.1.1: rta nan, lost 100%</status_text>