Implementing Nagios Telephone Alerts: VoIP & Modem Solutions for System Admins


4 views

When extending Nagios monitoring to voice alerts, you have several technical approaches to consider. While commercial solutions exist, let's focus on open-source alternatives that give you full control over the implementation.

The most modern approach uses VoIP technologies. Here's how to integrate Asterisk with Nagios:

# Install Asterisk and required modules
sudo apt-get install asterisk asterisk-moh-opsound-gsm

# Configure /etc/asterisk/extensions.conf
[from-nagios]
exten => s,1,Answer()
exten => s,n,Playback(custom-alert-message)
exten => s,n,Hangup()

# Nagios command definition in commands.cfg
define command {
    command_name notify-by-phone
    command_line /usr/local/bin/send_phone_alert.sh "$NOTIFICATIONTYPE$" "$HOSTALIAS$" "$SERVICEDESC$" "$SERVICESTATE$"
}

For legacy systems or where VoIP isn't available, a modem solution works:

#!/bin/bash
# send_phone_alert.sh using modem
echo "ATDT$PHONE_NUMBER" > /dev/ttyACM0
sleep 5
echo "PLAY /var/lib/nagios/alert.wav" > /dev/ttyACM0

Services like Twilio provide REST APIs for voice calls. Here's a Python script example:

from twilio.rest import Client

account_sid = 'YOUR_ACCOUNT_SID'
auth_token = 'YOUR_AUTH_TOKEN'
client = Client(account_sid, auth_token)

call = client.calls.create(
    url='http://your-server.com/nagios-alert.xml',
    to='+1234567890',
    from_='+1987654321'
)

For dynamic alert messages, consider these TTS options:

  • Espeak: espeak -v en "Nagios alert: $HOSTNAME$ is $STATE$" --stdout | sox -t wav - alert.wav
  • Google TTS API
  • Amazon Polly

Ensure your phone alerts don't become single points of failure:

# Nagios service definition with escalation
define serviceescalation {
    host_name               server1
    service_description     HTTP
    first_notification      3
    last_notification       5
    notification_interval   10
    contact_groups          admins-by-phone
}

While SMS and email notifications are standard in Nagios monitoring, voice call alerts provide an additional layer of reliability for critical infrastructure alerts. The core technical challenge involves converting Nagios' alert system into telephony signals.

You have two primary hardware approaches:

  • Analog Modem Solution: A USRobotics 56K modem (~$50) connected via serial port
  • VoIP Gateway: Devices like Grandstream HT802 ($80) for SIP integration

Here's how to implement TTS alerts using a modem:

# Install required packages
sudo apt install alsa-utils sox mgetty

# Configure mgetty for outgoing calls
/etc/mgetty/mgetty.config:
  port ttyS0
  speed 115200
  init-chat "" "ATZ" OK "ATDT{PHONE_NUMBER}" CONNECT

Add this to your commands.cfg:

define command {
    command_name    notify-host-by-voice
    command_line    /usr/local/bin/voice_alert.sh "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTSTATE$" "$HOSTOUTPUT$"
}

voice_alert.sh implementation:

#!/bin/bash
TTS_ENGINE="/usr/bin/espeak"
MODEM_DEV="/dev/ttyS0"

# Generate alert message
$TTS_ENGINE -w /tmp/alert.wav "$1: $2 is $3 - $4"

# Initiate call
echo "ATDT1234567890" > $MODEM_DEV
sleep 10
aplay /tmp/alert.wav > $MODEM_DEV
echo "ATH" > $MODEM_DEV

For those preferring API-based solutions:

  • Twilio Programmable Voice ($0.0135/min)
  • Plivo Voice API (Pay-as-you-go pricing)
  • AWS Pinpoint SMS and Voice
  1. Test modem connectivity with minicom -D /dev/ttyS0
  2. Verify audio playback with aplay -l
  3. Check Nagios debug logs at /var/log/nagios3/nagios.log

Remember to test during off-hours and implement a call throttling mechanism to avoid alert fatigue.