Icinga2 Notifications: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 238: | Zeile 238: | ||
</pre> | </pre> | ||
− | ==notification zu host-datei hinzufügen== | + | ==notification zu host-datei oder template hinzufügen== |
<pre> | <pre> | ||
vars.notification["telegram"] = { | vars.notification["telegram"] = { |
Aktuelle Version vom 8. Dezember 2017, 10:33 Uhr
E-Mail Benachrichtigung einrichten
- Die meisten Dinge wurden hier schon durch das Icinga2-Team angelegt
- Es werden daher auch keine Plugins, Command- und Notification-Definitionen mehr benötigt
- Lediglich die E-Mail-Addresse an welche die Mails versandt werden sollen muss eingetragen werden
E-Mail-Addresse eintragen
- vi /etc/icinga2/zones.d/global-templates/users.conf
/** * The example user 'icingaadmin' and the example * group 'icingaadmins'. */ object User "icingaadmin" { import "generic-user" display_name = "Icinga 2 Admin" groups = [ "icingaadmins" ] email = "tech@xinux.int" } object UserGroup "icingaadmins" { display_name = "Icinga 2 Admin Group" }
Mail-Benachrichtigung zu Host-Datei oder Template hinzufügen
vars.notification["mail"] = { groups = [ "icingaadmins" ] }
Benachrichtigungs-Intervalle einrichten
- times.begin setzt hierbei eine Wartezeit bis die erste Benachrichtigung versandt wird
- interval setzt die Zeiträume zwischen den Benachrichtigungsversuchen fest
- falls das versenden von Nachrichten nach einem bestimmten Zeitraum enden soll kann auch noch ein times.end gesetzt werden
template Notification "mail-service-notification" { command = "mail-service-notification" states = [ OK, Warning, Critical, Unknown ] types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] interval = 15m times.begin = 30m vars += { // notification_icingaweb2url = "https://www.example.com/icingaweb2" // notification_from = "Icinga 2 Service Monitoring <icinga@example.com>" notification_logtosyslog = false } period = "24x7" }
Telegram-Benachrichtigung einrichten
Vorraussetzungen
- Auf einem Smartphone installiertes und aktiviertes Telegram
Bot auf Smartphone einrichten
Chat-ID herraus finden
Unbedingt vorher dem Bot ein "Hallo" schicken, sonst erhält man im folgenden Schritt keinen Output!
- TOKEN="4620711675:AAEfhUw7TMdGuFJjo4beRvQrpuWERNzPBD8"
- curl --silent https://api.telegram.org/bot${TOKEN}/getUpdates
{"ok":true,"result":[{"update_id":300872536, "message":{"message_id":353,"from":{"id":501616824,"is_bot":false,"first_name":"Herr","last_name":"Schmidt?","username":"Herr_Janning","language_code":"de"},"chat":{"id":-213374873,"first_name":"Herr","last_name":"Schmidt?","username":"Herr_Janning","type":"private"},"date":1511447683,"text":"Hallo"}}]}
- Der folgende Teil, zwischen den Leerzeilen, aus dem oberen Output ist der wichtige
{"ok":true,"result":[{"update_id":300872536, "message":{"message_id":353,"from":{"id":501616824,"is_bot":false,"first_name":"Herr","last_name":"Schmidt?","username":"Herr_Janning","language_code":"de"}, "chat":{"id":-213374873, "first_name":"Herr","last_name":"Schmidt?","username":"Herr_Janning","type":"private"},"date":1511447683,"text":"Hallo"}}]}
Chat-ID verrifizieren
- /usr/bin/curl --silent --output /dev/null --data-urlencode "chat_id="-213374873" --data-urlencode "text=Hallo welt" https://api.telegram.org/bot${TOKEN}/sendMessage
- Wenn der Bot in Telegram ein "Hallo Welt" sendet stimmt die Chat-ID
Plugins herrunter laden und ins Verzeichnis kopieren
- git clone https://github.com/lazyfrosch/icinga2-telegram.git
- cd icinga2-telegram
- mv telegram-host-notification.sh telegram-service-notification.sh /etc/icinga2/scripts
- cd /etc/icinga2/scripts
- chmod +x telegram-host-notification.sh telegram-service-notification.sh
command definieren
- /etc/icinga2/zones.d/global-templates/commands.conf
object NotificationCommand "telegram-host-notification" { import "plugin-notification-command" command = [ SysconfDir + "/icinga2/scripts/telegram-host-notification.sh" ] env = { NOTIFICATIONTYPE = "$notification.type$" HOSTNAME = "$host.name$" 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$" TELEGRAM_BOT_TOKEN = "462071178:AAEfhUw7TMdGuFJjo4beRvQrpuWndNzPBD8" TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$" // optional ICINGAWEB2_URL = "http://10.82.50.25/icingaweb2" } } object NotificationCommand "telegram-service-notification" { import "plugin-notification-command" command = [ SysconfDir + "/icinga2/scripts/telegram-service-notification.sh" ] env = { NOTIFICATIONTYPE = "$notification.type$" SERVICEDESC = "$service.name$" HOSTNAME = "$host.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$" TELEGRAM_BOT_TOKEN = "462071178:AAEfhUw7TMdGuFJjo4beRvQrpuWndNzPBD8" TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$" // optional ICINGAWEB2_URL = "http://10.82.50.25/icingaweb2" } }
templates anlegen
- vi /etc/icinga2/zones.d/global-templates/templates.conf
template Notification "telegram-host-notification" { command = "telegram-host-notification" states = [ Up, Down ] types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] interval = 30m times.begin = 60m vars += { // notification_icingaweb2url = "https://www.example.com/icingaweb2" // notification_from = "Icinga 2 Host Monitoring <icinga@example.com>" notification_logtosyslog = false } period = "24x7" } /** * Provides default settings for service notifications. * By convention all service notifications should import * this template. */ template Notification "telegram-service-notification" { command = "telegram-service-notification" states = [ OK, Warning, Critical, Unknown ] types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] interval = 30m times.begin = 60m vars += { // notification_icingaweb2url = "https://www.example.com/icingaweb2" // notification_from = "Icinga 2 Service Monitoring <icinga@example.com>" notification_logtosyslog = false } period = "24x7" }
notifications anlegen
apply Notification "telegram-icingaadmin" to Host { import "telegram-host-notification" command = "telegram-host-notification" users = [ "icingaadmin" ] assign where host.vars.notification.telegram } apply Notification "telegram-icingaadmin" to Service { import "telegram-service-notification" command = "telegram-service-notification" users = [ "icingaadmin" ] assign where host.vars.notification.telegram }
chat-id zu users.conf hinzufügen
/** * The example user 'icingaadmin' and the example * group 'icingaadmins'. */ object User "icingaadmin" { import "generic-user" display_name = "Icinga 2 Admin" groups = [ "icingaadmins" ] vars.telegram_chat_id = "-213374873" email = "tech@xinux.int" } object UserGroup "icingaadmins" { display_name = "Icinga 2 Admin Group" }
notification zu host-datei oder template hinzufügen
vars.notification["telegram"] = { groups = [ "icingaadmins" ] }