• Command Expansion
Skip to end of metadata
Go to start of metadata

General

Jochen Bern contributed a nice patch to the config.cgi which is mainly called "Command expander". It is linked throughout the Classic UI (check the extinfo.cgi for service information and follow the link below "ACTIVE" e.g.).

The main intention is to resolve all passed $ARGn$ macros into their given values. Currently, all other macros such as $USERn$ or $HOSTADDRESS$ are not resolved, because the expander just doesn't know it yet (remains a todo within #1329)

There's still the possibility to translate those values with pen and paper (wink)

Command Expander

Host State Information - ACTIVE

expanded command

View Config Selection

Own command

Own command expanded

View from the Host config list - check-mk-ping url

Manual Expansion

$ARGn$ macros are being passed by seperating them with '!'.

$USER1$ definition in resource.cfg

# Sets $USER1$ to be the path to the plugins
$USER1$=/usr/lib/nagios/plugins

Command definition

define  command {
        command_name    check_ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5 -4
}

Service definition

define service {
        host_name       localhost
        service_description     PING4
        check_command   check_ping!500.0,20%!800.0,60%
...
}

Associated host definition, holding address.

define host {
        host_name       localhost
        address 127.0.0.1
...
}

Now you can map the following

  • $USER1$ - check resource.cfg = /usr/lib/nagios/plugins
  • $HOSTADRESS$ - map host_name from service and host, and get host address = 127.0.0.1
  • $ARG1$ - first argument = 500.0,20%
  • $ARG2$ - second argument = 800.0,60%

Final command as Icinga would call it:

/usr/lib/nagios/plugins/check_ping -H 127.0.0.1 -w 500.0,20% -c 800.0,60% -p 5 -4

Test it as icinga user.

DO NOT run it as root, or with root environment!
If the icinga user did not get a shell, change it temporary in /etc/passwd from /bin/false (or /sbin/nologin) to /bin/bash (or /binsh).

# su - icinga
$ env -i
$ /usr/lib/nagios/plugins/check_ping -H 127.0.0.1 -w 500.0,20% -c 800.0,60% -p 5 -4
  • No labels