Hi.
I also can’t say much about the director, but here - as an example -
a complete way to create a service and assign it dynamically to specific hosts.
It is supposed to also help other users, so just skip the parts you already know.
A service typically requires 3 parts to get it working:
-
A plugin-file,
in this case check_mem.pl.
Under Centos, typically placed unter /usr/lib64/nagios/plugins/.
(On Debian based systems under /usr/lib/nagios/plugins).
Staying at this example: /usr/lib64/nagios/plugins/check_mem.pl
This can be also executed at the commandline for first tests.
It is just “something” which can be executed and returns requested information and an exit status.
0 = OK
1 = warning
2 = critical
3 = unknown
Based on this status, Icinga2 will interpret the service. -
Now we require a CheckCommand,
which uses the plugin from step 1.
Fortunately, in this case this has already been done (part of the Icinga Template Library - ITL). The CheckCommand defines how to use the plugin from step 1 (arguments, values).
In this case:
CheckCommand definition
# Taken from: /usr/share/icinga2/include/plugins-contrib.d/operating-system.conf
object CheckCommand "mem" {
command = [ PluginContribDir + "/check_mem.pl" ]
arguments = {
"-u" = {
set_if = "$mem_used$"
description = "Check USED memory"
}
"-f" = {
set_if = "$mem_free$"
description = "Check FREE memory"
}
"-C" = {
set_if = "$mem_cache$"
description = "Count OS caches as FREE memory"
}
"-w" = {
value = "$mem_warning$"
description = "Percent free/used when to warn"
}
"-c" = {
value = "$mem_critical$"
description = "Percent free/used when critical"
}
}
vars.mem_used = false
vars.mem_free = false
vars.mem_cache = false
}
So there already is a CheckCommand names “mem” which we can use
- Now we need a service, which uses the CheckCommand (“mem”).
We need to take care, that the check is executed at the agent, not at the master (or satellite).
So we need to set the “command_endpoint”.
This also means, the the plugin (in this case: check_mem.pl) has to be placed in the plugin-directory of the target system (where the check is executed) and has to be executable by the user “icinga” (on RedHat based systems) or “nagios” (on Debian based systems)
Example of a Service Defition with apply-rule
apply Service "memory" {
import "generic-service"
check_interval = 1m
// Using the CheckCommand from step 2
check_command = "mem"
// Execute this at the agent-machine, not elsewhere
command_endpoint = host.name
vars.mem_used = true
vars.mem_cache = true
vars.mem_warning = 80
vars.mem_critical = 90
assign where host.vars.os == "Linux"
ignore where host.vars.noagent
}
What we got until now
So what we got until here:
- A plugin
- a CheckCommand definition (“mem”),
- a Service using the CheckCommand definition (service name: “memory”)
This service will be applied to all hosts which have set the (host-)variable vars.os = “Linux”,
hosts without an agent will be ignored (we want the check to be executed by agent on the target system, so an agent is required).
- Example output - taken from debug-log
OK - 17.5% (356896 kB) used.|TOTAL=2041320KB;;;; USED=356896KB;1633056;1837188;; FREE=1684424KB;;;; CACHES=1572432KB;;;;
Greetings.