您好,登錄后才能下訂單哦!
搭建nagios的目的就是為了他的報警系統,nagios據我所了解可以有三種報警:
一、聲音報警
二、電子郵件報警
三、手機短訊報警
下面是我的郵件報警的配置過程:
1、開啟系統自帶的sendmail郵件系統
service sendmail start
如果沒有安裝,可以yum一下
yum install -y sendmail*
service sendmail restart
測試發送郵件:
echo "test" | mail lihuipeng007@163.com
我系統在關掉iptables和selinux前提下是正常的
2、配置nagios中報警郵箱
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那里加上自己的郵箱,如果有多個可以用逗號隔開
3、設置報警方式:
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!
}
這兩個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$
}
這里已經默認配置好,我們不用修改直接調用就是了
最后重啟服務:
service nagios retart
然后隨便關掉一些服務測試一下效果!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。