Hello all!
I’m following along with https://icinga.com/docs/icinga2/latest/doc/08-advanced-topics/#time-dependent-thresholds to setup a time-dependent thresholds for a check, and I keep getting a syntax error for the if statement for the threshold and I’m not sure what is causing this.
Relevent files and file snippits:
Error from icinga2 daemon -C
# icinga2 daemon -C
[2020-02-27 10:03:39 -0700] information/cli: Icinga application loader (version: 2.11.2-1)
[2020-02-27 10:03:39 -0700] information/cli: Loading configuration file(s).
[2020-02-27 10:03:39 -0700] critical/config: Error: syntax error, unexpected '{'
Location: in /etc/icinga2/zones.d/global-templates/service_apply.conf: 224:47-224:47
/etc/icinga2/zones.d/global-templates/service_apply.conf(222): vars.rab_queue = "exm-TaskRunner"
/etc/icinga2/zones.d/global-templates/service_apply.conf(223): vars.rab_queue_warn_thresh = {{
/etc/icinga2/zones.d/global-templates/service_apply.conf(224): if (get_time_period("jobrun".is_inside) {
^
/etc/icinga2/zones.d/global-templates/service_apply.conf(225): return "50000,-1,-1,9:"
/etc/icinga2/zones.d/global-templates/service_apply.conf(226): } else{
[2020-02-27 10:03:39 -0700] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.
/etc/icinga2/zones.d/global-templates/service_apply.conf:
apply Service "exm-TaskRunner RabbitMQ Queue" {
import "check_rabbitmq_queue"
assign where "RabbitMQ Server" in host.templates && "ProdServers" in host.groups
vars.rab_queue = "exm-TaskRunner"
vars.rab_queue_warn_thresh = {{
if (get_time_period("jobrun".is_inside) {
return "50000,-1,-1,5:"
} else{
return "500,-1,-1,5:"
}
}}
vars.rab_queue_crit_thresh = {{
if (get_time_period("jobrun".is_inside) {
return "55000,-1,-1,2:"
} else{
return "600,-1,-1,2:"
}
}}
}
/etc/icinga2/zones.d/global-templates/service_templates.conf
template Service "check_rabbitmq_queue" {
import "generic-service"
check_command = "check_rabbitmq_queue"
}
/etc/icinga2/zones.d/global-templates/timeperiods.conf
object TimePeriod "jobrun" {
display_name = "When Jobs Run"
ranges = {
"monday" = "23:30-00:30"
"tuesday" = "23:30-00:30"
"wednesday" = "23:30-00:30"
"thursday" = "23:30-00:30"
"friday" = "23:30-00:30"
"saturday" = "23:30-00:30"
"sunday" = "23:30-00:30"
}
}
/etc/icinga2/zones.d/global-templates/command_templates.conf
template CheckCommand "generic-rabbitmq-command" {
import "plugin-check-command"
arguments += {
"--no-proxy" = {
description = "Do not use environment proxy (default: false)"
set_if = "$no-proxy$"
}
"--no_ssl_strict" = {
description = "Do not verify SSL certificate (default: false)"
set_if = "$no-check-ssl$"
}
"--port" = {
description = "Specify the port to connect to (default: 15672)"
value = "$rab_port_num$"
}
"-H" = {
description = "Specify the host to connect to"
value = "$host.name$"
}
"-p" = {
description = "Password (default: guest)"
value = "$rab_pass$"
}
"-ssl" = {
description = "Use SSL (default: false)"
set_if = "$use-ssl$"
}
"-t" = {
description = "Seconds before plugin times out (default: 15)"
value = "$rab_timeout$"
}
"-u" = {
description = "Username (default: guest)"
value = "$rab_user$"
}
}
}
object CheckCommand "check_rabbitmq_queue" {
import "plugin-check-command"
import "generic-rabbitmq-command"
command = [
PluginDir + "/rabbitmq-scripts/check_rabbitmq_queue"
]
timeout = 30s
arguments += {
"--filter" = {
description = "Specify the queues to filter for the check. It's a perl regex (default: .*)"
value = "$rab_queue_filter$"
}
"--queue" = {
description = "Specify the queue to check (default: all)"
value = "$rab_queue$"
}
"--vhost" = {
description = "Specify the vhost where the queue resides (default: /)"
value = "$rab_queue_vhost$"
}
"-c" = {
description = "Critical thresholds specified in following order: messages[,messages_ready[,messages_unacknowledged[,consumers]]] Specify -1 if no critical threshold."
value = "$rab_queue_crit_thresh$"
}
"-w" = {
description = "Warning thresholds specified in following order: messages[,messages_ready[,messages_unacknowledged[,consumers]]] Specify -1 if no warning threshold."
value = "$rab_queue_warn_thresh$"
}
}
}
Can anyone see what I might be missing or might be doing wrong? If I format it without the Time Dependent Threshold(i.e. just use one value for the variable), it will pass through and work without issue.
