您好,登錄后才能下訂單哦!
Nagios 除了監(jiān)控功能很強(qiáng)大之外,它的報(bào)警功能也很不錯(cuò)。從運(yùn)維的角度來(lái)講,報(bào)警一般就是郵件和短信報(bào)警這兩種方式,這次實(shí)驗(yàn)實(shí)現(xiàn)的是Nagios 的郵件報(bào)警功能。
1、 安裝sendmail 組件
這里要確保sendmail 相關(guān)組件的完整安裝,
[root@server ~]# yum install sendmail* mailx
安裝完成后重啟sendmail 服務(wù)
[root@server ~]# service sendmail restart
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
測(cè)試sendmail 發(fā)信情況
[root@server ~]# /bin/mail -s "`date +%Y-%m-%d` Server SMS Test" 159158*****@163.com
hello
admin
.
EOT
2、 郵件報(bào)警的配置
一般而言,如果在整個(gè)系統(tǒng)中只有一個(gè)管理員,那么只需要在contact.cfg文件中,添加一下管理員的郵箱即可。但如果監(jiān)控的內(nèi)容中服務(wù)器有單獨(dú)的管理員,那就需要定義多個(gè)contact(聯(lián)系人),然后再通過(guò)contactgroup(聯(lián)系組)對(duì)各個(gè)contact 進(jìn)行分組。
(1) 修改contact.cfg
[root@server ~]# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagios
use generic-contact
alias Nagios
email 159158*****@163.com,159158*****@139.com // 改為自己的郵箱地址即可
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios
}
(2) 設(shè)置報(bào)警方式
[root@server ~]# vim /usr/local/nagios/etc/objects/templates.cfg
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
(3) 修改commands.cfg
[root@server ~]# vim /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
看到這里已經(jīng)默認(rèn)配置好,我們不用修改直接調(diào)用就行了。
(4) 通過(guò)-v參數(shù)檢查配置無(wú)誤之后,重啟nagios
[root@server ~]# service nagios restart
Running configuration check...done.
Stopping nagios: .done.
Starting nagios: done.
(5) 郵箱設(shè)置
這里以139郵箱為例,設(shè)置收信
點(diǎn)擊左上角“設(shè)置”可以看到這個(gè)版塊
點(diǎn)擊“手機(jī)通知”,打開(kāi)郵箱到達(dá)通知,設(shè)置接收時(shí)間段,設(shè)置完保存。
返回到這個(gè)版塊,點(diǎn)擊“白名單設(shè)置”,將服務(wù)器域名設(shè)置進(jìn)白名單
(6) 測(cè)試收信情況
可以隨便關(guān)閉客戶機(jī)上的一個(gè)服務(wù)做測(cè)試
設(shè)置郵件到達(dá)提醒后,還可以收到告警短信,效果如下:(需要設(shè)置成長(zhǎng)短信的形式)
可以QQ郵箱將域名設(shè)置進(jìn)白名單,然后微信設(shè)置QQ郵箱推送即可(由于設(shè)置簡(jiǎn)單,這里就不演示了)效果如下:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。