Hosts that are down more than 9 days

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
haile711
Posts: 197
Joined: Thu May 28, 2015 7:36 am

Hosts that are down more than 9 days

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Hosts that are down more than 9 days

Post by hsmith »

Interacting directly with the database isn't always recommended. What are you trying to accomplish that you would like this information?
Former Nagios Employee.
me.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Hosts that are down more than 9 days

Post 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.
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
haile711
Posts: 197
Joined: Thu May 28, 2015 7:36 am

Re: Hosts that are down more than 9 days

Post 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
User avatar
snapon_admin
Posts: 952
Joined: Mon Jun 10, 2013 10:39 am
Location: Kenosha, WI
Contact:

Re: Hosts that are down more than 9 days

Post by snapon_admin »

Isn't that what the deadpool is for under Admin > deadpool settings?
haile711
Posts: 197
Joined: Thu May 28, 2015 7:36 am

Re: Hosts that are down more than 9 days

Post 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?
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Hosts that are down more than 9 days

Post 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.
Former Nagios employee
haile711
Posts: 197
Joined: Thu May 28, 2015 7:36 am

Re: Hosts that are down more than 9 days

Post 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
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Hosts that are down more than 9 days

Post 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>
Former Nagios Employee
Locked