Contribute  :  Web Resources  :  Site Statistics  :  About  :  RSS  
    Bart's Soapbox talk about technology and politics    

SMS support for Zabbix

   

I use the popular monitoring tool Zabbix and wanted it to be able to send messages to cellphones and pagers. The obvious solution is to use one of the Internet based gateways, but that has the obvious problem of not workign when Zabbix wants to inform me about connection problems.

The solution for this is using a modem and an sms or pager client. sms_client is a tool that combines both.

Configuring sms_client to work properly with Zabbix is not as straightforward as you might think. The problem is that the alert scripts in Zabbix are started from some PHP script. When the alert script generates output (and doesn't redirect it to some file or /dev/null) it will hang there forever once it is finished, it will never terminate. The result is that the first message works, and after that it won't work anymore.

The solution is to use a script like the one provided here:

#!/usr/local/bin/bash

NUMBER=$1
shift

MSG="ZABBIX: "$(echo $* | head -c 150 | sed -e $(printf "s/\r*//g") )

echo ${MSG} | /usr/local/bin/sms_client -l 4 kpn:${NUMBER} >>/var/log/sms_client.log

This of course assumes one receipiant per message only, but since many sms centers do not really support more then one destination anyway this is usually not an issue.

This setup has the nice side effect that you also get a session log (should normally goto /dev/null, but for now goes into /var/log/sms_client.log for debugging)

Nov. 16 2005, updated the script to strip cr/lf and ensure messages are within the limit for length.




What's Related

Story Options

SMS support for Zabbix | 3 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
SMS support for Zabbix
Authored by: Anonymous on Wednesday, October 12 2005 @ 05:49 PM CEST
Where would one plug in this script? How would zabbix know to call this script? Where would the phone numbers be input in the contact to be fed into the script?

Thanks!

SMS support for Zabbix
Authored by: bart on Wednesday, October 26 2005 @ 03:35 AM CEST

You plug the script in by defining a media type in the config section.

  1. copy the script to /home/zabbix/bin (or whatever the homedir of your zabbix user is)
  2. Click on configuration on the main page of your zabbix server
  3. Add a new media type, be sure to set the type to 'script' and the command to the name of your script.

Now you can add this media type to users. You can add the phone number in the 'send to' field, where you'd normally put the email address for example.

Dutch KPN 'semafoon' (pager) support
Authored by: bart on Wednesday, November 16 2005 @ 06:04 PM CET

In order to get text messages to pagers in the Netherlands you will need to make a few modifications to sms_client and use a script like the this:

#!/usr/local/bin/bash
#
# Zabbix text pager notification script
# (C) 2005 Bart van Leeuwen
#

NUMBER=$1
shift

# Note, messages to text pagers are limited to 80 characters

MSG="$(echo $* | head -c 80 | sed -e $(printf "s/r*//g") )"

echo ${MSG} | /usr/local/bin/sms_client -l 4 kpntap:${NUMBER} >>/var/log/sema_client.log

KPN supports a variety of protocols for sending pager messages, I tested both TAP and UCP. In order for those to work you will have to add 2 lines to the sms_services file and create 2 new service configuration files:

In /usr/local/etc/sms/sms_services you need to add the following:

        kpntap                  = "TAP"
        kpnucp                  = "UCP"

You also have to add two configuration files in /usr/local/etc/sms/services/:

kpntap

# --------------------------------------------------------------------
# Sample SMS resource file for PTT/KPN Telcom (TAP)
# --------------------------------------------------------------------

{
        SMS_comms_params = "7E1"          # 8 Data, No Parity, 1 Stop Bit
        SMS_baud         = 19200

        # ------------------------------------------------------------
        # The SMSCnumber MUST be defined.
        # This is the number of your local message center.
        # ------------------------------------------------------------

        SMS_centre_number = "0665181803"  # PTT/KPN Telcom service
                                          # centre number (TAP)
}

# --------------------------------------------------------------------

kpnucp

# --------------------------------------------------------------------
# Sample SMS resource file for PTT/KPN Telcom (UCP)
# --------------------------------------------------------------------

{
        SMS_comms_params = "7E1"          # 8 Data, No Parity, 1 Stop Bit
        SMS_baud         = 19200

        # ------------------------------------------------------------
        # The SMSCnumber MUST be defined.
        # This is the number of your local message center.
        # ------------------------------------------------------------

        SMS_centre_number = "0665181802"  # PTT/KPN Telcom service
                                          # centre number (UCP)
}

# --------------------------------------------------------------------
 Copyright © 2014 Bart's Soapbox
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.29 seconds 
Powered by Apache Powered by FreeBSD