diff options
| -rw-r--r-- | master-secrets.conf.example | 5 | ||||
| -rwxr-xr-x | scripts/mail-host-notification.sh | 169 | ||||
| -rwxr-xr-x | scripts/mail-service-notification.sh | 174 | ||||
| -rwxr-xr-x | scripts/telegram-host-notification.sh | 89 | ||||
| -rwxr-xr-x | scripts/telegram-service-notification.sh | 92 | ||||
| -rw-r--r-- | zones.d/global-templates/hosts.conf | 9 | ||||
| l--------- | zones.d/master/features/notification.conf | 1 | ||||
| -rw-r--r-- | zones.d/master/notification-commands.conf | 201 | ||||
| -rw-r--r-- | zones.d/master/notifications.conf | 72 | ||||
| -rw-r--r-- | zones.d/master/users.conf | 15 |
10 files changed, 827 insertions, 0 deletions
diff --git a/master-secrets.conf.example b/master-secrets.conf.example index 18f5cf7..ce70605 100644 --- a/master-secrets.conf.example +++ b/master-secrets.conf.example @@ -2,3 +2,8 @@ * PGSQL password for the icinga user */ const SecretPgsqlPassword = "db password" + +/* + * Telegram bot token + */ +const TelegramBotToken = "token" diff --git a/scripts/mail-host-notification.sh b/scripts/mail-host-notification.sh new file mode 100755 index 0000000..2a2c011 --- /dev/null +++ b/scripts/mail-host-notification.sh @@ -0,0 +1,169 @@ +#!/bin/sh +# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ +# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license + +PROG="`basename $0`" +ICINGA2HOST="`hostname`" +MAILBIN="mail" + +if [ -z "`which $MAILBIN`" ] ; then + echo "$MAILBIN not found in \$PATH. Consider installing it." + exit 1 +fi + +## Function helpers +Usage() { +cat << EOF + +Required parameters: + -d LONGDATETIME (\$icinga.long_date_time\$) + -l HOSTNAME (\$host.name\$) + -n HOSTDISPLAYNAME (\$host.display_name\$) + -o HOSTOUTPUT (\$host.output\$) + -r USEREMAIL (\$user.email\$) + -s HOSTSTATE (\$host.state\$) + -t NOTIFICATIONTYPE (\$notification.type\$) + +Optional parameters: + -4 HOSTADDRESS (\$address\$) + -6 HOSTADDRESS6 (\$address6\$) + -b NOTIFICATIONAUTHORNAME (\$notification.author\$) + -c NOTIFICATIONCOMMENT (\$notification.comment\$) + -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) + -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)) + -v (\$notification_sendtosyslog\$, Default: false) + +EOF +} + +Help() { + Usage; + exit 0; +} + +Error() { + if [ "$1" ]; then + echo $1 + fi + Usage; + exit 1; +} + +urlencode() { + local LANG=C i=0 c e s="$1" + + while [ $i -lt ${#1} ]; do + [ "$i" -eq 0 ] || s="${s#?}" + c=${s%"${s#?}"} + [ -z "${c#[[:alnum:].~_-]}" ] || c=$(printf '%%%02X' "'$c") + e="${e}${c}" + i=$((i + 1)) + done + echo "$e" +} + +## Main +while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt +do + case "$opt" in + 4) HOSTADDRESS=$OPTARG ;; + 6) HOSTADDRESS6=$OPTARG ;; + b) NOTIFICATIONAUTHORNAME=$OPTARG ;; + c) NOTIFICATIONCOMMENT=$OPTARG ;; + d) LONGDATETIME=$OPTARG ;; # required + f) MAILFROM=$OPTARG ;; + h) Help ;; + i) ICINGAWEB2URL=$OPTARG ;; + l) HOSTNAME=$OPTARG ;; # required + n) HOSTDISPLAYNAME=$OPTARG ;; # required + o) HOSTOUTPUT=$OPTARG ;; # required + r) USEREMAIL=$OPTARG ;; # required + s) HOSTSTATE=$OPTARG ;; # required + t) NOTIFICATIONTYPE=$OPTARG ;; # required + v) VERBOSE=$OPTARG ;; + \?) echo "ERROR: Invalid option -$OPTARG" >&2 + Error ;; + :) echo "Missing option argument for -$OPTARG" >&2 + Error ;; + *) echo "Unimplemented option: -$OPTARG" >&2 + Error ;; + esac +done + +shift $((OPTIND - 1)) + +## Keep formatting in sync with mail-service-notification.sh +for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME HOSTOUTPUT HOSTSTATE USEREMAIL NOTIFICATIONTYPE ; do + eval "PAR=\$${P}" + + if [ ! "$PAR" ] ; then + Error "Required parameter '$P' is missing." + fi +done + +## Build the message's subject +SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!" + +## Build the notification message +NOTIFICATION_MESSAGE=`cat << EOF +***** Host Monitoring on $ICINGA2HOST ***** + +$HOSTDISPLAYNAME is $HOSTSTATE! + +Info: $HOSTOUTPUT + +When: $LONGDATETIME +Host: $HOSTNAME +EOF +` + +## Check whether IPv4 was specified. +if [ -n "$HOSTADDRESS" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv4: $HOSTADDRESS" +fi + +## Check whether IPv6 was specified. +if [ -n "$HOSTADDRESS6" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv6: $HOSTADDRESS6" +fi + +## Check whether author and comment was specified. +if [ -n "$NOTIFICATIONCOMMENT" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +Comment by $NOTIFICATIONAUTHORNAME: + $NOTIFICATIONCOMMENT" +fi + +## Check whether Icinga Web 2 URL was specified. +if [ -n "$ICINGAWEB2URL" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +$ICINGAWEB2URL/monitoring/host/show?host=$(urlencode "$HOSTNAME")" +fi + +## Check whether verbose mode was enabled and log to syslog. +if [ "$VERBOSE" = "true" ] ; then + logger "$PROG sends $SUBJECT => $USEREMAIL" +fi + +## Send the mail using the $MAILBIN command. +## If an explicit sender was specified, try to set it. +if [ -n "$MAILFROM" ] ; then + + ## Modify this for your own needs! + + ## Debian/Ubuntu use mailutils which requires `-a` to append the header + if [ -f /etc/debian_version ]; then + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL + ## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r` + else + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL + fi + +else + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ + | $MAILBIN -s "$SUBJECT" $USEREMAIL +fi diff --git a/scripts/mail-service-notification.sh b/scripts/mail-service-notification.sh new file mode 100755 index 0000000..c901f23 --- /dev/null +++ b/scripts/mail-service-notification.sh @@ -0,0 +1,174 @@ +#!/bin/sh +# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ +# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license + +PROG="`basename $0`" +ICINGA2HOST="`hostname`" +MAILBIN="mail" + +if [ -z "`which $MAILBIN`" ] ; then + echo "$MAILBIN not found in \$PATH. Consider installing it." + exit 1 +fi + +## Function helpers +Usage() { +cat << EOF + +Required parameters: + -d LONGDATETIME (\$icinga.long_date_time\$) + -e SERVICENAME (\$service.name\$) + -l HOSTNAME (\$host.name\$) + -n HOSTDISPLAYNAME (\$host.display_name\$) + -o SERVICEOUTPUT (\$service.output\$) + -r USEREMAIL (\$user.email\$) + -s SERVICESTATE (\$service.state\$) + -t NOTIFICATIONTYPE (\$notification.type\$) + -u SERVICEDISPLAYNAME (\$service.display_name\$) + +Optional parameters: + -4 HOSTADDRESS (\$address\$) + -6 HOSTADDRESS6 (\$address6\$) + -b NOTIFICATIONAUTHORNAME (\$notification.author\$) + -c NOTIFICATIONCOMMENT (\$notification.comment\$) + -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) + -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)) + -v (\$notification_sendtosyslog\$, Default: false) + +EOF +} + +Help() { + Usage; + exit 0; +} + +Error() { + if [ "$1" ]; then + echo $1 + fi + Usage; + exit 1; +} + +urlencode() { + local LANG=C i=0 c e s="$1" + + while [ $i -lt ${#1} ]; do + [ "$i" -eq 0 ] || s="${s#?}" + c=${s%"${s#?}"} + [ -z "${c#[[:alnum:].~_-]}" ] || c=$(printf '%%%02X' "'$c") + e="${e}${c}" + i=$((i + 1)) + done + echo "$e" +} + +## Main +while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt +do + case "$opt" in + 4) HOSTADDRESS=$OPTARG ;; + 6) HOSTADDRESS6=$OPTARG ;; + b) NOTIFICATIONAUTHORNAME=$OPTARG ;; + c) NOTIFICATIONCOMMENT=$OPTARG ;; + d) LONGDATETIME=$OPTARG ;; # required + e) SERVICENAME=$OPTARG ;; # required + f) MAILFROM=$OPTARG ;; + h) Usage ;; + i) ICINGAWEB2URL=$OPTARG ;; + l) HOSTNAME=$OPTARG ;; # required + n) HOSTDISPLAYNAME=$OPTARG ;; # required + o) SERVICEOUTPUT=$OPTARG ;; # required + r) USEREMAIL=$OPTARG ;; # required + s) SERVICESTATE=$OPTARG ;; # required + t) NOTIFICATIONTYPE=$OPTARG ;; # required + u) SERVICEDISPLAYNAME=$OPTARG ;; # required + v) VERBOSE=$OPTARG ;; + \?) echo "ERROR: Invalid option -$OPTARG" >&2 + Usage ;; + :) echo "Missing option argument for -$OPTARG" >&2 + Usage ;; + *) echo "Unimplemented option: -$OPTARG" >&2 + Usage ;; + esac +done + +shift $((OPTIND - 1)) + +## Keep formatting in sync with mail-host-notification.sh +for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME SERVICENAME SERVICEDISPLAYNAME SERVICEOUTPUT SERVICESTATE USEREMAIL NOTIFICATIONTYPE ; do + eval "PAR=\$${P}" + + if [ ! "$PAR" ] ; then + Error "Required parameter '$P' is missing." + fi +done + +## Build the message's subject +SUBJECT="[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!" + +## Build the notification message +NOTIFICATION_MESSAGE=`cat << EOF +***** Service Monitoring on $ICINGA2HOST ***** + +$SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE! + +Info: $SERVICEOUTPUT + +When: $LONGDATETIME +Service: $SERVICENAME +Host: $HOSTNAME +EOF +` + +## Check whether IPv4 was specified. +if [ -n "$HOSTADDRESS" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv4: $HOSTADDRESS" +fi + +## Check whether IPv6 was specified. +if [ -n "$HOSTADDRESS6" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv6: $HOSTADDRESS6" +fi + +## Check whether author and comment was specified. +if [ -n "$NOTIFICATIONCOMMENT" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +Comment by $NOTIFICATIONAUTHORNAME: + $NOTIFICATIONCOMMENT" +fi + +## Check whether Icinga Web 2 URL was specified. +if [ -n "$ICINGAWEB2URL" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +$ICINGAWEB2URL/monitoring/service/show?host=$(urlencode "$HOSTNAME")&service=$(urlencode "$SERVICENAME")" +fi + +## Check whether verbose mode was enabled and log to syslog. +if [ "$VERBOSE" = "true" ] ; then + logger "$PROG sends $SUBJECT => $USEREMAIL" +fi + +## Send the mail using the $MAILBIN command. +## If an explicit sender was specified, try to set it. +if [ -n "$MAILFROM" ] ; then + + ## Modify this for your own needs! + + ## Debian/Ubuntu use mailutils which requires `-a` to append the header + if [ -f /etc/debian_version ]; then + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL + ## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r` + else + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL + fi + +else + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ + | $MAILBIN -s "$SUBJECT" $USEREMAIL +fi diff --git a/scripts/telegram-host-notification.sh b/scripts/telegram-host-notification.sh new file mode 100755 index 0000000..5d42709 --- /dev/null +++ b/scripts/telegram-host-notification.sh @@ -0,0 +1,89 @@ +#!/bin/sh +# (C) Tobias Wiese | GPLv2+ +# This file is based on mail-host-notification.sh from Icinga used under GPLv2+ license +# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license +# Changes: The script was adapted to send Telegram Messages instead of mail. + +PROG="$(basename $0)" +ICINGA2HOST="$(hostname)" + +if [ -z "$(type curl)" ] ; then + echo "curl not found in \$PATH. Consider installing it." 2>&1 + exit 1 +fi + +## Function helpers +urlencode() { + local LANG=C i=0 c e s="$1" + + while [ $i -lt ${#1} ]; do + [ "$i" -eq 0 ] || s="${s#?}" + c=${s%"${s#?}"} + [ -z "${c#[[:alnum:].~_-]}" ] || c=$(printf '%%%02X' "'$c") + e="${e}${c}" + i=$((i + 1)) + done + echo "$e" +} + +## Keep formatting in sync with telegram-service-notification.sh +for P in DATE HOSTNAME HOSTDISPLAYNAME HOSTOUTPUT HOSTSTATE USERCHATID TYPE +do + eval "PAR=\$${P}" + + if [ ! "$PAR" ] ; then + echo "Required parameter '$P' is missing." >&2 + exit 1 + fi +done + +## Build the notification message +NOTIFICATION_MESSAGE=`cat << EOF +***** Host Monitoring on $ICINGA2HOST ***** + +$HOSTDISPLAYNAME is $HOSTSTATE! + +Info: $HOSTOUTPUT + +When: $DATE +Host: $HOSTNAME +EOF +` + +## Check whether IPv4 was specified. +if [ -n "$ADDRESS" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv4: $ADDRESS" +fi + +## Check whether IPv6 was specified. +if [ -n "$ADDRESS6" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv6: $ADDRESS6" +fi + +## Check whether author and comment was specified. +if [ -n "$COMMENT" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +Comment by $AUTHOR: + $COMMENT" +fi + +## Check whether Icinga Web 2 URL was specified. +if [ -n "$ICINGAWEB2URL" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +$ICINGAWEB2URL/monitoring/host/show?host=$(urlencode "$HOSTNAME")" +fi + +## Check whether verbose mode was enabled and log to syslog. +if [ "$VERBOSE" = "true" ] ; then + logger "$PROG sends Telegram => $CHATID" +fi + +## Send message via telegram +curl -X POST "https://api.telegram.org/bot${TOKEN}/sendMessage" \ + --data-urlencode "chat_id=$USERCHATID" \ + --data-urlencode "text=$NOTIFICATION_MESSAGE" \ + --data-urlencode "disable_web_page_preview=true" diff --git a/scripts/telegram-service-notification.sh b/scripts/telegram-service-notification.sh new file mode 100755 index 0000000..c5815ec --- /dev/null +++ b/scripts/telegram-service-notification.sh @@ -0,0 +1,92 @@ +#!/bin/sh +#!/bin/sh +# (C) Tobias Wiese | GPLv2+ +# This file is based on mail-service-notification.sh from Icinga used under GPLv2+ license +# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license +# Changes: The script was adapted to send Telegram Messages instead of mail. + +PROG="$(basename $0)" +ICINGA2HOST="$(hostname)" + +if [ -z "$(type curl)" ] ; then + echo "curl not found in \$PATH. Consider installing it." 2>&1 + exit 1 +fi + +## Function helpers +urlencode() { + local LANG=C i=0 c e s="$1" + + while [ $i -lt ${#1} ]; do + [ "$i" -eq 0 ] || s="${s#?}" + c=${s%"${s#?}"} + [ -z "${c#[[:alnum:].~_-]}" ] || c=$(printf '%%%02X' "'$c") + e="${e}${c}" + i=$((i + 1)) + done + echo "$e" +} + +## Keep formatting in sync with telegram-host-notification.sh +for P in DATE HOSTNAME HOSTDISPLAYNAME SERVICENAME SERVICEDISPLAYNAME \ + SERVICEOUTPUT SERVICESTATE USERCHATID TYPE +do + eval "PAR=\$${P}" + + if [ ! "$PAR" ] ; then + echo "Required parameter '$P' is missing." >&2 + exit 1 + fi +done + +## Build the notification message +NOTIFICATION_MESSAGE=`cat << EOF +***** Service Monitoring on $ICINGA2HOST ***** + +$SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE! + +Info: $SERVICEOUTPUT + +When: $DATE +Service: $SERVICENAME +Host: $HOSTNAME +EOF +` + +## Check whether IPv4 was specified. +if [ -n "$ADDRESS" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv4: $ADDRESS" +fi + +## Check whether IPv6 was specified. +if [ -n "$ADDRESS6" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +IPv6: $ADDRESS6" +fi + +## Check whether author and comment was specified. +if [ -n "$COMMENT" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +Comment by $AUTHOR: + $COMMENT" +fi + +## Check whether Icinga Web 2 URL was specified. +if [ -n "$ICINGAWEB2URL" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE + +$ICINGAWEB2URL/monitoring/service/show?host=$(urlencode "$HOSTNAME")&service=$(urlencode "$SERVICENAME")" +fi + +## Check whether verbose mode was enabled and log to syslog. +if [ "$VERBOSE" = "true" ] ; then + logger "$PROG sends Telegram => $CHATID" +fi + +## Send message via telegram +curl -X POST "https://api.telegram.org/bot${TOKEN}/sendMessage" \ + --data-urlencode "chat_id=$USERCHATID" \ + --data-urlencode "text=$NOTIFICATION_MESSAGE" \ + --data-urlencode "disable_web_page_preview=true" diff --git a/zones.d/global-templates/hosts.conf b/zones.d/global-templates/hosts.conf index e301dcf..ccc8007 100644 --- a/zones.d/global-templates/hosts.conf +++ b/zones.d/global-templates/hosts.conf @@ -1,3 +1,12 @@ template Host "generic-host" { check_command = "hostalive" + + /* Notifications */ + vars.notification["mail"] = { + groups = [ "hostmaster" ] + } + + vars.notification["telegram"] = { + groups = [ "hostmaster" ] + } } diff --git a/zones.d/master/features/notification.conf b/zones.d/master/features/notification.conf new file mode 120000 index 0000000..b143504 --- /dev/null +++ b/zones.d/master/features/notification.conf @@ -0,0 +1 @@ +../../../features-available/notification.conf
\ No newline at end of file diff --git a/zones.d/master/notification-commands.conf b/zones.d/master/notification-commands.conf new file mode 100644 index 0000000..57b15fe --- /dev/null +++ b/zones.d/master/notification-commands.conf @@ -0,0 +1,201 @@ +template NotificationCommand "generic-notification" { + vars += { + notification_address = "$address$" + notification_address6 = "$address6$" + notification_author = "$notification.author$" + notification_comment = "$notification.comment$" + notification_date = "$icinga.long_date_time$" + notification_icingaweb2url = IcingaWebUrl + notification_hostdisplayname = "$host.display_name$" + notification_hostname = "$host.name$" + notification_type = "$notification.type$" + } +} + +template NotificationCommand "generic-host-notification" { + import "generic-notification" + vars += { + notification_hostoutput = "$host.output$" + notification_hoststate = "$host.state$" + } +} + +template NotificationCommand "generic-service-notification" { + import "generic-notification" + vars += { + notification_servicedisplayname = "$service.display_name$" + notification_servicename = "$service.name$" + notification_serviceoutput = "$service.output$" + notification_servicestate = "$service.state$" + } +} + +object NotificationCommand "mail-host-notification" { + import "generic-host-notification" + + command = [ ConfigDir + "/scripts/mail-host-notification.sh" ] + + arguments += { + "-4" = "$notification_address$" + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-f" = { + value = "$notification_from$" + description = "Set from address." + } + "-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_useremail = "$user.email$" + } +} + +object NotificationCommand "mail-service-notification" { + import "generic-service-notification" + + command = [ ConfigDir + "/scripts/mail-service-notification.sh" ] + + arguments += { + "-4" = "$notification_address$" + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-e" = { + required = true + value = "$notification_servicename$" + } + "-f" = { + value = "$notification_from$" + description = "Set from address." + } + "-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" = { + required = true + value = "$notification_type$" + } + "-u" = { + required = true + value = "$notification_servicedisplayname$" + } + "-v" = "$notification_logtosyslog$" + } + + vars += { + notification_useremail = "$user.email$" + } +} + +object NotificationCommand "telegram-host-notification" { + import "generic-host-notification" + + command = [ ConfigDir + "/scripts/telegram-host-notification.sh" ] + + env = { + ADDRESS = "$notification_address$" + ADDRESS6 = "$notification_address6$" + AUTHOR = "$notification_author$" + COMMENT = "$notification_comment$" + DATE = "$notification_date$" + ICINGAWEB2URL = "$notification_icingaweb2url$" + HOSTDISPLAYNAME = "$notification_hostdisplayname$" + HOSTNAME = "$notification_hostname$" + TYPE = "$notification_type$" + + HOSTOUTPUT = "$notification_hostoutput$" + HOSTSTATE = "$notification_hoststate$" + + USERCHATID = "$notification_userchatid$" + TOKEN = "$notification_token$" + } + + vars += { + notification_userchatid = "$user.vars.telegram$" + notification_token = TelegramBotToken + } +} + +object NotificationCommand "telegram-service-notification" { + import "generic-service-notification" + + command = [ ConfigDir + "/scripts/telegram-service-notification.sh" ] + + env = { + ADDRESS = "$notification_address$" + ADDRESS6 = "$notification_address6$" + AUTHOR = "$notification_author$" + COMMENT = "$notification_comment$" + DATE = "$notification_date$" + ICINGAWEB2URL = "$notification_icingaweb2url$" + HOSTDISPLAYNAME = "$notification_hostdisplayname$" + HOSTNAME = "$notification_hostname$" + TYPE = "$notification_type$" + + SERVICEDISPLAYNAME = "$notification_servicedisplayname$" + SERVICENAME = "$notification_servicename$" + SERVICEOUTPUT = "$notification_serviceoutput$" + SERVICESTATE = "$notification_servicestate$" + + USERCHATID = "$notification_userchatid$" + TOKEN = "$notification_token$" + } + + vars += { + notification_userchatid = "$user.vars.telegram$" + notification_token = TelegramBotToken + } +} diff --git a/zones.d/master/notifications.conf b/zones.d/master/notifications.conf new file mode 100644 index 0000000..b980851 --- /dev/null +++ b/zones.d/master/notifications.conf @@ -0,0 +1,72 @@ +template Notification "generic-notification" { + types = [ + Problem, + Acknowledgement, + Recovery, + Custom, + FlappingStart, + FlappingEnd, + ] +} + +template Notification "generic-host-notification" { + import "generic-notification" + states = [ Up, Down ] +} + +template Notification "generic-service-notification" { + import "generic-notification" + states = [ OK, Warning, Critical, Unknown ] +} + +apply Notification "mail" to Host { + import "generic-host-notification" + + command = "mail-host-notification" + + user_groups = host.vars.notification.mail.groups + users = host.vars.notification.mail.users + + interval = 2h + + assign where host.vars.notification.mail +} + +apply Notification "mail" to Service { + import "generic-service-notification" + + command = "mail-service-notification" + + user_groups = host.vars.notification.mail.groups + users = host.vars.notification.mail.users + + interval = 2h + + assign where host.vars.notification.mail +} + +apply Notification "telegram" to Host { + import "generic-host-notification" + + command = "telegram-host-notification" + + user_groups = host.vars.notification.telegram.groups + users = host.vars.notification.telegram.users + + interval = 2h + + assign where host.vars.notification.telegram +} + +apply Notification "telegram" to Service { + import "generic-service-notification" + + command = "telegram-service-notification" + + user_groups = host.vars.notification.telegram.groups + users = host.vars.notification.telegram.users + + interval = 2h + + assign where host.vars.notification.telegram +} diff --git a/zones.d/master/users.conf b/zones.d/master/users.conf new file mode 100644 index 0000000..03072d3 --- /dev/null +++ b/zones.d/master/users.conf @@ -0,0 +1,15 @@ +template User "generic-user" { } + +object User "hostmaster" { + import "generic-user" + + display_name = "tobiaswiese.net Hostmaster" + groups = [ "hostmaster" ] + + email = "hostmaster@tobiaswiese.net" + vars.telegram = -1001430477767 +} + +object UserGroup "hostmaster" { + display_name = "tobiaswiese.net Hostmaster Group" +} |
