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/
它可以工作,我可以从终端发送短信。
纳吉奥斯
#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 调试
[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.
从 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:~$
答案1
它可以工作,我可以从终端发送短信。
你已经测试过了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
然后再试一次。
更新时间:星期一 8月 13日 17:57:59 ICT 2012
在命令上设置 SUID 位以允许nagios
代表执行 gammu root
:
# chmod 4755 /usr/bin/gammu
然后再试一次:
# su - nagios -s /bin/bash
$ echo "test" | gammu –sendsms TEXT 0123456789