gammu-smsd конфигурация:
#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/
Он работает, и я могу отправлять SMS с терминала.
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
}
Команда:
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$
}
Редактировать:
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
Дополнительная информация
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.
Отправка SMS от пользователя nagios
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:~$
Он работает, и я могу отправлять SMS с терминала.
Вы тестировали как root
?
output=Error opening device, it doesn't exist.
Удостоверься что nagios
(и apache
если хотите) имеет разрешение на запись на /dev/rfcomm0
.
Сначала проверьте это:
# ls -l /dev/rfcomm0
Предполагая, что вы получите:
crw-rw---- 1 root dialout 216, 0 2012-08-10 23:15 /dev/rfcomm0
затем добавьте nagios
пользователь к dialout
группа:
$ sudo usermod -a -G dialout nagios
и попробуй еще раз.
ОБНОВЛЕНИЕ 13 августа, понедельник, 17:57:59, ICT 2012
Установите бит SUID в команде, чтобы разрешить nagios
выполнить гамму от имени root
:
# chmod 4755 /usr/bin/gammu
и попробуй еще раз:
# su - nagios -s /bin/bash
$ echo "test" | gammu –sendsms TEXT 0123456789