A Guide to Monitoring Servers/Services with Nagios — Part 2

Kelom
5 min readAug 27, 2020

--

(ADDING A REMOTE WINDOWS BOX TO NAGIOS SERVER)

In part 1 of this series(read it here), we installed and configured the Nagios server. In this article, we will go a step further and add a Windows host to the Nagios Core server for monitoring.

Step 1: we will start by downloading and installing nsclient++ from https://nsclient.org/download/0.5.2/#0.5.2.39

Enter the IP address of the Nagios Core server in the Allowed hosts box
And Enter a password in the Password box (for the purpose of this demo/article we wouldn’t enter any password)

Step 2: We will add the windows box by adding an entry to the windows.cfg file located at (on the Nagios server): /usr/local/nagios/etc/objects.

vi /usr/local/nagios/etc/objects/windows.cfg
define host {
use windows-server
host_name winserver
alias winserver
address 192.168.0.103
notification_interval 1
notification_options d,u,r,f,s
check_interval 1
retry_interval 1
contact_groups admins
notifications_enabled 1
notification_period 24x7
}

By default, Nagios comes with the following windows services enabled (/usr/local/nagios/etc/objects/windows.cfg), you can also add any service you wish to monitor (for the purpose of this article we will stick with these default services):

define service {
use generic-service
host_name winserver
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
define service {
use generic-service
host_name winserver
service_description Uptime
check_command check_nt!UPTIME
}
define service {
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service {
use generic-service
host_name winserver
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
vi /usr/local/nagios/etc/objects/windows.cfg

After you are done, save the changes and exit.

Explanation of the various parameters:

host_name = A short name used to identify the host
notification_interval = the number of “time units” to wait before re-notifying a contact that this service is still down or unreachable. This value is in minutes
notification_options = Used to determine when notifications for the host should be sent out. Valid options are a combination of one or more of the following: d = send notifications on a DOWN state, u = send notifications on an UNREACHABLE state, r = send notifications on recoveries (OK state), f = send notifications when the host starts and stops flapping, and s = send notifications when scheduled downtime starts and ends
check_interval = Used to define the number of “time units” to wait before scheduling the next “regular” check of the service. “Regular” checks are those that occur when the service is in an OK state or when the service is in a non-OK state, but has already been rechecked max_check_attempts number of times
retry_interval = used to define the number of “time units” to wait before scheduling a re-check of the service
contact_groups = This is a list of the short names of the contact groups that should be notified whenever there are problems (or recoveries) with this service. Multiple contact groups should be separated by commas
notifications_enabled = used to determine whether or not notifications for a host or service are enabled. Values: 0 = disable host notifications, 1 = enable host notifications.
notification_period = used to specify the short name of the time period during which notifications of events for this service can be sent out to contacts. No service notifications will be sent out during times which is not covered by the time period

For more info read the doc: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/objectdefinitions.html

Step 3: Next, still on the Nagios server, open nagios.cfg located at: /usr/local/nagios/etc/

vi /usr/local/nagios/etc/nagios.cfg

Uncomment the line below by removing the # sign and save the changes.

cfg_file=/usr/local/nagios/etc/objects/windows.cfg

Step 4: Restart the Nagios service

systemctl restart nagios.service

Step 5: Modify the nsclient.ini file located at C:\Program Files\NSClient++

; Undocumented section
[/settings/default]
; PASSWORD - Password used to authenticate against server
;password = time
; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.allowed hosts = 192.168.0.11
port = 12489
; Undocumented section[/modules]; CheckSystem - Various system related checks, such as CPU load, process state, service state memory usage and PDH counters.CheckSystem = 1; NSClientServer - A server that listens for incoming check_nt connection and processes incoming requests.NSClientServer = 1; CheckExternalScripts - Execute external scriptsCheckExternalScripts = 1; CheckHelpers - Various helper function to extend other checks.CheckHelpers = 1; CheckEventLog - Check for errors and warnings in the event log.CheckEventLog = 1; CheckDisk - CheckDisk can check various file and disk related things.CheckDisk = 1; CheckNSCP - Use this module to check the healt and status of NSClient++ it selfCheckNSCP = 1; NRPEServer - A server that listens for incoming NRPE connection and processes incoming requests.NRPEServer = 1; Undocumented section[/modules]; Undocumented keyCheckExternalScripts = 1; Undocumented keyCheckHelpers = 1; Undocumented keyCheckEventLog = 1; Undocumented keyCheckNSCP = 1; Undocumented keyCheckDisk = 1; Undocumented keyCheckSystem = 1; Undocumented keyNSClientServer = 1; Undocumented keyNRPEServer = 1

Step 6: Allow port 12489 through the windows firewall

Step 7: restart the NSClient++ Monitoring Agent service

We have successfully configured the windows box to be monitored by the Nagios server.

login to the nagios web interface by using the ip address of the nagios server followed by /nagios, mine is: http://192.168.20.131/nagios/

You should see the status of the windows server on Nagios

Read: Part 3 - Add Linux box with MySQL database and monitor the MySQL database.

--

--