1.下載安裝sendEmail工具
成都創(chuàng)新互聯(lián)公司從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務公司,擁有項目網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元武清做網(wǎng)站,已為上家服務,為武清各地企業(yè)和個人服務,聯(lián)系電話:18982081108[root@db02 ~]# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
[root@db02 ~]# tar xvf sendEmail-v1.56.tar.gz
[root@db02 ~]# mv sendEmail-v1.56/sendEmail /usr/local/bin/sendEmail2
[root@db02 ~]# chmod 755 /usr/local/bin/sendEmail2
[root@db02 ~]# /usr/local/bin/sendEmail2 -f z597011036@126.com -t dick@tingyun.tech -s smtp.126.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu z597011036@126.com -xp z597011036zzz -m test
Jun 01 16:59:03 db02 sendEmail2[27006]: Email was sent successfully! #測試郵件發(fā)送成功
[root@db02 ~]#
2.在nagios中定義聯(lián)系人和聯(lián)系組
[root@db02 ~]# cd /usr/local/nagios-4.1.1/etc/objects/
[root@db02 objects]# vim contacts.cfg
define contact{
contact_name dick #聯(lián)系人姓名
use generic-contact #使用聯(lián)系人模板
alias dick #別名
email dick@tingyun.tech #聯(lián)系人郵箱
}
define contact{
contact_name rayc
use generic-contact
alias rayc
email rayc@tingyun.tech
}
define contact{
contact_name tong
use generic-contact
alias tong
email z597011036@qq.com
}
define contactgroup{
contactgroup_name tingyun #定義聯(lián)系人組
alias tingyun
members dick,rayc #組中的成員
}
3.報警時間,級別設(shè)置
[root@db02 objects]# vim templates.cfg #報警參數(shù)設(shè)置
define contact{
name generic-contact #定義報警聯(lián)系人模板
service_notification_period 24x7 #服務報警的時間(24小時,7天)
host_notification_period 24x7 #主機報警的時間
service_notification_options w,u,c,r,f,s #服務報警級別
host_notification_options d,u,r,f,s #主機報警級別
service_notification_commands notify-service-by-email #服務報警的命令(在command.cfg文件中)
host_notification_commands notify-host-by-email
register 0 #是否可以繼承
}
define host{
name generic-host
notifications_enabled 1 #是否啟用主機報警
event_handler_enabled 1 #啟用主機事件程序
flap_detection_enabled 1
process_perf_data 1 #性能數(shù)據(jù)
retain_status_information 1 #程序啟動保留狀態(tài)信息
retain_nonstatus_information 1 #程序啟動保留非狀態(tài)信息
notification_period 24x7 #報警時間
register 0 #是否繼承
}
define host{
name linux-server #自定義模板
use generic-host #繼承哪個模板
check_period 24x7 #被選中的時鐘
check_interval 5 #主機每5分鐘檢查一次
retry_interval 1 #每隔1分鐘重試檢查一次
max_check_attempts 10 #檢查每個主機10次
check_command check-host-alive #默認命令檢查主機
notification_period workhours #只通知白天
notification_interval 120 #每兩個小時發(fā)送通知
notification_options d,u,r #只發(fā)送特定主機的通知
contact_groups tingyun #發(fā)送哪個組
register 0 #是否被繼承
}
define service{
name generic-service #定義模板
active_checks_enabled 1 #啟動服務檢查
passive_checks_enabled 1 #啟動被動檢查
parallelize_check 1 #主動服務檢查(禁用會出現(xiàn)嚴重問題)
obsess_over_service 1
check_freshness 0 #不檢查服務新鮮度
notifications_enabled 1 #啟動服務通知
event_handler_enabled 1 #啟用服務事件
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0 #服務不穩(wěn)定
check_period 24x7 #檢查服務時間
max_check_attempts 3 #重新檢查服務3次
normal_check_interval 10 #每10分鐘檢查一個服務
retry_check_interval 2 #每2分鐘再檢查一次
contact_groups tingyun #郵件通知聯(lián)系組
notification_options w,u,c,r #發(fā)送報警級別
notification_interval 1 #每1小時重新通知服務
notification_period 24x7 #通知時間
register 0 #是否繼承
}
define service{
name local-service #定義模板
use generic-service #繼承模板
max_check_attempts 4 #最多檢查服務4次
normal_check_interval 5 #正常情況下每5分鐘檢查一下服務
retry_check_interval 1 #重新檢查該服務需要1分鐘
register 0 #這只是個模板
notifications_enabled 1 #啟用報警
contact_groups tingyun #發(fā)送聯(lián)系組
}
4.報警腳本編寫
[root@db02 objects]# vim commands.cfg
define command {
command_name notify-service1-by-email
command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" | /usr/local/bin/sendEmail2 -f t 發(fā)件人郵箱 -t $CONTACTEMAIL$ -s smtp.139.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu 發(fā)件人郵箱用戶名 -xp 發(fā)件郵箱密碼
}
define command {
command_name notify-host1-by-email
command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" | /usr/local/bin/sendEmail2 -f 發(fā)件人郵箱 -t $CONTACTEMAIL$ -s smtp.139.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu 發(fā)件人郵箱用戶名 -xp 發(fā)件郵箱密碼
}
[root@db02 objects]# /etc/init.d/nagios restart
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.
[root@db02 objects]#
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
當前名稱:nagios使用sendEmail郵件報警-創(chuàng)新互聯(lián)
文章位置:http://vcdvsql.cn/article6/cdejig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站改版、外貿(mào)建站、網(wǎng)站策劃、網(wǎng)站設(shè)計公司、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容