Unable to apply/assign service to hostgroup


(Leonardo) #1

Hello,
I am new to Icinga2, I searched the web for a solution to my problem but I didn’t find it.
I want to apply the service snmp-load based on the number of cpu, so I wrote this configuration:

/etc/icinga2/icinga2.conf

include_recursive “conf.d”

/etc/icinga2/conf.d/linux-hosts.conf

object Host “server”{
import “redhat-server”
address = “10.10.10.10”
vars.os = “Linux”
vars.cpunum = “4” }

/etc/icinga2/conf.d/groups.conf

object HostGroup “4cpu” {
display_name = “Load 4 CPU”
assign where host.vars.cpunum == “4”
}

/etc/icinga2/conf.d/templates.conf

template Host “redhat-server” {
import “generic-host”
check_command = “hostalive-linux”
}

/etc/icinga2/conf.d/command.conf

object CheckCommand “hostalive-linux” {
import “ssh”
}

/etc/icinga2/conf.d/service.conf

apply Service “snmp-load” {
display_name = “Current Load 4 CPU”
import “generic-service”

check_command = “snmp-load”
vars.snmp_community = “community”
vars.snmp_v2 = true
vars.snmp_load_type = “netsl”
vars.snmp_warn = “4,2.8,2.8”
vars.snmp_crit = “5.2,4,4”
assign where host.groups == “4cpu”
}

output from # icinga2 daemon -C
[2018-11-22 10:28:41 +0100] information/cli: Icinga application loader (version: r2.10.2-1)
[2018-11-22 10:28:41 +0100] information/cli: Loading configuration file(s).
[2018-11-22 10:28:41 +0100] information/ConfigItem: Committing config item(s).
[2018-11-22 10:28:41 +0100] information/ApiListener: My API identity: monitoring.servizi.difesa.it
[2018-11-22 10:28:41 +0100] warning/ApplyRule: Apply rule ‘snmp-load’ (in /etc/icinga2/conf.d/services.conf: 121:1-121:25) for type ‘Service’ does not match anywhere!
[2018-11-22 10:28:41 +0100] warning/ApplyRule: Apply rule ‘snmp-load’ (in /etc/icinga2/conf.d/services.conf: 134:1-134:25) for type ‘Service’ does not match anywhere!
[2018-11-22 10:28:41 +0100] warning/ApplyRule: Apply rule ‘snmp-load’ (in /etc/icinga2/conf.d/services.conf: 147:1-147:25) for type ‘Service’ does not match anywhere!
[2018-11-22 10:28:41 +0100] warning/ApplyRule: Apply rule ‘snmp-load’ (in /etc/icinga2/conf.d/services.conf: 160:1-160:25) for type ‘Service’ does not match anywhere!
[2018-11-22 10:28:41 +0100] warning/ApplyRule: Apply rule ‘snmp-load’ (in /etc/icinga2/conf.d/services.conf: 173:1-173:25) for type ‘Service’ does not match anywhere!
[2018-11-22 10:28:41 +0100] warning/ApplyRule: Apply rule ‘snmp-load’ (in /etc/icinga2/conf.d/services.conf: 186:1-186:25) for type ‘Service’ does not match anywhere!
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 ScheduledDowntime.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 89 Services.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 IcingaApplication.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 189 Hosts.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 FileLogger.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 2 NotificationCommands.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 10 Notifications.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 NotificationComponent.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 8 HostGroups.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 ApiListener.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 Downtime.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 CheckerComponent.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 3 Zones.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 Endpoint.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 ApiUser.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 User.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 IdoMysqlConnection.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 218 CheckCommands.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 1 UserGroup.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 3 ServiceGroups.
[2018-11-22 10:28:41 +0100] information/ConfigItem: Instantiated 3 TimePeriods.
[2018-11-22 10:28:41 +0100] information/ScriptGlobal: Dumping variables to file ‘/var/cache/icinga2/icinga2.vars’
[2018-11-22 10:28:41 +0100] information/cli: Finished validating the configuration file(s).

Icinga Web 2 Version
2.6.1
Commit Git
b3e0b5d587c3587a09d82b3634dbe3a5dd315353
Data commit Gid
2018-08-02
Copyright
© 2013-2018 Il Progetto Icinga

Installed through EPEL repository on RHEL 7.6

I can’t solve the problem. I do not know why the hostgroups are not populated with the hosts.
I repeated the same configuration also for other number of CPU so I made 6 hostgroups and that’s why you see 6 warnings on the output.

I also would like to know where can I find a list of default and custom Vars, I searched through the documentation but I am unable to find it.

Thanks
Leonardo


(Marianne Spiller) #2

Hi,

can you please give it a try:

assign where "4cpu" in host.groups

It’s an array.

Cheers,
Marianne


(Leonardo) #3

:slight_smile:
You were right!
It worked!

Thank you very much.

Leonardo


#4

One tip: before writing commands, watch in the ITL, which commands are already there. Saves a lot of time!