Page 1 of 1

Finding All hosts not in groups

Posted: Thu Sep 21, 2017 3:39 am
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

Re: Finding All hosts not in groups

Posted: Thu Sep 21, 2017 8:53 am
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.

Re: Finding All hosts not in groups

Posted: Thu Sep 21, 2017 11:58 am
by lmiltchev
@amprantino, did mcapra's solution work for you? Let us know if you have any more questions.