{"id":117,"date":"2014-08-12T15:34:54","date_gmt":"2014-08-12T15:34:54","guid":{"rendered":"http:\/\/info.ffteixeira.net\/2014\/08\/12\/monitoring-windows-hosts-with-nagios-on-debian-gnu-linux\/"},"modified":"2014-08-12T15:34:54","modified_gmt":"2014-08-12T15:34:54","slug":"monitoring-windows-hosts-with-nagios-on-debian-gnu-linux","status":"publish","type":"post","link":"https:\/\/blog.ffteixeira.net\/?p=117","title":{"rendered":"Monitoring Windows hosts with Nagios on Debian GNU\/Linux"},"content":{"rendered":"<p><b>1. Install necessery nagios debian packages <\/b><\/p>\n<p><em><code>apt-get install nagios-images nagios-nrpe-plugin nagios-nrpe-server nagios-plugins nagios-plugins-basic nagios-plugins-standard<br \/>nagios3 nagios3-cgi nagios3-common nagios3-core<\/code><\/em><\/p>\n<p><b>2. Edit \/etc\/nagios-plugins\/config\/nt.cfg <\/b><\/p>\n<p>In the File substitute:<\/p>\n<p><em><code>define command { command_name check_nt command_line \/usr\/lib\/nagios\/plugins\/check_nt -H &#039;$HOSTADDRESS$&#039; -v &#039;$ARG1$&#039; }<\/code><\/em><\/p>\n<p>With:<\/p>\n<p><em><code>define command {<br \/>command_name check_nt<br \/>command_line \/usr\/lib\/nagios\/plugins\/check_nt -H &#039;$HOSTADDRESS$&#039; -p 12489 -v $ARG1$ $ARG2$<br \/>}<\/code><\/em><\/p>\n<p><b>3. Modify nrpe.cfg to put in allowd hoss to connect to the Nagions nrpe server <\/b><\/p>\n<p>vim \/etc\/nagios\/nrpe.cfg<\/p>\n<p>Lookup inside for nagios&rsquo;s configuration directive:<\/p>\n<p><em><code>allowed_hosts=127.0.0.1<\/code><\/em><\/p>\n<p>In order to allow more hosts to report to the nagios nrpe daemon, change the value to let&rsquo;s say:<\/p>\n<p><em><code>allowed_hosts=127.0.0.1,192.168.1.4,192.168.1.5,192.168.1.6<\/code><\/em><\/p>\n<p>This config allows the three IPs 192.168.1.4-6 to be able to report for nrpe.<\/p>\n<p>For the changes to nrpe server to take effect, it has to be restrarted.<\/p>\n<p><em><code>debian:~# \/etc\/init.d\/nagios-nrpe-server restart<\/code><\/em><\/p>\n<p>Further on some configurations needs to be properly done on the nrpe agent Windows hosts in this case <b> 192.168.1.4,192.168.1.5,192.168.1.6 <\/b><\/p>\n<p><b>4. Install the nsclient++ on all Windows hosts which CPU, Disk, Temperature and services has to be monitored <\/b><\/p>\n<p>Download the agent from <i>http:\/\/sourceforge.net\/projects\/nscplus<\/i> and launch the installer, click twice on it and follow the installation screens. Its necessery that during installation the agent has the <b> NRPE <\/b> protocol enabled. After the installation is complete one needs to modify the <b>NSC.ini<\/b><br \/>By default many of <i>nsclient++<\/i> tracking modules are not enabled in NSC.ini, thus its necessery that the following DLLs get activated in the conf:<\/p>\n<p><code>FileLogger.dll<br \/>CheckSystem.dll<br \/>CheckDisk.dll<br \/>NSClientListener.dll<br \/>SysTray.dll<br \/>CheckEventLog.dll<br \/>CheckHelpers.dll<\/code><\/p>\n<p>Another requirement is to instruct the nsclient++ angent to have access to the Linux installed nagios server again with adding it to the <b> allowed_hosts <\/b> config variable:<\/p>\n<p><em><code>allowed_hosts=192.168.1.1<\/code><\/em><\/p>\n<p>In my case the Nagios runs on Debian Lenny (Squeeze) 6 and possess the IP address of <b> 192.168.1.1 <\/b><br \/>To test the intalled windows nsclient++ agents are properly installed a simple telnet connection from the Linux host is enough:<\/p>\n<p><b>5. Create necessery configuration for the nagios Linux server to include all the Windows hosts which will be monitored <\/b><\/p>\n<p>There is a <b>window.cfg<\/b> template file located in <b> \/usr\/share\/doc\/nagios3-common\/examples\/template-object\/windows.cfg <\/b> on Debian.<\/p>\n<p>The file is a good start point for creating a conf file to be understand by nagios and used to periodically refresh information about the status of the Windows hosts.<\/p>\n<p>Thus it&rsquo;s a good idea to copy the file to nagios3 config directory:<\/p>\n<p><em><code>debian:~# mkdir \/etc\/nagios3\/objects<br \/>debian:~# cp -rpf \/usr\/share\/doc\/nagios3-common\/examples\/template-object\/windows.cfg \/etc\/nagios3\/objects\/windows.cfg<\/code><\/em><\/p>\n<p>A sample windows.cfg content, (which works for me fine) and monitor a couple of Windows nodes running MS-SQL service and IIS and makes sure the services are up and running are:<\/p>\n<p><em><code>define host{<br \/>use windows-server ; Inherit default values from a template<br \/>host_name Windows1 ; The name we&#039;re giving to this host<br \/>alias Iready Server ; A longer name associated with the host<br \/>address 192.168.1.4 ; IP address of the host<br \/>}<\/code><\/em><\/p>\n<p><em><code>define host{<br \/>use windows-server ; Inherit default values from a template<br \/>host_name Windows2 ; The name we&#039;re giving to this host<br \/>alias Iready Server ; A longer name associated with the host<br \/>address 192.168.1.4 ; IP address of the host<br \/>}<\/code><\/em><\/p>\n<p><em><code>define hostgroup{<br \/>hostgroup_name windows-servers ; The name of the hostgroup<br \/>alias Windows Servers ; Long name of the group<br \/>}<\/code><\/em><\/p>\n<p><em><code>define hostgroup{<br \/>hostgroup_name IIS<br \/>alias IIS Servers<br \/>members Windows1,Windows2<br \/>}<\/code><\/em><\/p>\n<p><em><code>define hostgroup{<br \/>hostgroup_name MSSQL<br \/>alias MSSQL Servers<br \/>members Windows1,Windows2<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows1<br \/>service_description NSClient++ Version<br \/>check_command check_nt!CLIENTVERSION<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{ use generic-service<br \/>host_name Windows1<br \/>service_description Uptime<br \/>check_command check_nt!UPTIME<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{ use generic-service<br \/>host_name Windows1<br \/>service_description CPU Load<br \/>check_command check_nt!CPULOAD!-l 5,80,90<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows1<br \/>service_description Memory Usage<br \/>check_command check_nt!MEMUSE!-w 80 -c 90<br \/>define service{<br \/>use generic-service<br \/>host_name Windows1<br \/>service_description C: Drive Space<br \/>check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows1<br \/>service_description W3SVC<br \/>check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows1<br \/>service_description Explorer<br \/>check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows2<br \/>service_description NSClient++ Version<br \/>check_command check_nt!CLIENTVERSION<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{ use generic-service<br \/>host_name Windows2<br \/>service_description Uptime<br \/>check_command check_nt!UPTIME<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{ use generic-service<br \/>host_name Windows2<br \/>service_description CPU Load<br \/>check_command check_nt!CPULOAD!-l 5,80,90<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows2<br \/>service_description Memory Usage<br \/>check_command check_nt!MEMUSE!-w 80 -c 90<br \/>define service{<br \/>use generic-service<br \/>host_name Windows2<br \/>service_description C: Drive Space<br \/>check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows2<br \/>service_description W3SVC<br \/>check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows2<br \/>service_description Explorer<br \/>check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{ use generic-service<br \/>host_name Windows1<br \/>service_description SQL port Check<br \/>check_command check_tcp!1433<br \/>}<\/code><\/em><\/p>\n<p><em><code>define service{<br \/>use generic-service<br \/>host_name Windows2<br \/>service_description SQL port Check<br \/>check_command check_tcp!1433<br \/>}<\/code><\/em><\/p>\n<p>The above config, can easily be extended for more hosts, or if necessery easily setup to track more services in nagios web frontend.<br \/><b>6. Test if connectivity to the nsclient++ agent port is available from the Linux server <\/b><\/p>\n<p><code>debian:~# telnet 192.168.58.6 12489<br \/>Trying 192.168.58.6...<br \/>Connected to 192.168.58.6.<br \/>Escape character is &#039;^]&#039;.<br \/>asd<br \/>ERROR: Invalid password.<\/code><\/p>\n<p>Another good idea is to launch on the Windows host the <b> NSClient++ (system tray) <\/b>, e.g.:<\/p>\n<p><code>Start, All Programs, NSClient++, Start NSClient++ (system tray).<\/code><\/p>\n<p>Test Nagios configuration from the Linux host running nagios and nrpe daemons to check if the <b>check_nt<\/b>, can succesfully authenticate and retrieve data generated from the nsclient++ on the Windows host:<\/p>\n<p><em><code>debian:~# \/usr\/lib\/nagios\/plugins\/check_nt -H 192.168.1.5 -p 12489 -v CPULOAD -w 80 -c 90 -l 5,80,90,10,80,90<\/code><\/em><\/p>\n<p>If everything is okay and the remote Windows system <i> 192.168.1.5 <\/i> has properly configured and running <b> NSClient++ <\/b> the above command should return an output like:<\/p>\n<p><code>CPU Load 1% (5 min average) 1% (10 min average) | &#039;5 min avg Load&#039;=1%;80;90;0;100 &#039;10 min avg Load&#039;=1%;80;90;0;100<\/code><\/p>\n<p>In case of the command returns:<\/p>\n<p><code>could not fetch information from server<\/code><\/p>\n<p>instead this means that probably there is some kind of problem with authentication or handshake of the Linux host&rsquo;s nagios <b> check_nt<\/b> to the Windows server&rsquo;s running on 12489.<\/p>\n<p>This is sometimes caused by misconfigured <b> NSC.ini <\/b> file, however in other occasions this error is caused by misconfigured Windows Firewall or because the NSClient++ is not running with Administrator user.<\/p>\n<p>By the way important note to make about Windows 2008r2 is that if <b>NSClient++<\/b> is running there it&rsquo;s absolutely required to Login with Windows Administrator and run the <i>NSClient++ \/start <\/i>, if it&rsquo;s run through the <b> Run As Adminsitrator <\/b> with an admin privileged user the aforementioned error might appear, so be careful.<br \/>I&rsquo;ve experienced this error myself and it took me about 40 minutes to find that I have to run it directly with Administrator user after logging as Administrator.<\/p>\n<p><b>7. Create nagios web iface Apache configuration <\/b><\/p>\n<p>nagios debian pachage is shipped with a config which is suitable to be set<code>debian:~# cp -rpf \/usr\/share\/doc\/nagios3-common\/examples\/apache2.conf \/etc\/apache2\/sites-avalable\/nagios<br \/><em>debian:~# ln -sf \/etc\/apache2\/sites-available\/nagios \/etc\/apache2\/sites-enabled\/nagios<\/em><\/code><\/p>\n<p>The <b> \/etc\/apache2\/sites-available\/nagios <\/b> can easily be configured to work on Virtualhost, to do so the above copied file need to be wrapped inside a VirtualHost directive. For that put in the beginning of the file;<\/p>\n<p><code>&lt;VirtualHost *:80&gt;<\/code><\/p>\n<p>and in the end of the file:<\/p>\n<p><code>&lt;VirtualHost *:80&gt;<\/code><\/p>\n<p><b>8. Restart nagios server and Apache for the new settings to take effect <\/b><\/p>\n<p><code><em>debian:~# \/etc\/init.d\/apache2 restart<\/em><br \/>...<br \/><em>debian:~# \/etc\/init.d\/nagios3 restart<\/em><\/code><\/p>\n<p>If some custom configuration about tracking the Debian Linux nagios host running services needs to be made, its also helpful for one to check in <b> \/etc\/nagios3\/conf.d<\/b><\/p>\n<p>Well that&rsquo;s mostly what I had to do to <b>make the Nagios3 server to keep track of a small Windows network on Debian GNU\/Linux Squeeze 6<\/b>, hope this small article help.<\/p>\n<p>Fonte: <a href=\"http:\/\/www.pc-freak.net\/blog\/monitoring-windows-hosts-with-nagios-on-debian-gnulinux\/\">pc-freak.net<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Install necessery nagios debian packages apt-get install nagios-images nagios-nrpe-plugin nagios-nrpe-server nagios-plugins nagios-plugins-basic nagios-plugins-standardnagios3 nagios3-cgi nagios3-common nagios3-core 2. Edit \/etc\/nagios-plugins\/config\/nt.cfg In the File substitute: define command { command_name check_nt command_line \/usr\/lib\/nagios\/plugins\/check_nt -H &#039;$HOSTADDRESS$&#039; -v &#039;$ARG1$&#039; } With: define command {command_name &hellip; <a href=\"https:\/\/blog.ffteixeira.net\/?p=117\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=117"}],"version-history":[{"count":0,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/posts\/117\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}