Recently I needed to setup a Zabbix distribution with SMS notifications. I had a Momo Design MD-@ USB Internet key to be used as GSM modem, with a BT Italia (Vodafone) SIM card. I used the 1.8.5 version of Zabbix, installed using the apt tool on a Ubuntu 11.10.
The Zabbix built-in SMS notification system seemed to have a bug, which cause a triple notification to be sent on every trigger action (bug ID ZBX-3507), so I preferred to use an external (custom) script and a third party tool: gammu-smsd.
This daemon connects to the GSM modem and listens for an outgoing queue; when you need to send a message, you just have to “inject” it into its queue, then it does the rest.
As soon as I plugged the USB key into the server, Ubuntu recognized it:
Oct 27 13:57:08 MyMachineName kernel: [764858.260009] usb 4-1: new full speed USB device number 2 using uhci_hcd
Oct 27 13:57:08 MyMachineName kernel: [764858.481158] cdc_acm 4-1:1.0: ttyACM0: USB ACM device
Oct 27 13:57:08 MyMachineName kernel: [764858.484118] usbcore: registered new interface driver cdc_acm
Oct 27 13:57:08 MyMachineName kernel: [764858.484121] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
Then I installed gammu-smsd and edited its configuration file:
apt-get install gammu-smsd
# Configuration file for Gammu SMS Daemon
# Gammu library configuration, see gammurc(5)
# Please configure this!
port = /dev/ttyACM0
connection = at
logformat = textall
# SMSD configuration, see gammu-smsdrc(5)
service = files
logfile = /var/log/gammu-smsd
# Increase for debugging information
debuglevel = 0
ReceiveFrequency = 300
# Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/
The port parameter is the device where the modem is mapped. This may change on other system.
I changed the logfile parameter also, because by default it is configured to log to syslog. You need to give the right permissions to it:
chmod a+rw /var/log/gammu-smsd
The ReceiveFrequency is used to tell gammu-smsd how often to check for incoming SMS; by default it is every 1 second, but in my case I didn’t need to receive SMS, so I raised it to 5 minutes.
An important parameter is PIN on the [smsd] section: in my case I removed the PIN check from my SIM card, so I didn’t use it in the configuration file.
In order to avoid “Cannot open file” errors, I also granted access to the device to everyone:
chmod a+rw /dev/ttyACM0
At this time I reloaded gammu-smsd and tested the configuration:
echo "Test message" | gammu-smsd-inject TEXT 335123456
(replace 335123456 with your mobile phone number!)
The gammu-smsd-monitor utility let you to check your modem status too.
In order to rotate gammu-smsd log file, I wrote a logrotate.d configuration file too:
As first I configured a new media type using the Zabbix administration front-end:
Administration / Media types -> Create Media Type
Script name: sendsms
sendsms is the name of the external script I used for my custom notification system.
Then I configured the new media type for my Zabbix user:
Administration / Users -> select Users in the top right corner – edit your user Media: Add
Send to: 335123456
When active, Use if severity: as you wish
Of course, I had an Action configured too, but for more information I suggest you to read about it on the official documentation page.
In order to configure Zabbix to use external notification scripts, I verified that the AlertScriptsPath was present in the configuration file:
cat /etc/zabbix/zabbix_server.conf | grep AlertScriptsPath
/etc/zabbix/alert.d is the directory where notifications script have to be.
Then I added the zabbix user to the gammu group, in order to give it the right permissions to inject messages into the outgoing gammu queue…
adduser zabbix gammu
… then I restarted Zabbix:
This is the script I used to inject Zabbix notifications into the gammu outgoing queue (/etc/zabbix/alert.d/sendsms):
# $1 recipient
# $2 subject
# $3 message
echo "$3" >> $TMPFILE
cat $TMPFILE | gammu-smsd-inject TEXT $1
chmod a+x /etc/zabbix/alert.d/sendsms
At this time I tested it by creating a new trigger with fake values (temperature < 100 °C, or everything else could let an action to be raised).
Zabbix.com: Configuration page on the official documentation site
gammu-smsd: Gammu SMSD