Nagios – Sending sms notifications through twilio

I really like nodejs so am going to use it to send alerts from nagios to users mobile phones via sms. I normally use telegram for this but there was a requirement for sms.

Get the twilio_sms.js script here:

https://raw.githubusercontent.com/zs1rcm/twilio_sms/main/twilio_sms.js

This will allow you to send sms’s by typing:

node twilio_sms.js <number> <text>

In Nagios edit /etc/nagios/misc_commands.cfg and add the following two lines:

define command {
command_name notify-by-twilio-sms
command_line /etc/nagios/twilio/twilio_sms.js $CONTACTPAGER$ "[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
}
define command {
command_name host-notify-by-twilio-sms
command_line /etc/nagios/twilio/twilio_sms.js $CONTACTPAGER$ "[Nagios] $HOSTSTATE$ alert for $HOSTNAME$"
}

next edit /etc/nagios/contacts.cfg

define contact{
contact_name rm-sms2
alias Rich Mobile
service_notification_period 24×7
host_notification_period 24×7
service_notification_options c,r
host_notification_options d,r
service_notification_commands notify-by-twilio-sms
host_notification_commands notify-by-twilio-sms
pager +xxxxxxxxxx //put users mobile number here
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s