Hi,
I am trying to create a template that will add a common http_check to our hosts. We have an “apply Notification” conf that refuses to play with it.
Template:
template Host "MyTemplate" {
import "generic-host"
groups = [ "api", ]
display_name = "MyTemplate"
check_command = "http"
enable_perfdata = true
command_endpoint = ""
vars.http_checks.isAlive.http_address = "$host.vars.isAlive_address$"
vars.http_checks.isAlive.http_uri = "$host.vars.isAlive_uri$"
vars.http_checks.isAlive.http_ssl = true
vars.http_checks.isAlive.http_string = true
vars.http_checks.isAlive.warning_notification = "host.vars.isAlive_warning_notification",
vars.http_checks.isAlive.critical_notification = "host.vars.isAlive_critical_notification"
}
Host
object Host "MyHost" {
import "MyTemplate"
address = "myhost.com"
groups = [ "DevOps", ]
display_name = "MyHostNew"
check_command = "dummy"
vars.isAlive_address = "myhost.com"
vars.isAlive_uri = "/IsAlive"
vars.isAlive_critical_notification = [ "team-devops-high", ]
vars.isAlive_warning_notification = [ "team-devops-low", ]
apply Notification "pagerduty_warn_service" to Service {
assign where service.vars.warning_notification && service.vars.warning_notification.len() > 0
users = [""]
if (typeof(service.vars.warning_notification) == Array) {
users = service.vars.warning_notification
}
command = "notify-service-by-pagerduty-agent"
period = "24x7"
types = [ Problem, Acknowledgement, Recovery ]
states = [ OK, Warning ]
}
apply Notification "pagerduty_critical_service" to Service {
assign where service.vars.critical_notification && service.vars.critical_notification.len() > 0
users = [""]
if (typeof(service.vars.critical_notification) == Array) {
users = service.vars.critical_notification
}
command = "notify-service-by-pagerduty-agent"
period = "24x7"
types = [ Problem, Acknowledgement, Recovery ]
states = [ OK, Critical ]
}
Icinga fails with:
[2019-07-22 11:05:32 +0000] critical/config: Error: Validation failed for object 'MyHost!http_checkisAlive!pagerduty_critical_service' of type 'Notification'; Attribute 'users': Object '' of type 'User' does not exist.
Location: in /etc/icinga2/conf.d/apply_notifications.conf: 16:3-16:14
/etc/icinga2/conf.d/apply_notifications.conf(14): apply Notification "pagerduty_critical_service" to Service {
/etc/icinga2/conf.d/apply_notifications.conf(15): assign where service.vars.critical_notification && service.vars.critical_notification.len() > 0
/etc/icinga2/conf.d/apply_notifications.conf(16): users = [""]
^^^^^^^^^^^^
/etc/icinga2/conf.d/apply_notifications.conf(17): if (typeof(service.vars.critical_notification) == Array) {
/etc/icinga2/conf.d/apply_notifications.conf(18): users = service.vars.critical_notification
[2019-07-22 11:05:32 +0000] critical/config: Error: Validation failed for object 'MyHost!http_checkisAlive!pagerduty_warn_service' of type 'Notification'; Attribute 'users': Object '' of type 'User' does not exist.
Location: in /etc/icinga2/conf.d/apply_notifications.conf: 4:3-4:14
/etc/icinga2/conf.d/apply_notifications.conf(2): apply Notification "pagerduty_warn_service" to Service {
/etc/icinga2/conf.d/apply_notifications.conf(3): assign where service.vars.warning_notification && service.vars.warning_notification.len() > 0
/etc/icinga2/conf.d/apply_notifications.conf(4): users = [""]
^^^^^^^^^^^^
/etc/icinga2/conf.d/apply_notifications.conf(5): if (typeof(service.vars.warning_notification) == Array) {
/etc/icinga2/conf.d/apply_notifications.conf(6): users = service.vars.warning_notification
I’m not sure about how apply notification works but all I want is for the notification arrays to be applied correctly to the templates. I’d appreciate any help offered.
Regards,