Skip to content

Nagios notifications via Telegram

dariomas edited this page May 17, 2016 · 1 revision

Nagios notifications via Telegram

First create a Telegram Bot by talking to the BotFather. The Telegram Bot will be the sender of the Nagios alerts. You’ll receive an API token that also includes the UserID of the Bot:

Token: 123456789:ABCdEFGHIjKLMNoPQRSTUVWXYZ1q2w3e4R5t UserID: 123456789

Get your UserID or GroupID

To receive Nagios alerts in a Telegram group chat, create a group chat and invite the Bot. The GroupID (id g135790246) of the Alerts group chat needs to be configured in the Nagios configuration as a negative number (-135790246)

Download the nagios_telegram.py script that will send the alerts via Telegram:

chmod 755 /usr/local/bin/nagios_telegram.py

Configure in Nagios

# commands to send host/service notifications
define command {
  command_name     notify-host-by-telegram
  command_line     /usr/local/bin/nagios_telegram.py --token $USER4$ --object_type host --contact $USER3$ --notificationtype "$NOTIFICATIONTYPE$" --hoststate "$HOSTSTATE$" --hostname "$HOSTNAME$" --hostaddress "$HOSTADDRESS$" --datetime "$LONGDATETIME$" --output "$HOSTOUTPUT$"
}
define command {
  command_name     notify-service-by-telegram
  command_line     /usr/local/bin/nagios_telegram.py --token $USER4$ --object_type service --contact $USER3$ --notificationtype "$NOTIFICATIONTYPE$" --servicestate "$SERVICESTATE$" --hostname "$HOSTNAME$" --hostaddress "$HOSTADDRESS$" --datetime "$LONGDATETIME$" --output "$SERVICEOUTPUT$" --servicedesc "$SERVICEDESC$" --servicename "$SERVICENAME$"
}

Edit /usr/local/nagios/etc/resource.cfg

$USER3$=-135790246
$USER4$=123456789:ABCdEFGHIjKLMNoPQRSTUVWXYZ1q2w3e4R5t
Clone this wiki locally