真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

nagios事件處理機(jī)制

接到zz的任務(wù),實(shí)現(xiàn)自動(dòng)化處理nagios某項(xiàng)報(bào)警

腦海里有個(gè)印象,這個(gè)功能之前線下做過(guò)實(shí)驗(yàn)

一、首先必須查看下nagios的官方文檔,確認(rèn)可行,以下是筆者整理的一些自認(rèn)為有用的信息

1)
了解命令的定義方法
Writing Event Handler Commands
Event handler commands will likely be shell or perl scripts, but they can be any type of executable that can run from a
command prompt. At a minimum, the scripts should take the following macros as arguments:
For Services: $SERVICESTATE$, $SERVICESTATETYPE$, $SERVICEATTEMPT$
For Hosts: $HOSTSTATE$, $HOSTSTATETYPE$, $HOSTATTEMPT$
這段說(shuō)的是,針對(duì)于主機(jī)處理需要的一些參數(shù),跟針對(duì)于服務(wù)需要的一些參數(shù),這方面配置是在objects/commands.cfg配置的
官方文檔記錄
define command{
command_name restart-httpd
command_line /usr/local/nagios/libexec/eventhandlers/restart-httpd $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}

2)
了解主機(jī)配置文件的方法(筆者線上host和service合并的一個(gè)文件,一般是分開(kāi)的,主host跟service是分開(kāi)的)
官方文檔記錄:
define service{
host_name somehost
service_description HTTP
max_check_attempts 4
event_handler restart-httpd
...
}


二、一些解釋?zhuān)?br />
1)
變量解釋?zhuān)?br />$SERVICESTATE$:服務(wù)的當(dāng)前狀態(tài)(OK、WARNING、UNKNOWN、CRITICAL)
$SERVICESTATETYPE$:服務(wù)器狀態(tài)類(lèi)型,分為兩種,軟狀態(tài),硬狀態(tài)
$SERVICEATTEMPT$:軟狀態(tài)的嘗試check的次數(shù)
這些值是后面自動(dòng)恢復(fù)腳本必須要處理的三個(gè)參數(shù)

2)
HARD:硬狀態(tài)
SOFT:軟狀態(tài)
nagios在檢測(cè)服務(wù)正常的過(guò)程中,如果第一次檢測(cè)失敗,狀態(tài)成SOFT 嘗試設(shè)置的最大次數(shù)后,狀態(tài)就改變成為HARD

3)
事件處理的一些參數(shù)配置
event_handler_timeout=30  超時(shí)時(shí)間
enable_event_handlers=1   開(kāi)機(jī)事件處理機(jī)制
event_handler


三、操作步驟:
1)
確認(rèn)事件處理開(kāi)關(guān)有沒(méi)有打開(kāi)
enable_event_handlers=1
0:關(guān)閉
1:打開(kāi)

2)
自恢復(fù)腳本制作
需要處理的參數(shù)太多,建議使用case,下面是官網(wǎng)的腳本例子,當(dāng)然可以寫(xiě)成其他的
#!/bin/sh
#
# Event handler script for restarting the web server on the local machine
#
# Note: This script will only restart the web server if the service is
# retried 3 times (in a "soft" state) or if the web service somehow
# manages to fall into a "hard" error state.
#
# What state is the HTTP service in?
case "$1" in
OK)
# The service just came back up, so don't do anything...
;;
WARNING)
# We don't really care about warning states, since the service is probably still running...
;;
UNKNOWN)
# We don't know what might be causing an unknown error, so don't do anything...
;;
CRITICAL)
# Aha! The HTTP service appears to have a problem - perhaps we should restart the server...
# Is this a "soft" or a "hard" state?
case "$2" in
# We're in a "soft" state, meaning that Nagios is in the middle of retrying the
# check before it turns into a "hard" state and contacts get notified...
SOFT)
# What check attempt are we on? We don't want to restart the web server on the first
# check, because it may just be a fluke!
case "$3" in
# Wait until the check has been tried 3 times before restarting the web server.
# If the check fails on the 4th time (after we restart the web server), the state
# type will turn to "hard" and contacts will be notified of the problem.
# Hopefully this will restart the web server successfully, so the 4th check will
# result in a "soft" recovery. If that happens no one gets notified because we
# fixed the problem!
3)
echo -n "Restarting HTTP service (3rd soft critical state)..."
# Call the init script to restart the HTTPD server
/etc/rc.d/init.d/httpd restart
;;
esac
;;
#

3)報(bào)警產(chǎn)生之后,如何當(dāng)nagios服務(wù)器得到下面?zhèn)魃蟻?lái)的報(bào)警呢,做出自維護(hù)呢(objects/commands.cfg)
在objects/commands.cfg該文件中表明當(dāng)報(bào)警產(chǎn)生,如何去執(zhí)行遠(yuǎn)端的腳本,


4)
在主機(jī)服務(wù)的配置文件中,啟用時(shí)間處理機(jī)制
event_handler  shell_name


/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
檢測(cè)上面修改的文件,有沒(méi)有報(bào)錯(cuò)

殺掉個(gè)服務(wù),做下簡(jiǎn)單的測(cè)試,ok

不辜負(fù)zz的信任,解決了

搞定收工

創(chuàng)新互聯(lián)專(zhuān)注于企業(yè)營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、網(wǎng)站重做改版、永州網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5網(wǎng)站設(shè)計(jì)、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性?xún)r(jià)比高,為永州等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。


分享文章:nagios事件處理機(jī)制
文章地址:http://weahome.cn/article/pogcie.html

其他資訊

在線咨詢(xún)

微信咨詢(xún)

電話咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部