前一段時間在Cu論壇發現一個提問,問題是nagios關於檢測主機http服務的.原帖地址http://bbs.chinaunix.net /forum.php?mod=viewthread&tid=4079340&page=1#pid23860101.樓主剛開始想實 現的是檢測主機的url是否正常,后來有回復用自定義腳本的.經過搜索,發現nagios自帶的check_http命令可以使用-u url的方式來檢測url的.經過試驗,確實是可行的,發帖紀錄下.
1.先運行check_http命令看下是否支持-u參數,注意返回的顯示里面有沒有
點擊(此處)折疊或打開
- /usr/local/nagios/libexec/check_http
- check_http: Could not parse arguments
- Usage:
- check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]
- [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]
- [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]
- [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]
- [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]
- [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]
- [-T <content-type>] [-j method]
2.自定義一個command,名字隨便起,我這里是check_http_u,當然了,我寫的簡單,你也可以加-w和-c等參數
點擊(此處)折疊或打開
- define command{
- command_name check_http_u
- command_line $USER1$/check_http -I $HOSTADDRESS$ -u $ARG1$
- }
3.給已經定義過的主機添加一個自定義服務,我這里寫成URL1,你可以根據需要修改成其他的.
點擊(此處)折疊或打開
- define service{
- use local-service ; Name of service template to use
- host_name xxx ;前面定義好的主機名
- service_description URL1 ;
- check_command check_http_u!'/path/index.html' ;
- notifications_enabled 1;
- }
4. 重啟nagios服務,重啟沒有錯誤的話,瀏覽器訪問你的nagios服務,過一段時間,就可以看到檢測的結果了.
轉自:blog.chinaunix.net/uid-1730385-id-3683735.html