Sunday, February 26, 2012

How to configure sms alert on gnokii on CentOS

1. plug your phone into Linux box
2. install gnokii
#yum install gnokii
3. configure gnokii to use our phone: configuration file is /etc/gnokiirc


# Set port to the physical port used to connect to your phone.
port = /dev/ttyACM0

# Change it according to instructions
model = AT
# Set model to the model number of your phone. For the
# Symbian phones use:
initlength = default

# cable with nk6510 driver.
connection = serial
# port software (eg. minicom). If you have wrong permissions for the
# directory, a warning will be generated. If you don't want a lockfile, set
# it to 'no'.
use_locking = no

# Baudrate to use on serial port connections.
# Currently used only by models AT and BIP/CIMD. Defaults to 19200.
serial_baudrate = 19200

# Gnokii "AT" model uses software handshake by default.
# Possible values: hardware (RTS/CTS - 7 wires) or software (XON/XOFF - 3 wires)
#handshake = software
# forever.
smsc_timeout = 10

# Set this to 1 if you want to break your phone with xgnokii. Works only
# with few Nokia models and FBUS communication
allow_breakage = 0

# Set bindir to point to the location of the various gnokiid binaries.
# In particular ensure that mgnokiidev is in this location, with
# permissions 4750, owned by root, group gnokii.  Ensure you
# are in the gnokii group and that the group exists...
bindir = /usr/sbin/

# Any entries in the following two sections will be set as environment
# variables when running the scripts.
# Handy for use for $VAR substitutions in your chat(8) script.
# Don't put your phone number here!!!
TELEPHONE = 12345678


# The following parameters control how libgnokii handles the debugging messages.
# Currently there are three categories: "debug" controls the libgnokii
# normal debug output, "rlpdebug" controls the debug output of the RLP
# subsystem, and "xdebug" is used by the xgnokii or smsd.


# where to log the debug output (on: stderr, off: /dev/null)
debug = on

# where to log the rlp debug output (on: stderr, off: /dev/null)
rlpdebug = off

# where to log X debug output (on: stderr, off: /dev/null)
xdebug = off

port = foobar
model = fake
connection = serial

# This is internal configuration for fake driver. The purpose is mostly
# testing only.
sms_inbox = /tmp/sms

4. define command in nagios to alert with sms in file /usr/local/nagios/etc/objects/commands.cfg

define command {
        command_name notify-service-by-sms
        command_line /usr/bin/printf "%b" "Nagios - $NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ IP: $HOSTADDRESS$ ($OUTPUT$)" | /usr/bin/gnokii --sendsms $CONTACTPAGER$ -r

define command {
        command_name notify-host-by-sms
        command_line /usr/bin/printf "%b" "Nagios - $NOTIFICATIONTYPE$ : Host $HOSTALIAS$:ip $HOSTADDRESS$ is $HOSTSTATE$ ($OUTPUT$)" | /usr/bin/gnokii --sendsms $CONTACTPAGER$ -r
5. define template contact to alert with sms in file /usr/local/nagios/etc/objects/templates.cfg
define contact{
        name                            sms-test         ; The name of this contact template
        service_notification_period     24x7                    ; service notifications can be sent anytime
        host_notification_period        24x7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-sms ; send service notifications via email
        host_notification_commands      notify-host-by-sms    ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
 6. define who will receive the sms in file  /usr/local/nagios/etc/objects/contacts.cfg

define  contact{
        contact_name                    dara
        use                             sms-test
        alias                           dara
        pager                           +85515765093
 define contactgroup{
        contactgroup_name       group-sms
        alias                   Nagios admin
        members                 dara

#note: members can be add more than one

7. define host that we will receive sms if the host is down or unreachable

define host{
        use                    linux-server            ; Name of host template to use
        host_name               mail-server-01
        alias                   mail postfix and pop3
        contact_groups          group-sms

define hostgroup{
        hostgroup_name  server-group ; The name of the hostgroup
        alias           server farm group ; Long name of the group
        members         mail-server-01     ; Comma separated list of hosts that belong to this group
8. add user nagios to dialup group
[root@nagios-01]# ls /dev/ttyACM0 -l
crw-rw---- 1 root uucp 166, 0 Feb 26 16:14 /dev/ttyACM0

[root@nagios-01]# usermod -a -G uucp nagios

9. restart nagios service

[root@nagios-01]#  /etc/init.d/nagios restart



  1. Excelente aporte, pero e seguido al pie de la letra para que envie mensajes por un celular, tengo bien configurado el gnokii y nagios perono no envia sms al momento que el dispositivo que estoy monitoreando, me puede talves indicar algun directorio donde puedo ver los logs para ver el problema

  2. hello i have a problem with gnokii when i want to send a sms with nagios user i have this message error Gnokii serial_open: open: Périphérique ou ressource occupé
    Impossible d'ouvrir le péripherique ATBUS: Périphérique ou ressource occupé
    AT bus initialization failed (1)
    Initialization failed (1)
    Serial device: closing device
    Can you help me please
    thank you

  3. i think you can unplug and plug the phone, and check for /dev/ttyACM0, or check with dmesg to see, which device file that the phone register to.