Skip to content

Instantly share code, notes, and snippets.

@cyper85
Created January 20, 2016 15:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyper85/ab8bc2d1aea6a1adc88d to your computer and use it in GitHub Desktop.
Save cyper85/ab8bc2d1aea6a1adc88d to your computer and use it in GitHub Desktop.
Nagios Notfication via Telegram
# 'notify-host-by-telegram' command definition
define command{
command_name notify-host-by-telegram
command_line /usr/bin/curl -X POST --data chat_id=$CONTACTPAGER$ --data text="***** Nagios *****%0A%0ANotification Type: $NOTIFICATIONTYPE$%0AHost: $HOSTNAME$%0AState: $HOSTSTATE$%0AAddress: $HOSTADDRESS$%0AInfo: $HOSTOUTPUT$%0A%0ADate/Time:
$LONGDATETIME$%0A" https://api.telegram.org/bot$BOT-TOKEN$/sendMessage
}
# 'notify-service-by-telegram' command definition
define command{
command_name notify-service-by-telegram
command_line /usr/bin/curl -X POST --data chat_id=$CONTACTPAGER$ --data text="***** Nagios *****%0A%0ANotification Type: $NOTIFICATIONTYPE$%0A%0AService: $SERVICEDESC$%0AHost: $HOSTALIAS$%0AAddress: $HOSTADDRESS$%0AState: $SERVICESTATE$%0A%0
ADate/Time: $LONGDATETIME$%0A%0AAdditional Info:%0A%0A$SERVICEOUTPUT$%0A" https://api.telegram.org/bot$BOT-TOKEN$/sendMessage
}
define contact {
contact_name andreas-telegram
alias Andreas Neumann
service_notification_options w,u,c,r
service_notification_period 24x7
host_notification_period 24x7
service_notification_commands notify-service-by-telegram
host_notification_commands notify-host-by-telegram
host_notification_options d,r
pager $CHAT-ID$
}
#!/bin/sh
# This is a sample shell script showing how you can submit the SEND_CUSTOM_HOST_NOTIFICATION command
# to Nagios. Adjust variables to fit your environment as necessary.
now=`date +%s`
commandfile='/var/lib/nagios3/rw/nagios.cmd'
/usr/bin/printf "[%lu] SEND_CUSTOM_HOST_NOTIFICATION;blog.stadtplan-ilmenau.de;3;andreas-telegram;Sinnlose Notification als Test?!?\n" $now > $commandfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment