0

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:~$
masegaloeh
  • 17,978
  • 9
  • 56
  • 104
Jerry
  • 179
  • 2
  • 8
  • 19

1 Answers1

3

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
quanta
  • 50,327
  • 19
  • 152
  • 213
  • `# ls -l /dev/rfcomm0` `ls: cannot access /dev/rfcomm0: No such file or directory` – Jerry Aug 13 '12 at 04:40
  • I take it from your above config `port = /dev/rfcomm0`. – quanta Aug 13 '12 at 04: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 05:49
  • After plugging your phone, type `dmesg` to see which port it is using. – quanta Aug 13 '12 at 05:53
  • I have copied output of `dmesg` to this [file](http://www.mediafire.com/?owukq71hzg4j1rf). I could not find out actual port from the output. – Jerry Aug 13 '12 at 06:48
  • Use a pastebin client tool (fpaste, wgetpaste, ...) to paste some ending lines. Dont't upload to mediafire. Switch to `nagios` user (`su - nagios -s /bin/bash`) and send a testing sms with gammu to see what does it say. – quanta Aug 13 '12 at 07:08
  • when I Switch to nagios user, Should I be root to send SMS?? – Jerry Aug 13 '12 at 11:29
  • I connected my mobile phone through USB cable and now nagios sends SMS alert. Problem is that it is not real-time. If any service is down, It takes around two minutes to send SMS alert. What should I do?? – Jerry Aug 29 '12 at 05:01
  • It depends on normal_check_interval, max_check_attempts, ... – quanta Aug 29 '12 at 05:04
  • I have changed `interval_length=1` (in nagios.cfg file), `normal_check_interval=1` and `max_check_attempts=1` in host definition. Still it takes around one minute. – Jerry Aug 29 '12 at 06:14
  • http://nagios.sourceforge.net/docs/3_0/configmain.html#interval_length – quanta Aug 29 '12 at 06:22
  • I have read above link and they have not tested other values for `interval_length` variable. I set it to `1s` that reduced alert time to around one minute. I could not find any way to send sms alert in a second. Is it possible to send SMS alert in one/two second(s)??? – Jerry Aug 29 '12 at 07:12
  • It is possible. But are you sure you want to do this? Post another topic and insert link here. – quanta Aug 29 '12 at 07:33
  • http://serverfault.com/questions/422377/how-to-configure-nagios-realtime-sms-alert – Jerry Aug 29 '12 at 07:47