Finding All hosts not in groups

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
amprantino
Posts: 140
Joined: Thu Apr 18, 2013 8:25 am
Location: libexec

Finding All hosts not in groups

Post by amprantino »

Hello all,

Is there a way to find the hosts that dont belong to any group?

Creating a foo group with all hosts and then excluding the groups does not work
A similar post for group exclusion exists here: https://support.nagios.com/forum/viewto ... =7&t=21500

Any ideas
Thank you
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Finding All hosts not in groups

Post by mcapra »

The JSON Query Generator is a good place to start. It can typically be found here in Core 4+:

Code: Select all

http://<your_nagios_host>/nagios/jsonquery.html
I'd write a script to first pull hostlist to get a list of every host, then for each host in that list pull hostgrouplist and find values where the response's data.hostgrouplist array is empty.

In pseudocode:

Code: Select all

$hostlist = http://10.35.7.25/nagios/cgi-bin/objectjson.cgi?query=hostlist

for each $host in $hostlist {
    $json = http://10.35.7.25/nagios/cgi-bin/objectjson.cgi?query=hostgrouplist&hostgroupmember=$host

    if $json.data.hostgrouplist.size() < 1 {
        print "$host has no hostgroup"
    }
}
I'm sure a more efficient algorithm could be crafted, but if this is a one-off thing I'd just do the above.
Former Nagios employee
https://www.mcapra.com/
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Finding All hosts not in groups

Post by lmiltchev »

@amprantino, did mcapra's solution work for you? Let us know if you have any more questions.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked