How-to: Monitor Windows with Nagios
To add a Windows PC/server to the Nagios networking monitoring system there are a few options. In this article are instructions for a solution using a NCPA client on the Windows machine with an NCPA integration and config files on the Nagios Core machine
On Windows
Firstly, download, install and configure the NCPA client on the Windows machine.
Download from the Nagios website here
Run the installer once downloaded, by double-clicking on it
The only item of configuration required is to provide an API key. All other fields can be left at their defaults. The API key should be selected by you – it’s simply a unique identifier for this installation and also acts as the ‘password’ for gaining access to the GUI once the client is installed. One thing I did discover is that some special characters cause issues when passing data between the Nagios Core system and the NCPA listener via its API – I had to remove a ‘$’ symbol to make it work. Make sure you remember or note down the key you choose. In the example below you’ll see <<API_key>> – change this to something unique for your installation and use it in the installation on Windows and in replacement of each <<API_key>> below.
Finally, test that the installation was successful by opening a browser on the Windows machine and navigating to:
https://localhost:5693/gui/
Log in by providing the API key you chose earlier. If you get a page displayed then the client is running. It’s worth also opening the Live Data page to see that the client is retrieving at least some data.
On the Nagios Core machine
Next, on the Nagios Core machine (for which instructions for installation on a Raspberry Pi can be found here, and Basic configuration instructions here), download, install and configure NCPA:
cd /tmp
wget https://assets.nagios.com/downloads/ncpa/check_ncpa.tar.gz
tar xvf check_ncpa.tar.gz
sudo chown nagios:nagios check_ncpa.py
sudo chmod 775 check_ncpa.py
sudo mv check_ncpa.py /usr/local/nagios/libexec
Then edit the Nagios commands config file to make use of the newly-installed components:
sudo nano /usr/local/nagios/etc/objects/commands.cfg
adding the following:
define command {
command_name check_ncpa
command_line $USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$
}
It’s not a bad idea to restart Nagios at this point – if it fails to start with only the above change then it’s easier to identify that an error is within that task:
sudo systemctl restart nagios
Next create a new config file in the objects folder (we’ll call it cctv.cfg to monitor a CCTV server running on Windows):
sudo nano /usr/local/nagios/etc/objects/cctv.cfg
into the new, blank file add the following:
define host {
host_name CCTV Server
address <<ip_address_of_windows_machine>>
check_command check_ncpa!-t ‘<<API_key>>’ -P 5693 -M system/agent_version
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24×7
contacts nagiosadmin
notification_interval 60
notification_period 24×7
notifications_enabled 1
icon_image ncpa.png
statusmap_image ncpa.png
register 1
}
define service {
host_name CCTV Server
service_description CPU Usage
check_command check_ncpa!-t ‘<<API_key>>’ -P 5693 -M cpu/percent -w 50 -c 70 -q ‘aggregate=avg’
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24×7
notification_interval 60
notification_period 24×7
contacts nagiosadmin
register 1
}
define service {
host_name CCTV Server
service_description Memory Usage
check_command check_ncpa!-t ‘<<API_key>>’ -P 5693 -M memory/virtual -w 50 -c 70 -u G
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24×7
notification_interval 60
notification_period 24×7
contacts nagiosadmin
register 1
}
define service {
host_name CCTV Server
service_description Process Count
check_command check_ncpa!-t ‘<<API_key>>’ -P 5693 -M processes -w 200 -c 250
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24×7
notification_interval 60
notification_period 24×7
contacts nagiosadmin
register 1
}
define service {
host_name CCTV Server
service_description Disk Usage C:
check_command check_ncpa!-t ‘<<API_key>>’ -P 5693 -M ‘disk/logical/C:|/used_percent’ –warning 50 –critical 70 –units Gi
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24×7
notification_interval 60
notification_period 24×7
contacts nagiosadmin
register 1
}
Finally, to include the above config file within the Nagios environment, reference it from the nagios.cfg file:
sudo nano /usr/local/nagios/etc/nagios.cfg
adding a line as follows:
cfg_file=/usr/local/nagios/etc/objects/cctv.cfg
Restart the Nagios service:
sudo systemctl restart nagios
And, if all is well, you should see the newly-monitored host and services in the Nagios console
Clearly, many options in the config above can be altered to suit your needs and there are also many other check_commands that can offer access to alternative monitoring metrics. The above provides a summary of, and alerting at thresholds related to, disk usage (C:), running processes, memory usage, processor time and host state. More info on those and other options can be found at https://www.nagios.org/ncpa/help.php