Hello,
I am working on building up a new Icinga2 Setup in our Environment, in which I want to try to automatize as much as possible.
In the last days I created a Master → Satellite → Agent setup to try migrating hand written configuration from our old Icinga2 Setup into Director. Now I reached a point, where I am not able to implement a CheckCommand into director that works like expected.
The old Config:
object CheckCommand "infiniband_rate" {
import "plugin-check-command"
command = [ PluginDir + "/check_ib_link" ]
arguments = {
"-a" = {
description = "List of active port(s)"
value = "$ib_port$"
}
"-d" = {
description = "HCA device to check"
value = "$ib_device$"
}
"-r" = {
description = "Expected rate in Gb/sec."
value = "$ib_rate$"
}
}
}
apply Service "infiniband" {
import "generic-service"
if ( "sys/infiniband/mlx4_port1_40" in host.vars.groups) {
// infinband device mlx4, port 1, 40GB rate
vars.ib_port = "1"
vars.ib_device = "mlx4_0"
vars.ib_rate = "40"
} else if ( "sys/infiniband/mlx4_port1_56" in host.vars.groups) {
// infinband device mlx4, port 1, 56GB rate
vars.ib_port = "1"
vars.ib_device = "mlx4_0"
vars.ib_rate = "56"
} else if ( "sys/infiniband/mlx5_port1_40" in host.vars.groups) {
// infinband device mlx5, port 1, 40GB rate
vars.ib_port = "1"
vars.ib_device = "mlx5_0"
vars.ib_rate = "40"
} else if ( "sys/infiniband/mlx5_port1_56" in host.vars.groups) {
// infinband device mlx5, port 1, 56GB rate
vars.ib_port = "1"
vars.ib_device = "mlx5_0"
vars.ib_rate = "56"
} else if ( "sys/infiniband/mlx5_port1_100" in host.vars.groups) {
// infinband device mlx5, port 1, 100GB rate
vars.ib_port = "1"
vars.ib_device = "mlx5_0"
vars.ib_rate = "100"
} else if ( "sys/infiniband/mlx5_port2_100" in host.vars.groups) {
// infinband device mlx5, port 2, 100GB rate
vars.ib_port = "2"
vars.ib_device = "mlx5_2"
vars.ib_rate = "100"
}
display_name = "Infiniband interface " + host.vars.ib_port
check_command = "infiniband_rate"
if (host.name != NodeName) {
command_endpoint = host.name
}
assign where "sys/infiniband" in host.vars.groups
}
The groups like sys/infiniband have been imported from our CMDB as dicts and looks now like:
object Host "s002.domain.net" {
import "generic-agent"
display_name = "s002"
address = "xxx.xxx.240.12"
zone = "xxx"
vars.centos = {
centos7 = {
cluster = true
}
}
vars.redhatel = true
vars.redhatel7 = true
vars.server = true
vars.sys = {
icinga2 = {
client = true
zone = {
xxx = true
}
}
infiniband = {
mlx5_port1_100 = true
}
openssh = true
platform_mpi = true
prometheus = true
racadm = true
resolver = true
}
vars.vendor = {
dell = {
poweredge = {
c6525 = true
}
}
}
}
I read somewhere on the internet, that conditions on custom host variables should be done inside the CheckCommando not on the ApplyService.
So, I try to do this, but I am failing to found the right syntax for the condition. Inside the Director Command preview it shows this:
object CheckCommand "infiniband_rate" {
import "plugin-check-command"
command = [ PluginDir + "/check_ib_link" ]
arguments += {
"-a" = {
description = "List of active port(s)"
required = true
value = {{
if (host.vars.sys.infiniband.mlx5_port2_100) {
return "2"
} else {
return "1"
}
}}
}
"-d" = {
description = "HCA device to check"
required = true
value = {{
if (host.vars.sys.infiniband.mlx4_port1_40) {
return "mlx4_0"
} else if (host.vars.sys.infiniband.mlx4_port1_56) {
return "mlx4_0"
} else if (host.vars.sys.infiniband.mlx5_port1_40) {
return "mlx5_0"
} else if (host.vars.sys.infiniband.mlx5_port1_56) {
return "mlx5_0"
} else if (host.vars.sys.infiniband.mlx5_port1_100) {
return "mlx5_0"
} else if (host.vars.sys.infiniband.mlx5_port2_100) {
return "mlx5_2"
}
}}
}
"-r" = {
description = "Expected rate in Gb/sec."
required = true
value = {{
if (host.vars.sys.infiniband.mlx4_port1_40) {
return "40"
} else if (host.vars.sys.infiniband.mlx4_port1_56) {
return "56"
} else if (host.vars.sys.infiniband.mlx5_port1_40) {
return "40"
} else if (host.vars.sys.infiniband.mlx5_port1_56) {
return "56"
} else if (host.vars.sys.infiniband.mlx5_port1_100) {
return "100"
} else if (host.vars.sys.infiniband.mlx5_port2_100) {
return "100"
} else {
return false
}
}}
}
}
}
They me be other elegant ways to do this inside Director, but I really want to understand how to call the custom vars here. I am also grateful for suggestion for other solutions.
For me it looks like that inside the command condition host.vars.sys.infiniband.mlx* is not available, but I saw similar examples on the net. So, I am wondering what I am do wrong here.
- Director version (System - About):1.9.0
- Icinga Web 2 version and modules (System - About): 2.9.5
- Icinga 2 version (
icinga2 --version
): 2.13.2-1 - Operating System and version: RockyLinux 8
- Webserver, PHP versions:
- Apache 2.4.37-41
- PHP 7.4.19