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 本文朋友郭工整理,感謝他的共享!!!