監控主機配置:redhatlinuxas4,nagios3
被監控主機:WindowsServer2008R2Enterprise,nsclient++0.4.4.172
Nagios是一款開源的免費網絡監視工具,其功能強大,靈活性強。能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網絡設置,打印機等。nagios監控windows系統有三種實現方式:SNMP、NSClient++、NRPE。

下面介紹使用NSClient++方式來監控Windows:
在windows下安裝nsclient++,運行NSCP-0.4.0.172-x64.msi安裝文件,一步一步往下走,其中需要設置nagios監控主機IP和NSClient密碼(值當使用check_nt時使用)。
Allowed hosts:填寫nagios監控主機IP。
NSClient Password:當使用命令check_nt時需要設置密碼,根據自己情況設置。
Module to load:根據自己的需要選擇相應的模塊。
安裝完畢以后,打開windows服務管理器,查看nsclient服務是否啟動,然后在nagios監控主機上面進行相關的配置,主要涉及兩個配置文件nagios.cfg和windows.cfg。
1、 因為nagios是模塊化調用,先到配置文件打開windows相關模塊,編輯nagios.cfg文件:
[root@localhostetc]#ls
cgi.cfghtpasswdnagios.cfgnrpe.cfgobjectsobjects.bakobjects.tarresource.cfg
[root@localhostetc]#pwd
/usr/local/nagios/etc
[root@localhostetc]#vinagios.cfg
將#cfg_file=/usr/local/nagios/etc/objects/windows.cfg該行前面的#注釋去掉即可。
2、修改windows.cfg配置文件,需要修改define host和define service兩部分:
#DefineahostfortheWindowsmachinewe'llbemonitoring
#Changethehost_name,alias,andaddresstofityoursituation
definehost
{usewindows-server;Inheritdefaultvaluesfromatemplate
host_namevideo4-beijing;Thenamewe'regivingtothishost被監控主機的主機名
aliasvideo4-beijing;Alongernameassociatedwiththehost
contact_groupssa;
address10.12.4.169;IPaddressofthehost被監控主機的IP}
#CreateaserviceformonitoringCPUload
#Changethehost_nametomatchthenameofthehostyoudefinedabove
defineservice
{usegeneric-service
host_namevideo4-beijing
service_descriptionCPULoad
check_commandcheck_nt!CPULOAD!-l5,80,90
contact_groupssa}
#Createaserviceformonitoring
#Changethehost_nametomatchthenameofthehostyoudefinedabove
defineservice
{usegeneric-service
host_namevideo4-beijing
service_descriptionMemoryUsage
check_commandcheck_nt!MEMUSE!-w80-c90
contact_groupssa}
#CreateaserviceformonitoringC:/diskusage
#Changethehost_nametomatchthenameofthehostyoudefinedabove
defineservice
{usegeneric-service
host_namevideo4-beijing
service_descriptionC:/DriveSpace
check_commandcheck_nt!USEDDISKSPACE!-lc-w80-c90
contact_groupssa}
3、修改完相關的配置文件以后,執行如下命令檢查配置文件是否正確:
[root@localhostobjects]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
4、遇到的問題,在檢查配置文件時錯誤信息如下:
Checkingservices...
Error:Contactgroup'admins'specifiedinservice'C:/DriveSpace'forhost'video4-beijing'isnotdefinedanywhere!
Error:Contactgroup'admins'specifiedinservice'Explorer'forhost'video4-beijing'isnotdefinedanywhere!
Error:Contactgroup'admins'specifiedinservice'MemoryUsage'forhost'video4-beijing'isnotdefinedanywhere!
Checked14services.
Checkinghosts...
Error:Contactgroup'admins'specifiedinhost'video4-beijing'isnotdefinedanywhere!
Checked7hosts.
Checkinghostgroups...
Checked2hostgroups.
Checkingservicegroups...
Checked0servicegroups.
Checkingcontacts...
Checked1contacts.
Checkingcontactgroups...
Checked1contactgroups.
Checkingserviceescalations...
Checked0serviceescalations.
Checkingservicedependencies...
Checked0servicedependencies.
Checkinghostescalations...
Checked0hostescalations.
Checkinghostdependencies...
Checked0hostdependencies.
Checkingcommands...
Checked25commands.
Checkingtimeperiods...
Checked5timeperiods.
Checkingforcircularpathsbetweenhosts...
Checkingforcircularhostandservicedependencies...
Checkingglobaleventhandlers...
Checkingobsessivecompulsiveprocessorcommands...
Checkingmiscsettings...
TotalWarnings:0
TotalErrors:4
***>Oneormoreproblemswasencounteredwhilerunningthepre-flightcheck...
Checkyourconfigurationfile(s)toensurethattheycontainvalid
directivesanddatadefintions.Ifyouareupgradingfromaprevious
versionofNagios,youshouldbeawarethatsomevariables/definitions
mayhavebeenremovedormodifiedinthisversion.Makesuretoread
theHTMLdocumentationregardingtheconfigfiles,aswellasthe
'WhatsNew'sectiontofindoutwhathaschanged.
以上問題的原因是因為一開始在windows.cfg文件中定義host和service時沒有增加contact_groupssa這個字段,host和service默認所在的contact_group為admins,而我的nagios監控主機contacts.cfg文件中配置的contactgroup為sa。