[Day 4] 4. Remote Machine Monitoring (Nagios)
NCPA Plugin
To monitor a remote machine (Windows), we'll use the Nagios plugin NCPA (Nagios Cross Platform Agent) in a Windows VM, which helps keep your base Windows machine clean. Keep the Windows VM in NAT mode.
Steps for Installation:
Do this in Windows Machine:
-
Install NCPA Plugin:
- Install the NCPA plugin using the setup file provided by your Manu Sir.
- Go through the installation steps (Next, Next).
- When asked, set a token (password) for the installation.
- Keep the default port 5693.
- Finish the installation.
-
Check Windows Virtual Machine Details:
- Find the IP address of the Windows virtual machine (for example: ).
192.168.80.133 - Ensure the firewall is turned off. If it's on, turn it off.
- Find the IP address of the Windows virtual machine (for example:
-
Access NCPA from Browser:
- On your base Windows machine, open a browser.
- In the browser, visit (use the Windows Virtual machine's IP address). Please note that this is
https://192.168.80.133:5693and nothttps.http - Enter the necessary information, and you should be able to view the machine's statistics.
Troubleshooting Steps (If Problems Occur)
- Check the Firewall: Ensure the firewall is not blocking the connection.
- Check NCPA Service: Press , type
Windows + R, and ensure theservices.mscservice is running.ncpa - Verify URL: Double-check the URL for accuracy.
Next Steps for Plugin Communication:
-
Download the Plugin:
shellwget http://192.168.0.52/sw/security_tools/nagios/check_ncpa.tar.gz -
Extract the Plugin:
shelltar -zxf check_ncpa.tar.gz -
Copy the Plugin:
shellsudo cp check_ncpa.py /usr/local/nagios/libexec/ -
Check Permissions:
- Verify that has executable permissions.
check_ncpa.py
- Verify that
-
Edit the Shebang Line:
- Open and change the shebang to:
check_ncpa.py
#!/usr/bin/env python3
- Open
-
Check Plugin Version:
bashcd /usr/local/nagios/libexec/ sudo ./check_ncpa.py -V -
Plugin Communication:
bashsudo ./check_ncpa.py -t <your_token> -H <windows_vm_ip> -M memory/virtual- : Token (password)
-t - : Host IP address (IP of machine you want to monitor)
-H - : Metric to monitor (e.g., memory/virtual)
-M
-
Edit Configuration File:
-
Navigate to
./usr/local/nagios/etc/objects -
Open
and define the plugin:commands.cfgbashdefine command { command_name check_ncpa command_line $USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$ }
-
-
Configure Nagios to Monitor the Machine:
-
Edit
and uncomment this line/usr/local/nagios/etc/nagios.cfg. (line 51)cfg_dir=/usr/local/nagios/etc/servers -
Create a directory
underservers./usr/local/nagios/etc/ -
Create a new file
insidewin_10_1.cfgwith the following content:/serversplaintextdefine host{ use windows-server host_name win-10_1 alias Windows 10 System 1 address <windows_server_ip> max_check_attempts 5 } define service{ use generic-service host_name win-10_1 service_description NCPA Agent Version check_command check_ncpa!-t '<your_token>' -p -P 5693 -M system/agent_version } define service{ use generic-service host_name win-10_1 service_description CPU Average check_command check_ncpa!-t '<your_token>' -p -P 5693 -M cpu/percent -w 20 -c 40 -q 'aggregate=avg' }Comment out the line
in thehostgroups windows-serversfile fromtemplates.cfgbecause the Nagios developers included this reference but did not define the corresponding host group./usr/local/nagios/etc/objects
-
-
Restart and check status of Nagios:
bashsudo systemctl restart nagios sudo systemctl status nagios -
Monitoring the Status: Open any browser in your host machine:
http://<nagios_server_ip>/nagios
Explanation of Configuration Details:
-
Templates:
- and
windows-serverare predefined templates in Nagios (found ingeneric-service).templates.cfg - These templates define the structure of services and hosts.
-
Check Command Explanation:
- is the function you defined in
check_ncpa.commands.cfg - : Token/password for authentication.
-t - : Port number (5693). This is default port used by NCPA.
-p - : Metric to monitor (e.g., CPU or memory).
-M - : Warning threshold (percentage).
-w - : Critical threshold (percentage).
-c - : Query parameter (e.g., 'aggregate=avg').
-q
Read Next
[Day 4] 5. Reverse Proxy Setup with Nginx and Apache
In this setup, we'll use **Nginx** as a reverse proxy in front of an **Apache** server. The flow looks like this: **Client** → **Nginx** → **Apache...
[Day 4] 6. SQUID
For this setup, we need to configure **Squid** as a reverse proxy. Follow the steps below: **Important:** SQUID runs on port **3128** by default....