From 82a5c5a62465c27492e2d1ca7996f19384d67174 Mon Sep 17 00:00:00 2001 From: "Marianne M. Spiller" Date: Wed, 5 Apr 2017 12:29:23 +0200 Subject: [PATCH 1/3] Add notification command parameters to the default mail notification script Replace the previous notification scheme - now using getops in place of ENV variables, giving the ability to integrate with the Icinga Director. refs #5170 Signed-off-by: Michael Friedrich --- etc/icinga2/conf.d/commands.conf | 138 ++++++++++++++---- etc/icinga2/conf.d/notifications.conf | 6 +- etc/icinga2/conf.d/templates.conf | 15 +- etc/icinga2/scripts/mail-host-notification.sh | 121 +++++++++++++-- .../scripts/mail-service-notification.sh | 126 ++++++++++++++-- 5 files changed, 354 insertions(+), 52 deletions(-) diff --git a/etc/icinga2/conf.d/commands.conf b/etc/icinga2/conf.d/commands.conf index e97b087af..d40fb84e8 100644 --- a/etc/icinga2/conf.d/commands.conf +++ b/etc/icinga2/conf.d/commands.conf @@ -3,36 +3,124 @@ object NotificationCommand "mail-host-notification" { command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ] - env = { - NOTIFICATIONTYPE = "$notification.type$" - HOSTALIAS = "$host.display_name$" - HOSTADDRESS = "$address$" - HOSTSTATE = "$host.state$" - LONGDATETIME = "$icinga.long_date_time$" - HOSTOUTPUT = "$host.output$" - NOTIFICATIONAUTHORNAME = "$notification.author$" - NOTIFICATIONCOMMENT = "$notification.comment$" - HOSTDISPLAYNAME = "$host.display_name$" - USEREMAIL = "$user.email$" + arguments += { + "-4" = { + required = true + value = "$notification_address$" + } + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-f" = "$notification_from$" + "-i" = "$notification_icingaweb2url$" + "-l" = { + required = true + value = "$notification_hostname$" + } + "-n" = { + required = true + value = "$notification_hostdisplayname$" + } + "-o" = { + required = true + value = "$notification_hostoutput$" + } + "-r" = { + required = true + value = "$notification_useremail$" + } + "-s" = { + required = true + value = "$notification_hoststate$" + } + "-t" = { + required = true + value = "$notification_type$" + } + "-v" = "$notification_logtosyslog$" + } + + vars += { + notification_address = "$address$" + notification_address6 = "$address6$" + notification_author = "$notification.author$" + notification_comment = "$notification.comment$" + notification_type = "$notification.type$" + notification_date = "$icinga.long_date_time$" + notification_hostname = "$host.name$" + notification_hostdisplayname = "$host.display_name$" + notification_hostoutput = "$host.output$" + notification_hoststate = "$host.state$" + notification_useremail = "$user.email$" } } object NotificationCommand "mail-service-notification" { command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ] - env = { - NOTIFICATIONTYPE = "$notification.type$" - SERVICEDESC = "$service.name$" - HOSTALIAS = "$host.display_name$" - HOSTADDRESS = "$address$" - SERVICESTATE = "$service.state$" - LONGDATETIME = "$icinga.long_date_time$" - SERVICEOUTPUT = "$service.output$" - NOTIFICATIONAUTHORNAME = "$notification.author$" - NOTIFICATIONCOMMENT = "$notification.comment$" - HOSTDISPLAYNAME = "$host.display_name$" - SERVICEDISPLAYNAME = "$service.display_name$" - USEREMAIL = "$user.email$" + arguments += { + "-4" = { + required = true + value = "$notification_address$" + } + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-e" = { + required = true + value = "$notification_servicename$" + } + "-f" = "$notification_from$" + "-i" = "$notification_icingaweb2url$" + "-l" = { + required = true + value = "$notification_hostname$" + } + "-n" = { + required = true + value = "$notification_hostdisplayname$" + } + "-o" = { + required = true + value = "$notification_serviceoutput$" + } + "-r" = { + required = true + value = "$notification_useremail$" + } + "-s" = { + required = true + value = "$notification_servicestate$" + } + "-t" = "$notification_type$" + "-u" = { + required = true + value = "$notification_servicedisplayname$" + } + "-v" = "$notification_logtosyslog$" + } + + vars += { + notification_address = "$address$" + notification_address6 = "$address6$" + notification_author = "$notification.author$" + notification_comment = "$notification.comment$" + notification_type = "$notification.type$" + notification_date = "$icinga.long_date_time$" + notification_hostname = "$host.name$" + notification_hostdisplayname = "$host.display_name$" + notification_servicename = "$service.name$" + notification_serviceoutput = "$service.output$" + notification_servicestate = "$service.state$" + notification_useremail = "$user.email$" + notification_servicedisplayname = "$service.display_name$" } } - diff --git a/etc/icinga2/conf.d/notifications.conf b/etc/icinga2/conf.d/notifications.conf index 73f0f5f66..62057b937 100644 --- a/etc/icinga2/conf.d/notifications.conf +++ b/etc/icinga2/conf.d/notifications.conf @@ -10,18 +10,20 @@ apply Notification "mail-icingaadmin" to Host { import "mail-host-notification" - user_groups = host.vars.notification.mail.groups users = host.vars.notification.mail.users + interval = 2h + vars.notification_logtosyslog = true assign where host.vars.notification.mail } apply Notification "mail-icingaadmin" to Service { import "mail-service-notification" - user_groups = host.vars.notification.mail.groups users = host.vars.notification.mail.users + interval = 2h + vars.notification_logtosyslog = true assign where host.vars.notification.mail } diff --git a/etc/icinga2/conf.d/templates.conf b/etc/icinga2/conf.d/templates.conf index 3588f7fcf..1a8ea8328 100644 --- a/etc/icinga2/conf.d/templates.conf +++ b/etc/icinga2/conf.d/templates.conf @@ -51,6 +51,12 @@ template Notification "mail-host-notification" { FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] + vars += { + // notification_icingaweb2url = "https://www.example.com/icingaweb2" + // notification_from = "Icinga 2 Host Monitoring " + notification_logtosyslog = false + } + period = "24x7" } @@ -62,11 +68,16 @@ template Notification "mail-host-notification" { template Notification "mail-service-notification" { command = "mail-service-notification" - states = [ OK, Warning, Critical, Unknown ] + states = [ Critical, OK, Unknown, Warning ] types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] + vars += { + // notification_icingaweb2url = "https://www.example.com/icingaweb2" + // notification_from = "Icinga 2 Service Monitoring " + notification_logtosyslog = false + } + period = "24x7" } - diff --git a/etc/icinga2/scripts/mail-host-notification.sh b/etc/icinga2/scripts/mail-host-notification.sh index e1ac71664..b67b3db6b 100755 --- a/etc/icinga2/scripts/mail-host-notification.sh +++ b/etc/icinga2/scripts/mail-host-notification.sh @@ -1,20 +1,119 @@ #!/bin/sh -template=`cat <