|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
由于移动增加了飞信api接口,在Linux命令行下使用飞信客户端需要图片验证码,以前一直使用良好的报警系统一下失灵了。随时掌握服务器状态多重要呀,这是我们运维必须要做的。
申请139邮箱,成功申请后配置邮件到达短信通知,使用长格式。139邮件短信通知这个功能好用,而且免费:)缺点:短信报警有延时,不如linux命令行飞信报警快
139邮箱申请:http://mail.10086.cn/ http://caspian.dotconf.net/menu/Software/SendEmail/
1.下载
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
2.编译安装
tar xvzf sendEmail-v1.56.tar.gz
cd sendEmail-v1.56/
cp sendEmail /usr/local/bin
chmod +x /usr/local/bin/sendEmail 3.测试邮件发送:
/usr/local/bin/sendEmail -f hugwww@163.com -t hugwww@139.com -s smtp.163.com -u “send by hugwww” -xu hugwww -xp gaojinbo.com -m “邮件发送成功,good” 4.编写nagios报警脚本1.编写发送脚本vi sendsms.sh
#!/bin/bash
fetionDir=/usr/local/139/
cd $fetionDir
DIR=`pwd`user=13800138000@139.com
pwd=13800138000for phone in `cat $DIR/phonelist.txt`
do
echo “$phone” | sed ‘/^[ t]*$/d’ | sed ‘s/^[ t]*//’ | sed ‘s/[ t]*$//’ | grep ‘^1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]‘
if (($? == 0 ));then
if [[ -f $DIR/msg.txt ]];then
echo “================” >> msg.txt
fi
phone=`echo “$phone” | sed ‘s/^[ t]*//’ | sed ‘s/[ t]*$//’`
echo “sms $phone $1″ >> $DIR/msg.txt
echo “quit” >> $DIR/msg.txt
$fetionDir/fetion –mobile=$user –pwd=$pwd –to=$phone –msg-utf8=”$1″
else
continue
fidone
2.接收者邮件地址vi /usr/local/139/phonelist.txt
#hugwww
13724506486@139.com 3.修改139目录权限(否则运行Nagios的用户不能写入信息内容到/usr/local/139/msg.txt)
chown -R nagios.nagios /usr/local/139
chmod +x /usr/local/139/sendsms.sh 4.配置Nagios
vi commands.cfg
###################################################################
#
# notify-host-by-sendmsg/notify-service-by-sendmsg //定义发送139邮件短信报警的命令
#
###################################################################
define command {
command_name notify-host-by-fetion
command_line /usr/local/139/sendsms.sh “Host $HOSTSTATE$ alert for $HOSTNAME$($HOSTADDRESS$) on $TIME$.”
}define command {
command_name notify-service-by-fetion
command_line /usr/local/139/sendsms.sh “”$TIME$”:$SERVICEDESC$($HOSTADDRESS$) is $SERVICESTATE$.”
} 5.定义联系人
vi contacts.cfg
define contact {
contact_name admin
alias system admin
host_notification_period 24×7
service_notification_period 24×7
host_notification_options d,r
service_notification_options w,u,c,r
service_notification_commands notify-service-by-email,notify-service-by-fetion
host_notification_commands notify-host-by-email,notify-host-by-fetion
email 13800138000@139.com
pager 13800138000@139.com
} 测试故障时是否能够触发短信报警
/usr/local/139/sendsms.sh “nagios Host alert” 完成!
|
|