报错信息:
It appears as though you do not have permission to view information for any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.
解决方法:
[root@oracle-linux6 ~]# sed -i 's/use_authentication=1/use_authentication=0/g' /usr/local/nagios/etc/cgi.cfg
接着刷新网页即可。
默认就监控本机(localhost):
Nagios服务器的Linux主机文件(localhost.cfg):
[root@oracle-linux6 ~]# cat /usr/local/nagios/etc/objects/localhost.cfg |grep -v "^#" |grep -v "^$"
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost ; Comma separated list of hosts that belong to this group
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Users
check_command check_local_users!20!50
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Swap Usage
check_command check_local_swap!20!10
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 0
}
备注:不同主机用主机名(host_name)进行区分,服务是跟主机名的。
也可以用命令行测试远程主机的HTTP服务:
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_http -I www.baidu.com
HTTP OK: HTTP/1.0 200 OK - 286558 bytes in 3.510 second response time |time=3.509989s;;;0.000000 size=286558B;;;0
命令行测试本机的TCP 端口:
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 80
TCP OK - 0.000 second response time on 127.0.0.1 port 80|time=0.000208s;;;0.000000;10.000000
命令行测试远程主机的TCP端口:
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_tcp -H www.baidu.com -p 80
TCP OK - 0.019 second response time on www.baidu.com port 80|time=0.019031s;;;0.000000;10.000000
[root@oracle-linux6 ~]#
[root@oracle-linux6 ~]# echo $?
0
注释:TCP端口能通时,返回值为0
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_tcp -H www.baidu.com -p 888
CRITICAL - Socket timeout after 10 seconds
[root@oracle-linux6 ~]#
[root@oracle-linux6 ~]# echo $?
2
注释:TCP端口不能通时,返回值为非0
命令行测试远程主机的NTP服务:( 远程主机必须要在防火墙开启UDP 123端口 )
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_ntp -H 192.168.168.130
NTP OK: Offset unknown|
[root@oracle-linux6 ~]#
[root@oracle-linux6 ~]# echo $?
0
注释:UDP 123端口能通时,返回值为0
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_ntp -H 192.168.168.130
CRITICAL: No response from NTP server
[root@oracle-linux6 ~]#
[root@oracle-linux6 ~]# echo $?
2
注释:UDP 123不能通时,返回值为非0
命令行测试远程主机是否能PING通:
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_icmp -H 192.168.168.130
OK - 192.168.168.130: rta 0.403ms, lost 0%|rta=0.403ms;200.000;500.000;0; pl=0%;40;80;; rtmax=0.497ms;;;; rtmin=0.322ms;;;;
[root@oracle-linux6 ~]#
[root@oracle-linux6 ~]# echo $?
0
注释:能通时,返回值为0;不能通时,返回值为非0
可以不显示输出结果:
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_icmp -H 192.168.168.130 > /dev/null
[root@oracle-linux6 ~]#
[root@oracle-linux6 ~]# echo $?
0
可以自定义输出结果:
[root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_icmp -H 192.168.168.130 > /dev/null && echo 'yes'
yes
######
查看Nagios的告警历史记录: