icinga2 – push notifications to your smartphone with pushover
Inhaltsverzeichnis
Register at https://pushover.net/
iPhone App: https://itunes.apple.com/de/app/pushover-notifications/id506088175?mt=8
Your user key (log in and confirm the email): https://pushover.net/
Your Devices -> iPhone -> Activate Encryption
Create a new Application to get your api token key: https://pushover.net/apps
Create the pushover script for icinga2 to the official api:
vim /etc/icinga2/scripts/pushover.pl #!/usr/bin/perl use LWP::UserAgent; use Mozilla::CA; LWP::UserAgent->new()->post( "https://api.pushover.net/1/messages.json", [ "token" => "aizowaTOKENpcg5fdthz", "user" => "u6obubUSERkdjtcveq", "message" => $ENV{'message'}, "title" => $ENV{'title'}, ]);
Create the text template which is sent to your device:
vim /etc/icinga2/zones.d/master/commands/pushover.conf object NotificationCommand "push-notification" { import "plugin-notification-command" command = [ SysconfDir + "/icinga2/scripts/pushover.pl" ] env = { title = "$service.display_name$ on $host.display_name$: Status changed to $service.state$" message = "$service.output$" } }
Add the notification template
vim /etc/icinga2/zones.d/master/templates.conf template Host "notification-enabled" { vars.notification_enabled = true } template Service "notification-enabled" { vars.notification_enabled = true }
Add the notification to the specific services you configured ( import )
vim /etc/icinga2/zones.d/master/services/ssh.conf apply Service "ssh" { import "notification-enabled" import "5minute-service" check_command = "ssh" assign where host.vars.os == "Linux" }
Add the apply notification template for the services and hosts
vim /etc/icinga2/zones.d/master/notifications.conf apply Notification "push-notification" to Host { users = [ "mattionline" ] command = "push-notification" types = [ Problem, Recovery, Acknowledgement ] states = [ Critical, Warning, Unknown ] interval = 0 assign where host.vars.notification_enabled == true } apply Notification "push-notification" to Service { users = [ "mattionline" ] command = "push-notification" types = [ Problem, Recovery, Acknowledgement ] states = [ Critical, Warning, Unknown ] interval = 0 assign where service.vars.notification_enabled == true }
Add the notification user
vim /etc/icinga2/zones.d/master/users.conf object User "mattionline" { import "generic-user" display_name = "mattionline" email = "info@mattionline.de" }
chown nagios:nagios pushover.pl chmod +x pushover.pl apt-get install perl liblwp-protocol-https-perl perl -MCPAN -e 'install Mozilla::CA' systemctl restart icinga2
Debug: tailf -n 100 /var/log/icinga2/icinga2.log
[2016-10-03 14:43:30 +0200] warning/PluginNotificationTask: Notification command for object ‚oldpi.mattionline.lan!ntp_time‘ (PID: 2193, arguments: ‚/etc/icinga2/scripts/pushover.pl‘) terminated with exit code 128, output: execvpe(/etc/icinga2/scripts/pushover.pl) failed: Permission denied
chmod +x 😉
Hey, I followed this script but I keep getting an error on this line
import „notification-enabled“
When i attach it to a service I want alerted on. Whats the deal with that?
Do you have the „template Service“ entry too?