Hello guys,
I tried to use a function to determine a command to apply within a
CheckCommand.
This is described here, but for a NotificationCommand.
https://github.com/Icinga/icinga2/blob/master/doc/5-advanced-topics.md#use-functions-command-attribute
Here is what I have:
object CheckCommand "my-check" {
import "plugin-check-command"
command = {{
var my_check_script = "check_script_one"
if (service.vars.my_var) {
my_check_script = "check_script_two"
}
var cmd = [ PluginDir + "/" + my_check_script ]
return cmd
}}
arguments = {
...
}
}
So, my idea was that a variable is set within a "apply Service" definition
and that's what then controls the condition in the CheckCommand.
Unfortunatelly, it doesn't work. The error I got is here:
critical/config: Error: Validation failed for Object 'my-check' (Type:
'CheckCommand') at
/etc/icinga2/zones.d/global-templates/checkcommand.conf:10: Attribute
'command' must be an array if the 'arguments' attribute is set.
The cmd is actually defined as an array…so the problem must be something
else.
If I understand correctly, what I did is a lambda function ( {{ ... }},
https://github.com/Icinga/icinga2/blob/master/doc/20-language-reference.md#nullary-lambdas
).
I tried to define it as a function ( { ... } ), which lead to different
error:
critical/config: Error: Error while evaluating expression: Tried to access
undefined script variable 'service'
I guess a service context is missing?
Is this wrong idea, any ideas?
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users