nagios添加139邮件短信通知报警

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 [email protected] -t [email protected] -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`

[email protected]
pwd=13800138000

for 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
fi

done

 

 

2.接收者邮件地址

vi /usr/local/139/phonelist.txt
#hugwww
[email protected]

 

 

 

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                         [email protected]
pager                           [email protected]
}

 

测试故障时是否能够触发短信报警
/usr/local/139/sendsms.sh “nagios Host alert”

 

完成!

你可能感兴趣的:(职场,nagios,通知,短信,休闲)