How to Monitor Ubuntu 20.04 Using SNMP in Nagios XI


Monitoring Ubuntu 20.04 using SNMP (Simple Network Management Protocol) in Nagios XI provides an agentless monitoring solution for tracking critical system metrics such as CPU load, disk usage, and running processes. SNMP is lightweight and widely used but requires proper configuration for security and performance. This guide will walk you through setting up SNMP and integrating it with Nagios XI.
Prerequisites
Before proceeding, ensure you have:
- An Ubuntu 20.04 system with root or sudo access.
- A Nagios XI server with SNMP monitoring enabled.
- A valid SNMP community string (for SNMP v2c) or a secure SNMPv3 user.
- Open UDP port 161 for SNMP traffic.
Step 1: Install SNMP on Ubuntu 20.04
Update your package list and install the SNMP daemon:
sudo apt-get update
sudo apt-get install snmpd libsnmp-dev -y
Step 2: Configure SNMP v2c
1. Backup the default configuration:
sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.bak
2. Replace it with a new configuration:
sudo sh -c "echo 'rocommunity Str0ngC0mmunity <Nagios-XI-IP> default' > /etc/snmp/snmpd.conf"
Replace <Nagios-XI-IP>
with the actual IP address of your Nagios XI server.
3. Restart the SNMP service:
sudo systemctl restart snmpd.service
4. Verify that SNMP is running:
sudo systemctl status snmpd
:small_blue_diamond: Security Note: SNMP v2c does not support encryption. For better security, use SNMP v3, which includes authentication and encryption.
Step 3: Configure Firewall
To allow SNMP traffic through UFW (Uncomplicated Firewall), run:
sudo ufw allow 161/udp
sudo ufw reload
sudo ufw status | grep 161
Step 4: Enable SNMP on Boot
Ensure SNMP starts automatically after reboots:
sudo systemctl enable snmpd.service
Step 5: Test SNMP Communication
From your Nagios XI server, test if SNMP is responding:
snmpwalk -v2c -c Str0ngC0mmunity <Ubuntu-IP> system
Expected output:
SNMPv2-MIB::sysDescr.0 = STRING: Linux ubuntu20 5.4.0-91-generic x86_64
:small_blue_diamond: Troubleshooting: If SNMP doesn’t respond, check logs:
sudo journalctl -u snmpd --no-pager | tail -20
Step 6: Integrate SNMP with Nagios XI
- Log in to Nagios XI.
- Go to Configure > Run a Configuration Wizard > Linux SNMP.
- Enter the Ubuntu IP and SNMP community string (
Str0ngC0mmunity
). - Select SNMP v2c or SNMP v3 (recommended for security).
- Choose the metrics you want to monitor (CPU, disk, processes, etc.).
- Set warning/critical thresholds.
- Finish the wizard and apply the configuration.
Troubleshooting & Common Issues
1. SNMP Service Not Responding
- Check if SNMP is running:
sudo systemctl status snmpd
- Restart if needed:
sudo systemctl restart snmpd
2. SNMP Query Fails from Nagios XI
- Ensure port 161/UDP is open:
sudo netstat -tulnp | grep 161
- If SNMP is not listening, restart the service.
3. Incorrect Community String
- Verify the correct community string in
/etc/snmp/snmpd.conf
:
cat /etc/snmp/snmpd.conf | grep rocommunity
4. Test from Nagios XI Server Run an SNMP check:
cd /usr/local/nagios/libexec
./check_snmp_storage.pl -H <Ubuntu-IP> -C Str0ngC0mmunity -m "^/$" -w 80 -c 90
This checks disk usage, warning at 80% and critical at 90%.
Final Notes
- SNMP v2c is simple but lacks encryption. Use SNMP v3 for secure monitoring.
- Ensure port 161/UDP is open between Nagios XI and Ubuntu.
- Test SNMP connectivity before integrating with Nagios XI.
- For advanced monitoring, configure SNMP traps for event-based alerts.