Nagios SMS notification with gammu smsd does not work
7,105
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
Related videos on Youtube
Author by
Jerry
Updated on September 18, 2022Comments
-
Jerry almost 2 years
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:~$
-
Greg Petersen almost 12 yearsOnce 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.
-
Greg Petersen almost 12 yearsHow about
nagios.log
? -
Jerry almost 12 yearsI haven't looked at nagios.log. Thank you....Now I am trying to fix it....
-
Jerry almost 12 yearsi have added the output of
grep notify-service-by-sms /path/to/nagios.log
above. -
Greg Petersen almost 12 yearsset
debug_level
to 256, try again and post thenagios.debug
here.
-
-
Greg Petersen almost 12 yearsI take it from your above config
port = /dev/rfcomm0
. -
Jerry almost 12 yearsI have connected my phone using blue-tooth and assigned
port = /dev/rfcomm0
. It works and I can send SMS from terminal. I executedroot@khalid:/dev# ls -l
butrfcomm0
was not found. How SMS is being sent using/dev/rfcomm0
port(actually it does not exist indev
directory)? -
Greg Petersen almost 12 yearsAfter plugging your phone, type
dmesg
to see which port it is using. -
Jerry almost 12 yearsI have copied output of
dmesg
to this file. I could not find out actual port from the output. -
Greg Petersen almost 12 yearsUse 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. -
Jerry almost 12 yearswhen I Switch to nagios user, Should I be root to send SMS??
-
Jerry almost 12 yearsI 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??
-
Greg Petersen almost 12 yearsIt depends on normal_check_interval, max_check_attempts, ...
-
Jerry almost 12 yearsI have changed
interval_length=1
(in nagios.cfg file),normal_check_interval=1
andmax_check_attempts=1
in host definition. Still it takes around one minute. -
Jerry almost 12 yearsI have read above link and they have not tested other values for
interval_length
variable. I set it to1s
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)??? -
Greg Petersen almost 12 yearsIt is possible. But are you sure you want to do this? Post another topic and insert link here.
-
Jerry almost 12 years