Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

gammu-smsd configuration:

#vi /etc/gammu-smsdrc

 # Configuration file for Gammu SMS Daemon

 # Gammu library configuration, see gammurc(5)
[gammu]
 # Please configure this!
port = /dev/rfcomm0
connection = bluephonet
 # Debugging
logformat = textall

 # SMSD configuration, see gammu-smsdrc(5)
[smsd]
service = files
 #logfile = syslog
logfile = /var/log/gammu-smsd

 # Increase for debugging information
debuglevel = 0

 # Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/

It works and I can send SMS from terminal.

Nagios

#vi /etc/nagios3/conf.d/localhost_nagios2.cfg
define host{
          use                     generic-host            ; Name of host template to use
          host_name               localhost
          alias                   localhost
          address                 x.x.x.187
          check_command           check-host-alive
          max_check_attempts      10
          notification_interval   120
         notification_period     24x7
          notification_options    d,r
          contact_groups  admins
  }

#vi /etc/nagios3/conf.d/timeperiods_nagios2.cfg
 define timeperiod{
         timeperiod_name 24x7
         alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
         monday          00:00-24:00
         tuesday         00:00-24:00
         wednesday       00:00-24:00
         thursday        00:00-24:00
         friday          00:00-24:00
         saturday        00:00-24:00
 }


#vi /etc/nagios3/conf.d/contacts_nagios2.cfg
 define contact{
         contact_name                    localhost
         alias                           localhost 
         service_notification_period     24x7
         host_notification_period        24x7
         service_notification_options    w,u,c,r
         host_notification_options       d,r
         service_notification_commands   notify-service-by-sms
         host_notification_commands      notify-host-by-sms
         pager                           +88xxxxxxxxxxx
 }
 define contactgroup{
         contactgroup_name       admins
         alias                   Nagios Administrators
         members                 localhost
 }

 #vi /etc/nagios3/conf.d/services_nagios2.cfg
 define service{
         use                             generic-service         
         host_name                       localhost
         service_description             SSH
         is_volatile                     0
         check_period                    24x7
         max_check_attempts              4
         normal_check_interval           5
         retry_check_interval            1
         contact_groups                  admins
         notification_interval           960
         notification_period             24x7
         check_command                   check_ssh
  }

Command:

define command{
        command_name    notify-host-by-sms
        command_line    /usr/bin/printf "%b" "Alert $HOSTNAME$ is $HOSTSTATE$" | /usr/bin/gammu --sendsms TEXT $CONTACTPAGER$

        }

define command{
        command_name    notify-service-by-sms
        command_line    /usr/bin/printf "%b" "Alert service $SERVICEDESC$ on $HOSTNAME$" is $SERVICESTATE$ | /usr/bin/gammu --sendsms TEXT $CONTACTPAGER$

        }

Edit:

log

Sun 2012/08/12 23:14:03 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:14:41 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:15:17 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:15:55 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:16:32 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:17:09 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:17:46 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:18:25 gammu-smsd[5712]: Read 0 messages
Sun 2012/08/12 23:19:04 gammu-smsd[5712]: Read 0 messages

Additional info

Nagios.log

[1344792542] SERVICE ALERT: localhost;SSH;CRITICAL;SOFT;1;Connection refused
[1344792602] SERVICE ALERT: localhost;SSH;CRITICAL;SOFT;2;Connection refused




#grep notify-service-by-sms /var/log/nagios3/nagios.log


[1344760748] SERVICE NOTIFICATION: localhost;localhost;SSH;CRITICAL;notify-service-by-sms;Connection refused
[1344762800] SERVICE NOTIFICATION: localhost;localhost;SSH;OK;notify-service-by-sms;SSH OK - OpenSSH_5.9p1 Debian-5ubuntu1 (protocol 2.0)
[1344780228] SERVICE NOTIFICATION: localhost;localhost;SSH;CRITICAL;notify-service-by-sms;Connection refused
[1344784378] SERVICE NOTIFICATION: localhost;localhost;SSH;OK;notify-service-by-sms;SSH OK - OpenSSH_5.9p1 Debian-5ubuntu1 (protocol 2.0)
[1344785462] SERVICE NOTIFICATION: localhost;localhost;SSH;CRITICAL;notify-service-by-sms;Connection refused
[1344785762] SERVICE NOTIFICATION: localhost;localhost;SSH;OK;notify-service-by-sms;SSH OK - OpenSSH_5.9p1 Debian-5ubuntu1 (protocol 2.0)
[1344786242] SERVICE NOTIFICATION: localhost;localhost;SSH;CRITICAL;notify-service-by-sms;Connection refused
[1344786842] SERVICE NOTIFICATION: localhost;localhost;SSH;OK;notify-service-by-sms;SSH OK - OpenSSH_5.9p1 Debian-5ubuntu1 (protocol 2.0)
[1344788117] SERVICE NOTIFICATION: localhost;localhost;SSH;CUSTOM (OK);notify-service-by-sms;SSH OK - OpenSSH_5.9p1 Debian-5ubuntu1 (protocol 2.0);nagiosadmin;test
[1344792289] SERVICE NOTIFICATION: localhost;localhost;SSH;CUSTOM (OK);notify-service-by-sms;SSH OK - OpenSSH_5.9p1 Debian-5ubuntu1 (protocol 2.0);nagiosadmin;sdd
[1344792722] SERVICE NOTIFICATION: localhost;localhost;SSH;CRITICAL;notify-service-by-sms;Connection refused

Nagios.debug

[1344830776.241243] [256.1] [pid=2978] Running command '/usr/bin/printf "%b" "Alert service SSH on localhost" is CRITICAL | /usr/bin/gammu --sendsms TEXT +880xxxxxxxxxx'...
[1344830776.258139] [256.1] [pid=2978] Execution time=0.016 sec, early timeout=0, result=3, output=Error opening device, it doesn't exist.

Sending SMS from nagios user

root@khalid-Dell-System-Inspiron-N4110:/home/khalid# sudo su - nagios -s /bin/bash
nagios@khalid-Dell-System-Inspiron-N4110:~$ echo "Test SMS" | gammu-smsd-inject TEXT  +88xxxxxxxxxxx

gammu-smsd-inject[3438]: Warning: No PIN code in /etc/gammu-smsdrc file
Failed to inject message: Can not open specified file.
nagios@khalid-Dell-System-Inspiron-N4110:~$
share|improve this question
    
Once you get the problem, you should take a look at the logs to see what happens. If it doesn't help, increase the debug level. –  quanta Aug 12 '12 at 17:15
    
How about nagios.log? –  quanta Aug 12 '12 at 17:22
    
I looked at but could not get any help by google –  Jerry Aug 12 '12 at 17:22
    
I haven't looked at nagios.log. Thank you....Now I am trying to fix it.... –  Jerry Aug 12 '12 at 17:38
    
i have added the output of grep notify-service-by-sms /path/to/nagios.log above. –  Jerry Aug 12 '12 at 17:51
show 1 more comment

1 Answer

up vote 2 down vote accepted

It works and I can send SMS from terminal.

Have you tested as root?

output=Error opening device, it doesn't exist.

Make sure that nagios (and apache if you want) has write permission on /dev/rfcomm0.

Check this first:

# ls -l /dev/rfcomm0

Assumming you get:

crw-rw---- 1 root dialout 216, 0 2012-08-10 23:15 /dev/rfcomm0

then add the nagios user to the dialout group:

$ sudo usermod -a -G dialout nagios

and try again.


UPDATE Mon Aug 13 17:57:59 ICT 2012

Set the SUID bit on the command to allow nagios execute gammu on behalf of the root:

# chmod 4755 /usr/bin/gammu

and try again:

# su - nagios -s /bin/bash
$ echo "test" | gammu –sendsms TEXT 0123456789
share|improve this answer
    
# ls -l /dev/rfcomm0 ls: cannot access /dev/rfcomm0: No such file or directory –  Jerry Aug 13 '12 at 4:40
    
I take it from your above config port = /dev/rfcomm0. –  quanta Aug 13 '12 at 4:41
    
I have connected my phone using blue-tooth and assigned port = /dev/rfcomm0. It works and I can send SMS from terminal. I executed root@khalid:/dev# ls -l but rfcomm0 was not found. How SMS is being sent using /dev/rfcomm0 port(actually it does not exist in dev directory)? –  Jerry Aug 13 '12 at 5:49
    
After plugging your phone, type dmesg to see which port it is using. –  quanta Aug 13 '12 at 5:53
    
I have copied output of dmesg to this file. I could not find out actual port from the output. –  Jerry Aug 13 '12 at 6:48
show 9 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.