Hello,
I’m looking for your wisdom … I’d like to process a value from a custom variable based on value from other custom/standard variable. I found a solution with intermediate step, but is there also other solution?
Scenario:
I have 3 custom variables:
vars = {
var_0 = "Clear"
var_1 = "Warning"
var_2 = "Critical"
}
and based on the actual service “state_id” (0 = OK, 1 = WARNING and 2 = CRITICAL) I’d like to use proper string from above defined custom variables (aka event severity mapping)
Within my NotificationCommand object definition I managed it like - get state_id, concatenate with “var_” string, get value of cust. variable matching the concatenated string. This works:
object NotificationCommand "notification-with-env" {
command = [ "/etc/icinga2/scripts/notification.sh" ]
vars = {
state_severity = {{ return macro("$var_" + macro("$state_id$") + "$") }}
}
env = {
STATE_ID = "$state_id$"
STATE_SEVERITY = "$state_severity$"
}
}
Questions:
- Is it possible to run “macro()” within the env dictionary (or other predefined function like “get_host()”)?
e.g.:
env = {
STATE_SEVERITY = macro("$state_id$") >> I know, assigning "$state_id$" just works, but question is about the macro() function
}
I get no value/no error …
- Is it possible to access the variables/runtime macros somehow directly within the env dictionary? I mean e.g. n-th entry from an array or to concatenate two cust. variables:
env {
NTH_ENTRY = "$my_array["$state_id$"]$" >> this troughs error obviously
CONCAT_STRINGS = "$var_" + "$state_id$" + "$" >> no errors, it just returns "state_id" (ignoring "$var_" ...?)
}
Thanks for ideas.