[Day 5] 8. Monitoring a Remote Linux Machine using Nagios
Overview
Goal:
Set up Nagios to monitor a remote Linux machine using NCPA (Nagios Cross-Platform Agent).
Setup:
- Nagios Server: The machine where Nagios is installed.
- Client Machine: The Linux system you want to monitor remotely.
Pre-requisite: Before proceeding, ensure the following:
-
Nagios Server Configuration:
If your Nagios server is not yet configured, refer to Day 3, File 6 and 7 for detailed setup instructions. -
Changes from Day 4, File 4:
Apply only the Nagios Server-specific changes mentioned in the file. Ignore the configurations related to monitoring a Windows machine.
Steps
1. Install Dependencies on the Client Machine
Run the following command to install required dependencies on the Client Machine:
bashsudo apt-get install wget libsqlite3-0
2. Install NCPA on the Client Machine
-
Download the NCPA Package:
Download the latest NCPA .deb file for your system. -
Install NCPA:
Use thecommand to install it:dpkgbashsudo dpkg -i ncpa-latest-1.amd64.debhere
stands for installation.-i
3. Configure NCPA on the Client Machine
-
Edit the Configuration File:
Open thefile to set the community string (password):ncpa.cfgbashsudo vim /usr/local/ncpa/etc/ncpa.cfgSearch for
and set your password:community_stringplaintextcommunity_string = <your_token> -
Restart the NCPA Service:
bashsudo systemctl restart ncpa sudo systemctl status ncpa
4. Test Connectivity Between Nagios Server and Client
-
On the Nagios server, navigate to the
directory:libexecbashcd /usr/local/nagios/libexec/ -
Test the connection with the client machine:
bashsudo ./check_ncpa.py -t <your_token> -H <linux_machine_ip> -M system/agent_version- Replace with the password you configured in
<your_token>.ncpa.cfg - Replace with the IP address of the client machine.
<linux_machine_ip> - If successful, this command will return the agent version.
- Replace
5. Configure Nagios to Monitor the Client
-
Navigate to the Nagios configuration directory:
bashcd /usr/local/nagios/etc/servers -
Create a configuration file for the client (e.g.,
):deb_12-1.cfgbashsudo vim deb_12-1.cfg -
Add the following content to the file:
plaintextdefine host { use linux-server host_name deb_12-1 alias Debian 12 Sys 1 address <linux_machine_ip> max_check_attempts 5 } define service { use generic-service host_name deb_12-1 service_description Agent Version check_command check_ncpa!-t '<your_token>' -p -P 5693 -M system/agent_version } define service { use generic-service host_name deb_12-1 service_description Virtual Memory check_command check_ncpa!-t '<your_token>' -p -P 5693 -M memory/virtual -w 50 -c 80 -u G }- Replace with the client machine's IP address.
<linux_machine_ip> - Replace with the password you set earlier.
<your_token>
- Replace
6. Restart Nagios
Restart the Nagios service to load the new configuration:
bashsudo systemctl restart nagios
sudo systemctl status nagios
7. Access the Nagios Web Interface
Open a browser and navigate to:
plaintexthttp://<nagios_server_ip>/nagios
- Replace with the IP address of the Nagios server.
<nagios_server_ip> - Log in with your Nagios credentials to view the monitoring status.
Expected Output
- Agent Version: Displays the version of the NCPA agent installed on the client.
- Virtual Memory: Shows the current virtual memory usage with warning () and critical (
-w) thresholds set at 50% and 80%, respectively.-c
Troubleshooting
- NCPA Connectivity Issues:
-
Verify the NCPA service is running on the client:
bashsudo systemctl status ncpa -
Ensure the Nagios server can reach the client machine on port 5693 (default NCPA port).
-
- Invalid Token or IP:
- Double-check the in
community_stringand ensure it matches the token in the Nagios configuration.ncpa.cfg - Verify the client machine's IP address.
- Double-check the
Read Next
[Day 5] 9. Extra
#### **1. What is an Application Proxy?** An **Application Proxy** acts as an intermediary between the client and the server, facilitating secure c...
[Day 6] 1. Firewall and its Types
A **Firewall** is a unit (hardware, software, or a combination of both) used to control network traffic. It allows authorized traffic and blocks unaut...