Page 1 of 1

Find Hosts Missing a Service

Posted: Wed Feb 07, 2018 3:05 pm
by REFan
I am looking for a way to discover what hosts do not have a specific service assigned.
I have a new service that checks if Windows has a pending reboot that I want most of my Windows servers to have.

I know I can put all of these servers in a host group to force them to get this service but I thought this would be a good idea to double check that all of my hosts have this service.

Any advice on how I can pull this data?

Re: Find Hosts Missing a Service

Posted: Wed Feb 07, 2018 4:57 pm
by npolovenko
Hello, @REFan, You could probably make a custom query to mysql:

Code: Select all

echo "select * from tbl_host JOIN (tbl_lnkServiceToHost);" | mysql -uroot -pnagiosxi nagiosql
Or you could look into object.cache file. It has all the configs that are being used at the present moment.

Code: Select all

/usr/local/nagios/var/objects.cache
Let me know if that helps.

Re: Find Hosts Missing a Service

Posted: Thu Feb 08, 2018 10:37 am
by REFan
Cool I was able to look at objects.cache and pull out the members of the host group.

Is there a way to export the hosts that are associated with a service? Looking at that file there isn't one service with all associated hosts.

Re: Find Hosts Missing a Service

Posted: Thu Feb 08, 2018 1:27 pm
by kyang
You should be able to grep that objects.cache file.

Code: Select all

grep -1 service_description /usr/local/nagios/var/objects.cache
This should list all the hosts and services


This is an example of where I'm looking for the Ping service in all hosts. (You can change the string "Ping" to whatever service you are looking for under specific hosts.)

Code: Select all

grep 'Ping' -B 2 /usr/local/nagios/var/objects.cache | grep 'service_description\|host_name'
Let us know if this works for you.

Re: Find Hosts Missing a Service

Posted: Thu Feb 08, 2018 4:39 pm
by REFan
Very cool! That does work. I also was able to pull some data from the Reports tab. I was able to export the list of hosts in the host group and create a service group to export hosts that are assigned directly to the service.

Re: Find Hosts Missing a Service

Posted: Thu Feb 08, 2018 4:42 pm
by dwhitfield
It sounds like this issue has been resolved. Is it okay if we lock this thread? Thanks for choosing the Nagios forums!