搭建nagios的目的就是為了他的報(bào)警系統(tǒng),nagios據(jù)我所了解可以有三種報(bào)警:
一、聲音報(bào)警
二、電子郵件報(bào)警
三、手機(jī)短訊報(bào)警
下面是我的郵件報(bào)警的配置過程:
1、開啟系統(tǒng)自帶的sendmail郵件系統(tǒng)
service sendmail start
如果沒有安裝,可以yum一下
yum install -y sendmail*
service sendmail restart
測(cè)試發(fā)送郵件:
echo "test" | mail lihuipeng007@163.com
我系統(tǒng)在關(guān)掉iptables和selinux前提下是正常的
2、配置nagios中報(bào)警郵箱
vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined
above)
alias Nagios Admin ; Full name of user
email lihuipeng007@163.com
; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
在email那里加上自己的郵箱,如果有多個(gè)可以用逗號(hào)隔開
3、設(shè)置報(bào)警方式:
vi /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!
}
這兩個(gè)notify-service-by-email 和 notify-host-by-email 是在command.cfg那里定義的,看看是怎么定義的:
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios ***** Notification
Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$
Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$ " |
/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 ***** Notification
Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host:
$HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time:
$LONGDATETIME$ Additional Info: $SERVICEOUTPUT$ " | /bin/mail -s "**
$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is
$SERVICESTATE$ **" $CONTACTEMAIL$
}
這里已經(jīng)默認(rèn)配置好,我們不用修改直接調(diào)用就是了
最后重啟服務(wù):
service nagios retart
然后隨便關(guān)掉一些服務(wù)測(cè)試一下效果!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。