Hi all
I’m trying to figure out a way to use a host variable in a check command and calculate a threshold from it. If that is even possible.
The host objects have a variable host.vars.vm_cpu_cores
which the get via an import&sync. This variable simply holds the number of cpu cores as an integer value.
Now I would like to “dynamically” change the thresholds for the load check based on what the hosts cores.
by_ssh is used as check command:
object CheckCommand "by_ssh_check_load" {
import "by_ssh"
vars.by_ssh_command = [ PluginDir + "/check_load" ]
vars.by_ssh_arguments = {
"-w" = {
value = "$load_wload1$,$load_wload5$,$load_wload15$"
}
"-c" = {
value = "$load_cload1$,$load_cload5$,$load_cload15$"
}
}
...
}
Now I have tried various approaches to accomplish what I want:
vars.load_cload1 = number("$host.vars.vm_cpu_cores$")
vars.load_cload15 = number("$host.vars.vm_cpu_cores$")
vars.load_cload5 = number("$host.vars.vm_cpu_cores$")
vars.load_wload1 = number("$host.vars.vm_cpu_cores$")
vars.load_wload15 = number("$host.vars.vm_cpu_cores$")
vars.load_wload5 = number("$host.vars.vm_cpu_cores$")
vars.load_cload1 *= 2
vars.load_cload5 += 2
vars.load_wload1 += 1
vars.load_wload15 -= 1
Result:
critical/config: Error: Error while evaluating expression: Can't convert '$host.vars.vm_cpu_cores$' to a floating point number.
Location: in /etc/icinga2/zones.d/global-satellites/commands-byssh.conf: 136:22-136:55
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(134): }
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(135):
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(136): vars.load_cload1 = number("$host.vars.vm_cpu_cores$")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(137): vars.load_cload15 = number("$host.vars.vm_cpu_cores$")
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(138): vars.load_cload5 = number("$host.vars.vm_cpu_cores$")
If I encase the whole vars. part with { ... }
and remove the number()
object CheckCommand "by_ssh_check_load" {
import "by_ssh"
vars.by_ssh_command = [ PluginDir + "/check_load" ]
vars.by_ssh_arguments = {
"-w" = {
value = "$load_wload1$,$load_wload5$,$load_wload15$"
}
"-c" = {
value = "$load_cload1$,$load_cload5$,$load_cload15$"
}
}
{
vars.load_cload1 = "$host.vars.vm_cpu_cores$"
vars.load_cload15 = "$host.vars.vm_cpu_cores$"
vars.load_cload5 = "$host.vars.vm_cpu_cores$"
vars.load_wload1 = "$host.vars.vm_cpu_cores$"
vars.load_wload15 = "$host.vars.vm_cpu_cores$"
vars.load_wload5 = "$host.vars.vm_cpu_cores$"
vars.load_cload1 *= 2
vars.load_cload5 += 2
vars.load_wload1 += 1
vars.load_wload15 -= 1
}
...
the config validation is complaining about the whole package saying “Value computed is not used”.
critical/config: Error: Value computed is not used.
Location: in /etc/icinga2/zones.d/global-satellites/commands-byssh.conf: 135:3-147:3
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(133): }
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(134): }
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(135): {
^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(136): vars.load_cload1 = "$host.vars.vm_cpu_cores$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(137): vars.load_cload15 = "$host.vars.vm_cpu_cores$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(138): vars.load_cload5 = "$host.vars.vm_cpu_cores$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(139): vars.load_wload1 = "$host.vars.vm_cpu_cores$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(140): vars.load_wload15 = "$host.vars.vm_cpu_cores$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(141): vars.load_wload5 = "$host.vars.vm_cpu_cores$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(142):
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(143): vars.load_cload1 *= 2
^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(144): vars.load_cload5 += 2
^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(145): vars.load_wload1 += 1
^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(146): vars.load_wload15 -= 1
^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-satellites/commands-byssh.conf(147): }
^^^
I have also tried doing this in the Director:
template Service "linux-by_ssh-cpu" {
import "generic-service-template"
check_command = "by_ssh_check_load"
vars.load_cload1 = "$host.vars.vm_cpu_cores$ *2"
vars.load_cload15 = "$host.vars.vm_cpu_cores$"
vars.load_cload5 = "$host.vars.vm_cpu_cores$ +2"
vars.load_wload1 = "$host.vars.vm_cpu_cores$ +1"
vars.load_wload15 = "$host.vars.vm_cpu_cores$ -1"
vars.load_wload5 = "$host.vars.vm_cpu_cores$"
}
The host variable gets resolved without problems, but no calculation is happening(what I pretty much expected)
Executed command line:
'/usr/lib64/nagios/plugins/check_by_ssh' '-C' ''\''/usr/lib64/nagios/plugins/check_load'\'' '\''-c'\'' '\''2 *2,2 +2,2'\'' '\''-w'\'' '\''2 +1,2,2 -1'\'''
Long story short:
Is what I’m trying to do even possible?
Does anyone know a better way to achieve something like this without having different templates/apply rules for each number of cores?
Best regards and thanks in advance