nagios+pnp4nagios系列文章(五) 安装配置及rrdtool出图最详细配置,解决途中遇到的各种问题!!!

1、安装软件:

名称:NSclient++(NSCP-0.4.1.73-x64.msi/NSCP-0.4.1.90-Win32.msi

安装软件时,需要输入nagios服务器的IP地址或主机名、密码。
可在nsclient.ini配置文件中,找到[/settings/default]配置项,在该标签项中查看。
-------------------------------------------------
2、添加服务:
[root@HAD06 check_commands]# vim /usr/local/nagios/etc/nagios.cfg
添加:
cfg_dir=/usr/local/nagios/etc/winservers
启用/usr/local/nagios/etc/winservers目录下主机配置文件。(无需再手动添加每一台监控主机,软件可自动加载该目录下的所有主机配置文件。
[root@HAD06 check_commands]# mkdir /usr/local/nagios/etc/winservers
[root@HAD06 check_commands]# chown nagios.nagios /usr/local/nagios/etc/winservers
[root@HAD06 check_commands]# ll /usr/local/nagios/etc/
总用量 140
-rw-rw-r--. 1 nagios nagios 11674 1月  20 22:50 cgi.cfg
-rw-rw-r--. 1 nagios nagios 11669 1月  20 15:24 cgi.cfg~
-rw-r--r--. 1 nagios nagios    27 1月  16 00:51 htpasswd.users
-rw-rw-r--. 1 nagios nagios 44765 1月  24 02:54 nagios.cfg
-rw-rw-r--. 1 nagios nagios 44710 1月  20 15:24 nagios.cfg~
-rw-r--r--. 1 nagios nagios  7988 1月  15 23:45 nrpe.cfg
drwxrwxr-x. 2 nagios nagios  4096 1月  24 03:56 objects
-rw-rw----. 1 nagios nagios  1340 1月  20 19:28 resource.cfg
-rw-rw----. 1 nagios nagios  1340 1月  20 15:24 resource.cfg~
drwxr-xr-x. 2 nagios nagios  4096 1月  24 11:19 winservers
[root@HAD06 check_commands]# vim /usr/local/nagios/etc/objects/commands.cfg
找到:
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
        }
修改成:
define command{
        command_name    check_nt
        command_line   $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 123456789 -v $ARG1$ $ARG2$  --安装NSclient++时将密码设置成:123456789
        }
[root@HAD06 check_commands]# vim /usr/local/nagios/etc/winservers/192.168.100.99.cfg
[root@HAD06 check_commands]# cat /usr/local/nagios/etc/winservers/192.168.100.99.cfg
###############################################################################
# WINDOWS.CFG - SAMPLE CONFIG FILE FOR MONITORING A WINDOWS MACHINE
#
# Last Modified: 06-13-2007
#
# NOTES: This config file assumes that you are using the sample configuration
#     files that get installed with the Nagios quickstart guide.
#
###############################################################################



###############################################################################
###############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################

# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation

define host{
    use        windows-server,host-pnp4    ; Inherit default values from a template
    host_name    192.168.100.99        ; The name we're giving to this host
    alias        192.168.100.99    ; A longer name associated with the host
    address        192.168.100.99    ; IP address of the host
        parents        linksys-Ruijie
    icon_image              win40.gif
        statusmap_image         win40.gd2
    2d_coords        500,200
    3d_coords        500,200,100
    }


###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################


# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    NSClient++ Version
    check_command        check_nt!CLIENTVERSION
    }



# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    Uptime
    check_command        check_nt!UPTIME
    }


# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    CPU Load
    check_command        check_nt!CPULOAD!-l 5,80,90
    }


# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    Memory Usage
    check_command        check_nt!MEMUSE!-w 80 -c 90
    }


# Create a service for monitoring C:\ disk usage
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    C:\ Drive Space
    check_command        check_nt!USEDDISKSPACE!-l c -w 80 -c 90
    }


# Create a service for monitoring the W3SVC service
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    W3SVC
    check_command        check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
    }


# Create a service for monitoring the Explorer.exe process
# Change the host_name to match the name of the host you defined above

define service{
    use            generic-service,svr-pnp4
    host_name        192.168.100.99
    service_description    Explorer
    check_command        check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
    }


define service{
        use                     generic-service,svr-pnp4
        host_name               192.168.100.99
        service_description     TCP-9008
        check_command           check_tcp!9008
        }

[root@HAD06 check_commands]#  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@HAD06 check_commands]# service nagios restart
-------------------------------------------------
3、添加服务实现对windows主机CPU温度监控:
#在被监控主机上部署该服务:
将附件解压,产生三个文件:check_temperature.vbs、OpenHardwareMonitorLib.dll、OpenHardwareMonitorReport.exe。将此三个文件拷贝到C:\Program Files\NSClient++\scripts目录下。
编辑nsclient.ini配置文件,添加以下配置项:
[/settings/external scripts/wrappings]
vbs=cscript.exe //T:30 //NoLogo %SCRIPT% %ARGS%

[/settings/external scripts/wrapped scripts]
check_temperature = scripts\\check_temperature.vbs
#定义CPU温度监控的命令:
[root@HAD06 check_commands]# vim /usr/local/nagios/etc/objects/commands.cfg
添加:
define command{
        command_name check_cpu_temperature
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_temperature
        }
#在nagios服务器使用命令测试:
[root@HAD06 check_commands]# ./check_nrpe -H 192.168.100.99 -c check_temperature
Measured CPU Temperatures: 0:29, 1:32, 2:25, 3:27, 4:19, 5:20, 6:27, 7:14 |'Max_Cpu_Temperature'=32Celsius;38;45;0;100
经测试该命令可以检测CPU的温度。
#添加CPU温度监控的配置项:
[root@HAD06 check_commands]# vim /usr/local/nagios/etc/winservers/192.168.100.99.cfg
define service{
        use                     generic-service,svr-pnp4
        host_name               192.168.100.99
        service_description     CPU_Temperature
        check_command           check_cpu_temperature
        normal_check_interval   2
        }
注:normal_check_interval   2:此选项是用来设置服务检查时间间隔,也就是说,nagios这一次检查和下一次检查之间所隔的时间,这里是2分钟
#重启nagios服务:
[root@HAD06 check_commands]# service nagios restart
******************************************************************
说明一下:
nsclient.ini配置文件中的check_temperature定义为1;
/usr/local/nagios/etc/objects/commands.cfg配置文件中的check_temperature定义为2;
/usr/local/nagios/etc/objects/commands.cfg配置文件中的check_cpu_temperature定义为3;
/usr/local/nagios/etc/winservers/192.168.100.99.cfg配置文件中的check_cpu_temperature定义为4;
/usr/local/nagios/etc/winservers/192.168.100.99.cfg配置文件中的CPU_Temperature定义为5;
如果1改变,那么2必须改变;
1、2跟其他么有直接关系,只是名字意义上的相似;
如果3改变,那么4必须改变;
5是可以在网页中显示的名字;
关系:nsclient.ini定义commands.cfg名称;
          commands.cfg定义192.168.100.99.cfg主机配置文件的名称;
          在192.168.100.99.cfg主机配置文件定义网页中显示的名字;
******************************************************************
附件:(包含三个文件:check_temperature.vbs、OpenHardwareMonitorLib.dll、OpenHardwareMonitorReport.exe)
-------------------------------------------------
4、网卡流量监控的实现:
Windows客户端的操作:
在windows主机上安装并SNMP服务

1、安装:

开始-控制面板-添加删除程序-添加/删除windows组件-选管理和监视工具-选简单网络管理协议(snmp),如图:

不过,在点击添加/删除windows组件时,可能会遇到错误“无法加载安装程序库 wbemupgd.dll,或是找不到函数 0cEntry。请与您的系统管理员联系。特定错误码是0x7e”。该问题的解决方法如下:

a、在windows环境变量的系统变量中增加一项,变量名填“path”,变量值填“%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem” 。

b、打开注册表,找到HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment,在其下增加如下键值:

名称:path
类型:REG_EXPAND_SZ
值:%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem

2、配置:

运行-services.msc-SNMP service-右键-属性-陷阱-在团体名称中填写如"nagios"-添加到列表,切换至"安全"选项卡,在接受团体名称点击添加-输入团体名称如“nagios”,在“接受来自这些主机的snmp数据包” 中添加远程nagios主机的IP。

3、开启防火墙端口

在windows防火墙例外端口中增加udp端口,端口号为161 。


Nagios服务器端的操作:
[root@HAD06 check_commands]# vim /usr/local/nagios/etc/objects/commands.cfg
#将附件中的文件check_traffic.sh拷贝到Nagios服务器上/usr/local/nagios/libexec目录中
[root@HAD06 check_commands]# ll /usr/local/nagios/libexec/check_traffic.sh
-rwxr-xr-x 1 nagios nagios 57584 11月 18 11:34 /usr/local/nagios/libexec/check_traffic.sh
#定义网卡流量监控的命令:
添加:
define command{
        command_name check_traffic_win
        command_line $USER1$/check_traffic.sh -V $ARG1$ -C $ARG2$ -H $HOSTADDRESS$ -I $ARG3$ -w $ARG4$ -c $ARG5$ -K -B
        }
[root@HAD06 check_commands]# cd /usr/local/nagios/libexec/
[root@HAD06 libexec]# ./check_traffic.sh -V 2c -C public -H 192.168.100.99 -L
List Interface for host 192.168.100.99.
Interface index 1 orresponding to  Software Loopback Interface 1
Interface index 2 orresponding to  WAN 微型端口(L2TP)
Interface index 3 orresponding to  WAN 微型端口(SSTP)
Interface index 4 orresponding to  WAN Miniport (IKEv2)
Interface index 5 orresponding to  WAN 微型端口(PPTP)
Interface index 6 orresponding to  WAN 微型端口(PPPOE)
Interface index 7 orresponding to  WAN 微型端口(IP)
Interface index 8 orresponding to  WAN 微型端口(IPv6)
Interface index 9 orresponding to  WAN 微型端口(网络监视器)
Interface index 10 orresponding to  Microsoft 内核调试网络适配器
Interface index 11 orresponding to  RAS 同步适配器
Interface index 12 orresponding to  Intel(R) 82574L 千兆网络连接
Interface index 13 orresponding to  Intel(R) 82574L 千兆网络连接 #2
Interface index 14 orresponding to  Microsoft ISATAP Adapter
Interface index 15 orresponding to  Microsoft ISATAP Adapter #2
Interface index 16 orresponding to  Microsoft ISATAP Adapter #3
Interface index 17 orresponding to  VMware Virtual Ethernet Adapter for VMnet1
Interface index 18 orresponding to  VMware Virtual Ethernet Adapter for VMnet8
Interface index 19 orresponding to  Microsoft ISATAP Adapter #4
Interface index 20 orresponding to  Teredo Tunneling Pseudo-Interface
Interface index 21 orresponding to  WAN 微型端口(IP)-WFP Native MAC Layer LightWeight Filter-0000
Interface index 22 orresponding to  WAN 微型端口(IP)-QoS Packet Scheduler-0000
Interface index 23 orresponding to  WAN 微型端口(IPv6)-WFP Native MAC Layer LightWeight Filter-0000
Interface index 24 orresponding to  WAN 微型端口(IPv6)-QoS Packet Scheduler-0000
Interface index 25 orresponding to  Intel(R) 82574L 千兆网络连接-WFP Native MAC Layer LightWeight Filter-0000
Interface index 26 orresponding to  Intel(R) 82574L 千兆网络连接 #2-WFP Native MAC Layer LightWeight Filter-0000
Interface index 27 orresponding to  Intel(R) 82574L 千兆网络连接-QoS Packet Scheduler-0000
Interface index 28 orresponding to  Intel(R) 82574L 千兆网络连接 #2-QoS Packet Scheduler-0000
Interface index 29 orresponding to  WAN 微型端口(网络监视器)-WFP Native MAC Layer LightWeight Filter-0000
Interface index 30 orresponding to  Intel(R) 82574L 千兆网络连接-WFP 802.3 MAC Layer LightWeight Filter-0000
Interface index 31 orresponding to  WAN 微型端口(网络监视器)-QoS Packet Scheduler-0000
Interface index 32 orresponding to  Intel(R) 82574L 千兆网络连接 #2-WFP 802.3 MAC Layer LightWeight Filter-0000
#在nagios服务器使用命令测试:
[root@HAD06 check_commands]# ./check_traffic.sh -V 2c -C public -H 192.168.100.99 -I 25 -w 12000,15000 -c 17000,18000
OK - The Traffic In is 40Kbps, Out is 9Kbps, Total is 49Kbps. The Check Interval is 138s |In=40Kbps;12000;17000;0;0 Out=9Kbps;15000;18000;0;0 Total=49Kbps;27000;35000;0;0 Interval=138s;1200;1800;0;0
经测试该命令可以监控网卡的流量。
#添加网卡流量监控的配置项:
[root@HAD06 libexec]# vim /usr/local/nagios/etc/winservers/192.168.100.99.cfg
define service{
        use                     generic-service,svr-pnp4
        host_name               192.168.100.99
        service_description     Traffic_Network_WFP Native MAC Layer LightWeight Filter
        check_command           check_traffic_win!2c!public!25!12000,15000!17000,18000
        normal_check_interval   5
        }
******************************************************************
说明一下:
192.168.100.99.cfg主机配置文件中,命令(check_command)中第三个参数是根据check_traffic.sh -V 2c -C public -H 192.168.100.99 -L结果得出的index后面的数字。
#将附件中文件check_traffic_win.php拷贝到/usr/local/pnp4nagios/share/templates/目录下。
[root@HAD06 libexec]# chown nagios.nagios /usr/local/pnp4nagios/share/templates/
监控网卡流量的服务,需要使用跟服务配套的出图文件。
#重启nagios服务:
[root@HAD06 libexec]# service nagios restart
******************************************************************
linux技术交流群:295294329   本文朋友郭工整理,感谢他的共享!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章