原来的
[root@nhserver2_5 objects]# cd /usr/local/nagios/etc/objects
[root@nhserver2_5 objects]# vim commands.cfg
# 'check_http' command definition
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
要修改为
define command{
command_name check_http
command_line $USER1$/check_http -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$
}
[root@nhserver2_5 objects]# cd usr/local/nagios/etc/objects
[root@nhserver2_5 objects]# vim hosts_172.16.1.191.cfg
define host{
use windows-server
host_name 172.16.1.191
alias 172.16.1.191
address 172.16.1.191
}
define hostgroup{
hostgroup_name windows-servers
alias Windows Servers
}
define service{
use local-service
host_name 172.16.1.191
service_description check-host-alive
check_command check-host-alive
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
define service{
use local-service
host_name 172.16.1.191
service_description 172.16.1.191:9000/gx/login.jsp
check_command check_http!9000!"/gx/login.jsp"
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
[root@nhserver2_5 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@nhserver2_5 objects]# service nagios reload
测试
[root@nhserver2_5 libexec]# ./check_http -I 172.16.1.191 -p 9000 -u "/gx/login.jsp"
HTTP OK: HTTP/1.1 200 OK - 1438 bytes in 0.003 second response time |time=0.003178s;;;0.000000 size=1438B;;;0
[root@nhserver2_5 libexec]# ./check_http -I 172.16.1.191 -p 9000 -u "/gxx/login.jsp"
HTTP WARNING: HTTP/1.1 400 No Host matches server name skylink-3488y1g - 143 bytes in 0.002 second response time |time=0.002433s;;;0.000000 size=143B;;;0
-----------------------------------------------------------
过一会,就能在nagios的services中看到172.16.1.191:9000/gx/login.jsp这个地址能正常访问了。
172.16.1.191
172.16.1.191:9000/gx/login.jsp
OK 04-17-2014 21:05:21 0d 0h 0m 49s 1/5 HTTP OK: HTTP/1.1 200 OK - 1438 bytes in 0.016 second response time
check-host-alive
OK 04-17-2014 21:04:19 0d 0h 1m 51s 1/5 PING OK - Packet loss = 0%, RTA = 0.49 ms
改动一下地址172.16.1.191:9000/gxx/login.jsp(为gxx),看结果如何:提示没有找到合适的地址,结果正确。
172.16.1.191
172.16.1.191:9000/gxx/login.jsp
WARNING 04-17-2014 21:09:04 0d 0h 1m 9s 1/5 HTTP WARNING: HTTP/1.1 400 No Host matches server name 172.16.1.191 - 139 bytes in 0.002
second response time
check-host-alive
PENDING N/A 0d 0h 2m 9s+ 1/5 Service check scheduled for Thu Apr 17 21:10:04 CST 2014
=============================================================================
自定义一个check_http_nh命令来做:
[root@nhserver2_5 objects]# cd /usr/local/nagios/etc/objects
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
#command_line $USER1$/check_http -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$
}
#加入一个自定义的命令
define command{
command_name check_http_nh
#command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
command_line $USER1$/check_http_nh -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$
}
[root@nhserver2_5 libexec]# cd /usr/local/nagios/libexec
[root@nhserver2_5 libexec]# cp check_http check_http_nh
[root@nhserver2_5 libexec]# chown nagios.nagios check_http_nh
[root@nhserver2_5 objects]# cd /usr/local/nagios/etc/objects
[root@nhserver2_5 objects]# vim hosts_172.16.1.191.cfg
define host{
use windows-server
host_name 172.16.1.191
alias 172.16.1.191
address 172.16.1.191
}
define hostgroup{
hostgroup_name windows-servers
alias Windows Servers
}
define service{
use local-service
host_name 172.16.1.191
service_description check-host-alive
check_command check-host-alive
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
define service{
use local-service
host_name 172.16.1.191
service_description 172.16.1.191:9000/gx/login.jsp
check_command check_http_nh!9000!"/gx/login.jsp" #改为自定义的命令来检测
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
[root@nhserver2_5 libexec]# cd /usr/local/nagios/libexec
[root@nhserver2_5 libexec]# ./check_http_nh -I 172.16.1.191 -p 9000 -u "/gx/login.jsp"
HTTP OK: HTTP/1.1 200 OK - 1438 bytes in 0.020 second response time |time=0.019584s;;;0.000000 size=1438B;;;0
[root@nhserver2_5 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@nhserver2_5 objects]# service nagios reload
过一会儿,就能看到nagios中的service的状态正常了:
172.16.1.191
172.16.1.191:9000/gx/login.jsp
OK 04-17-2014 21:46:20 0d 0h 1m 1s 1/5 HTTP OK: HTTP/1.1 200 OK - 1438 bytes in 0.009 second response time
check-host-alive
OK 04-17-2014 21:45:20 0d 0h 2m 1s 1/5 PING OK - Packet loss = 0%, RTA = 0.97 ms