hostsgroup others

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
gabo004
Posts: 1
Joined: Mon Feb 23, 2015 10:13 am

hostsgroup others

Post by gabo004 »

Hello,
How could I create hostgroup, which automaticlly contains every hosts, that are not defined in any other group ? something like:

Code: Select all

define  hostgroup{
         hostgroup_name            others
         members                   *, !HOSTGROUP1, !HOSTGROUP2...
         } 
Thank you.
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: hostsgroup others

Post by jdalrymple »

Doesn't seem possible using builtin constructs. If it were possible I'd think the way you suggested would be it, and that doesn't work fro me. You'll probably have to write a script that parses your config and creates your hg for you.
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: hostsgroup others

Post by millisa »

Is the goal just to catch hosts not added to a hostgroup so you can spot them?

If so, you could do it with a service definition since with those you *can* send it a * for the host_name and then do a set of exceptions with hostgroups.
Something like this would use check_dummy for all hosts not defined in the hostgroups you list:

Code: Select all

define service{
        use                             yourservicetemplate
        host_name                       *
        hostgroup_name                  !hostgroup1, !hostgroup2, !hostgroupC
        service_description             NoHostGroup
        check_command                   check_dummy!2!IHaveNoHostGroup  
          #check_dummy takes 0-3 (0=ok, 1=warn, 2=crit, 3=unk) 
          #as the first arg and just returns that as the nagios state
          #2nd arg is output text
        }
check_dummy command def in case you don't have one:

Code: Select all

define command{
        command_name check_dummy
        command_line $USER1$/check_dummy $ARG1$ $ARG2$
}
(If you want to include other hostgroups in a hostgoups directive, you'd normally do with the optional 'hostgroup_members' directive, not in the members directive; unfortunately hostgroup_members doesn't take !'s for negation - feature request?)

Edit1: Changed the check to use check_dummy instead of check_ping
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: hostsgroup others

Post by jdalrymple »

Nice one, I tested this and it did work. It won't create a hostgroup for you, but it might achieve your needs.
Locked