Icinga2 sending Pushover alerts revisited
Using Icinga2 to monitor your infrastructure is great. Here is my second edition of the script that enables your Icinga to alert you using the Pushover service.
A while back I wrote about Pushover notification with Icinga 2.
I have recently been helping an Icinga administrator who was not getting his Pushover alerts. This had led to the second edition.
What is new is that the notify_by_pushover2 script now checks if Pushover accepted the message, and if it did not it logs the response and exits with a failure that will be readable in the icinga2 log file. The icinga2 log file is in /var/log/icinga2/icinga2.log on my system.
I will repeat the instructions here, except the Pushover-script is changed.
Here is the quick guide to making your Icinga 2 do notifications using the Pushover service.
You need to create one file - notify_by_pushover2.sh in my example. Permissions on that file need to be like the existing files in the same folder. My script is based on what i learnt from the script found in Using Pushover to push Nagios notifications.
You need to edit four files: commands.conf, templates.conf, notifications.conf and users.conf. This is assuming the out of the box default configuration files are used.
The text that i show in my examples below is text that you should add to the existing configuration files, you should not replace the existing text in those files.
In my example notifications.conf i use some "assign where" that relate to mail. I know this could be done in a more clean way.
/etc/icinga2/scripts/notify_by_pushover2.sh
#!/bin/sh
response=$(curl --write-out %{http_code} --silent \
-F "token=$PUSHOVERTOKEN" \
-F "user=$PUSHOVERUSER" \
-F "title=$PUSHOVERTITLE" \
-F "message=$PUSHOVERMESSAGE" \
https://api.pushover.net/1/messages)
if [[ "$response" == *200 ]]
then
echo Pushover message sent succesfully
exit 0
else
echo Activation of Pushover service failed. This is the response from Pushover: $response
exit 1
fi
/etc/icinga2/conf.d/commands.conf
object NotificationCommand "pushover-host-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/notify_by_pushover2.sh" ]
env = {
PUSHOVERUSER = "$user.vars.pushover_user$"
PUSHOVERTOKEN = "$user.vars.pushover_token$"
PUSHOVERTITLE = "Icinga Skanderborg"
PUSHOVERMESSAGE = "$notification.type$ $host.display_name$ $host.state$ $icinga.long_date_time$"
}
}
object NotificationCommand "pushover-service-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/notify_by_pushover2.sh" ]
env = {
PUSHOVERUSER = "$user.vars.pushover_user$"
PUSHOVERTOKEN = "$user.vars.pushover_token$"
PUSHOVERTITLE = "Icinga"
PUSHOVERMESSAGE = "$notification.type$ $host.display_name$ $service.display_name$ $service.state$ $icinga.long_date_time$"
}
}
/etc/icinga2/conf.d/templates.conf
template Notification "pushover-host-notification" {
command = "pushover-host-notification"
states = [ Up, Down ]
types = [ Problem, Acknowledgement, Recovery, Custom,
FlappingStart, FlappingEnd,
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
period = "24x7"
}
template Notification "pushover-service-notification" {
command = "pushover-service-notification"
states = [ OK, Warning, Critical, Unknown ]
types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
period = "24x7"
}
/etc/icinga2/conf.d/notifications.conf
apply Notification "pushover-icingaadmin" to Host {
import "pushover-host-notification"
user_groups = host.vars.notification.mail.groups
users = host.vars.notification.mail.users
assign where host.vars.notification.mail
interval = 0 // disable re-notification
}
apply Notification "pushover-icingaadmin" to Service {
import "pushover-service-notification"
user_groups = host.vars.notification.mail.groups
users = host.vars.notification.mail.users
assign where host.vars.notification.mail
interval = 0 // disable re-notification
}
/etc/icinga2/conf.d/users.conf
object User "icingaadmin" {
import "generic-user"
display_name = "Icinga 2 Admin"
groups = [ "icingaadmins" ]
email = "admin@bruntt.dk"
vars.pushover_user = "YOUR PUSHOVER USER TOKEN HERE"
vars.pushover_token = "YOUR PUSHOVER APPLICATION TOKEN HERE"
}