Page 1 of 1
hostsgroup others
Posted: Sun May 31, 2015 2:34 pm
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.
Re: hostsgroup others
Posted: Mon Jun 01, 2015 9:33 am
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.
Re: hostsgroup others
Posted: Tue Jun 02, 2015 4:01 am
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
Re: hostsgroup others
Posted: Tue Jun 02, 2015 9:28 am
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.