nagios監(jiān)控使用139郵箱報(bào)警
139郵箱申請(qǐng):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.測(cè)試郵件發(fā)送:
/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 “郵件發(fā)送成功,good”
4.配置Nagios
cd /usr/local/nagios/etc/objects
vi commands.cfg
建議,nagios報(bào)警盡量不要使用本機(jī)sendmail,在大網(wǎng)站注冊(cè)個(gè)免費(fèi)郵箱發(fā)去吧,也減少了很多麻煩,比如sendmail問(wèn)題導(dǎo)致的報(bào)警不能及時(shí)到達(dá)
以下為command中定義的發(fā)郵件命令,根據(jù)自己的實(shí)際情況修改
command.cfg中加入
define command{
command_name notify-host-by-sendEmail
command_line /usr/bin/printf "%b" "***** Nagios-BJ *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f ceshi@163.com -t $CONTACTEMAIL$ -s smtp.163.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu ceshi -xp xxxxxxxx -l /var/log/sendEmail.log
}
define command{
command_name notify-service-by-sendEmail
command_line /usr/bin/printf "%b" "***** Nagios-BJ *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/local/bin/sendEmail -f ceshi@163.com -t $CONTACTEMAIL$ -s smtp.163.com -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu ceshi -xp xxxxxxxx -l /var/log/sendEmail.log
}
解釋:
-f 表示發(fā)送者的郵箱
-t 表示接收者的郵箱
-u 表示郵件的主題
-xu 表示SMTP驗(yàn)證的用戶(hù)名
-xp 表示SMTP驗(yàn)證的密碼(注意,這個(gè)密碼貌似有限制,例如我用d!5neyland就不能被正確識(shí)別)
-m 表示郵件的內(nèi)容
如果你不帶-m參數(shù)的話,就會(huì)提示你自行輸入
5.定義聯(lián)系人
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-sendEmail
host_notification_commands notify-host-by-sendEmail
email 13800138000@139.com
pager 13800138000@139.com
}
測(cè)試故障時(shí)是否能夠觸發(fā)短信報(bào)警
/usr/local/139/sendsms.sh “nagios Host alert”