Nagios利用NSClient++监控Windows主机
一、简介
1、获取更多的NSClient原理,请参考NSClient++官方站点
NSClient++官网:http://www.nsclient.org/
2、NSClient++与NRPE
NSClient++的工作原理
NRPE的工作原理
Nagios对Windows主机的监控主要有三种方法
第一种是NSclient++
第二种是NRPE
第三种是SNMP(不是很常用)
NSclient++与nrpe最大的区别就是:
1、被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的.当监控主机将监控请求发给nrpe后,nrpe调用插件来完成监控.
2、NSclient++则不同,被监控机上只安装NSclient++,没有任何的插件.当监控主机将监控请求发给NSclient++后,NSclient++直接完成监控,所有的监控是由NSclient++完成的。
这也说明了NSclient++的一个很大的问题,不灵活,没有可扩展性.它只能完成自己本身包含的监控操作,不能由一些插件来扩展.好在NSclient++已经做的不错了,基本上可以完全满足我们的监控需要。
二、check_nt的方式监控windows主机
1、下载NSClient++
下载地址:http://sourceforge.net/projects/nscplus/files/nscplus/
2、安装NSClient++
Allowed hosts:(this is the IP of the nagios (or other)server)
允许的主机地址:Nagios服务器端的IP地址
NSClient password(only userd via check_nt)
NSClient的密码:填写Nagios跟NSClient++进程通信的密码,可以不设置
Modules to load:
安装并加载相应的模块:NSClient++自带的有check_plugins插件,check_nt,check_nrpe,NSCA,WMI
在这里我们全部选择,以后会有用到的。
点击【Finsh】,表示安装NSClient++完成
3、查看NSClient++服务是否已经启用
4、查看NSClient++的配置文件
默认是安装在C:\Program Files\NSClient++ 目录下,NSC.ini即为NSClient服务的配置文件,一般我们无需修改,但是当我们监控端的IP地址改变时,或者密码忘记,即可以在这里修改了。
安装时加载的模块
设置允许连接的地址:为Nagios的IP地址
NRPE的默认端口号
三、NSClient应用监控
NSClient++与Nagios服务器通信,主要使用Nagios服务器的check_nt插件。原理图如下
1、check_nt插件的使用说明
[root@Nagios~]#cd/usr/local/nagios/libexec/[root@Nagioslibexec]#./check_nt-h#查看check_nt的语法check_ntv2.0.3(nagios-plugins2.0.3)Copyright(c)2000YvesRubin(rubiyz@yahoo.com)Copyright(c)2000-2014NagiosPluginDevelopmentTeam<devel@nagios-plugins.org>ThisplugincollectsdatafromtheNSClientservicerunningonaWindowsNT/2000/XP/2003server.Usage:check_nt-Hhost-vvariable[-pport][-wwarning][-ccritical][-lparams][-dSHOWALL][-u][-ttimeout]Options:-h,--helpPrintdetailedhelpscreen-V,--versionPrintversioninformation--extra-opts=[section][@file]Readoptionsfromaninifile.Seehttps://www.nagios-plugins.org/doc/extra-opts.htmlforusageandexamples.Options:-H,--hostname=HOSTNameofthehosttocheck-p,--port=INTEGEROptionalportnumber(default:1248)#默认端口号-s,--secret=<password>#指定的密码Passwordneededfortherequest-w,--warning=INTEGERThresholdwhichwillresultinawarningstatus-c,--critical=INTEGERThresholdwhichwillresultinacriticalstatus-t,--timeout=INTEGERSecondsbeforeconnectionattempttimesout(default:-l,--params=<parameters>Parameterspassedtospecifiedcheck(seebelow)-d,--display={SHOWALL}Displayoptions(currentlyonlySHOWALLworks)-u,--unknown-timeoutReturnUNKNOWNontimeouts10)-h,--helpPrintthishelpscreen-V,--versionPrintversioninformation-v,--variable=STRINGVariabletocheckValidvariablesare:CLIENTVERSION=GettheNSClientversionIf-l<version>isspecified,willreturnwarningifversionsdiffer.CPULOAD=AverageCPUloadonlastxminutes.Requesta-lparameterwiththefollowingsyntax:-l<minutesrange>,<warningthreshold>,<criticalthreshold>.<minuterange>shouldbelessthan24*60.Thresholdsarepercentageandupto10requestscanbedoneinoneshot.ie:-l60,90,95,120,90,95UPTIME=Gettheuptimeofthemachine.-l<unit><unit>=seconds,minutes,hours,ordays.(default:minutes)Thresholdswillusetheunitspecifiedabove.USEDDISKSPACE=Sizeandpercentageofdiskuse.Requesta-lparametercontainingthedriveletteronly.Warningandcriticalthresholdscanbespecifiedwith-wand-c.MEMUSE=Memoryuse.Warningandcriticalthresholdscanbespecifiedwith-wand-c.SERVICESTATE=Checkthestateofoneorseveralservices.Requesta-lparameterswiththefollowingsyntax:-l<service1>,<service2>,<service3>,...Youcanspecify-dSHOWALLincaseyouwanttoseeworkingservicesinthereturnedstring.PROCSTATE=Checkifoneorseveralprocessarerunning.SamesyntaxasSERVICESTATE.COUNTER=CheckanyperformancecounterofWindowsNT/2000.Requesta-lparameterswiththefollowingsyntax:-l"\\<performanceobject>\\counter","<description>The<description>parameterisoptionalandisgiventoaprintfoutputcommandwhichrequiresafloatparameter.If<description>doesnotinclude"%%",itisusedasalabel.Someexamples:"Pagingfileusageis%%.2f%%%%""%%.f%%%%pagingfileused."INSTANCES=CheckanyperformancecounterobjectofWindowsNT/2000.Syntax:check_nt-H<hostname>-p<port>-vINSTANCES-l<counterobject><counterobject>isaWindowsPerfmonCounterobject(eg.Process),ifitistwowords,itshouldbeenclosedinquotesThereturnedresultswillbeacomma-separatedlistofinstancesontheselectedcomputerforthatobject.ThepurposeofthisistoberunfromcommandlinetodeterminewhatinstancesareavailableformonitoringwithouthavingtologontotheWindowsservertorunPerfmondirectly.ItcanalsobeusedinscriptsthatautomaticallycreateNagiosserviceconfigurationfiles.Someexamples:check_nt-H192.168.1.1-p1248-vINSTANCES-lProcess#check_nt的语法Notes:-TheNSClientserviceshouldberunningontheservertogetanyinformation(http://nsclient.ready2run.nl).-Criticalthresholdsshouldbelowerthanwarningthresholds-Defaultport1248issometimesinusebyotherservices.Theerroroutputwhenthishappenscontains"Cannotmapxxxxxtoprotocolnumber".Onefixforthisistochangetheporttosomethingelseoncheck_ntandontheclientserviceit'sconnectingto.Sendemailtohelp@nagios-plugins.orgifyouhavequestionsregardinguseofthissoftware.Tosubmitpatchesorsuggestimprovements,sendemailtodevel@nagios-plugins.org
2、check_nt命令的使用
check_nt参数解释
-w:警告比例
-c:紧急比例
-l:过去5分钟的平均值,80%的警告 90%紧急
四、定义命令、主机、服务
1、定义命令
[root@Nagios~]#vim/usr/local/nagios/etc/objects/commands.cfg#'check_win'commanddefinitiondefinecommand{command_namecheck_wincommand_line$USER1$/check_nt-H$HOSTADDRESS$-p12489-v$ARG1$$ARG2$}注释:$..$表示系统内置的宏,也就是所谓的变量$USER1$表示插件所在的目录-H指定主机地址$HOSTADDRESS$应用到哪个主机,就用哪个主机的地址$ARG1$传递的参数,形参-s指定密码默认为空
2、定义主机和服务
[root@Nagiosobjects]#cpwindows.cfgwindows106.cfg[root@Nagiosobjects]#sed-i's/winserver/Windows106/g'windows106.cfg[root@Nagiosobjects]#sed-i's/192.168.1.2/192.168.0.106/'windows106.cfg
4、检测配置文件是否有语法错误
[root@Nagios~]#servicenagiosconfigtestNagiosCore4.0.7Copyright(c)2009-presentNagiosCoreDevelopmentTeamandCommunityContributorsCopyright(c)1999-2009EthanGalstadLastModified:06-03-2014License:GPLWebsite:http://www.nagios.orgReadingconfigurationdata...Readmainconfigfileokay...Readobjectconfigfilesokay...Runningpre-flightcheckonconfigurationdata...Checkingobjects...Checked8services.Checked1hosts.Checked1hostgroups.Checked0servicegroups.Checked1contacts.Checked1contactgroups.Checked25commands.Checked5timeperiods.Checked0hostescalations.Checked0serviceescalations.Checkingforcircularpaths...Checked1hostsChecked0servicedependenciesChecked0hostdependenciesChecked5timeperiodsCheckingglobaleventhandlers...Checkingobsessivecompulsiveprocessorcommands...Checkingmiscsettings...TotalWarnings:0TotalErrors:0Thingslookokay-Noseriousproblemsweredetectedduringthepre-flightcheckObjectprecachefilecreated:/usr/local/nagios/var/objects.precache
5、重启nagios服务
[root@Nagiosobjects]#servicenagiosrestartRunningconfigurationcheck...Stoppingnagios:.done.Startingnagios:done.
四、浏览器查看监控信息
1、登陆后点击【Hosts】,查看新监控的Windows主机信息
2、点击【Services】,查看Windows服务的状态信息
3、等待几分钟后状态就正常了,如下图所示
三、NRPE的方式监控windows主机
1、修改NSClient++的配置文件
2、重新启动NSClient++服务
3、Nagios服务端测试NRPE命令
[root@Nagios~]#cd/usr/local/nagios/libexec/[root@Nagioslibexec]#./check_nrpe-hNRPEPluginforNagiosCopyright(c)1999-2008EthanGalstad(nagios@nagios.org)Version:2.15LastModified:09-06-2013License:GPLv2withexemptions(-lformoreinfo)SSL/TLSAvailable:AnonymousDHMode,OpenSSL0.9.6orhigherrequiredUsage:check_nrpe-H<host>[-b<bindaddr>][-4][-6][-n][-u][-p<port>][-t<timeout>][-c<command>][-a<arglist...>]Options:-n=DonouseSSL-u=MakesockettimeoutsreturnanUNKNOWNstateinsteadofCRITICAL<host>=TheaddressofthehostrunningtheNRPEdaemon<bindaddr>=bindtolocaladdress-4=useripv4only-6=useripv6only[port]=Theportonwhichthedaemonisrunning(default=5666)[timeout]=Numberofsecondsbeforeconnectiontimesout(default=10)[command]=Thenameofthecommandthattheremotedaemonshouldrun[arglist]=Optionalargumentsthatshouldbepassedtothecommand.Multipleargumentsshouldbeseparatedbyaspace.Ifprovided,thismustbethelastoptionsuppliedonthecommandline.Note:ThispluginrequiresthatyouhavetheNRPEdaemonrunningontheremotehost.Youmustalsohaveconfiguredthedaemontoassociateaspecificplugincommandwiththe[command]optionyouarespecifyinghere.Uponreceiptofthe[command]argument,theNRPEdaemonwillruntheappropriateplugincommandandsendthepluginoutputandreturncodebackto*this*plugin.Thisallowsyoutoexecutepluginsonremotehostsand'fake'theresultstomakeNagiosthinkthepluginisbeingrunlocally.check_nrpe语法:check_nrpe...-c<command>[-a<argument><argument><argument>]check_nrpe的内置命令:·CheckAlwaysCRITICAL(check)·CheckAlwaysOK(check)·CheckAlwaysWARNING(check)·CheckCPU(check)·CheckCRITICAL(check)·CheckCounter(check)·CheckEventLog/CheckEventLog(check)·CheckFile(check)·CheckFileSize(check)·CheckMem(check)·CheckMultiple(check)·CheckOK(check)·CheckProcState(check)·CheckServiceState(check)·CheckTaskSched/CheckTaskSched(check)·CheckUpTime(check)·CheckVersion(check)·CheckWARNING(check)·CheckWMI/CheckWMI(check)·CheckWMIValue(check)
[root@Nagioslibexec]#./check_nrpe-H192.168.1.142-p5666-cCheckCPU-awarn=80crit=90time=20mtime=10stime=4OKCPULoadok.|'20m'=0%;80;90'10s'=0%;80;90'4'=0%;80;90
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。