Monitoring NixOS with SNMP in Nagios XI: A Step-by-Step Guide


NixOS is a distinctive Linux distribution focused on reproducibility and declarative configuration, utilizing the Nix package manager. Unlike traditional distributions, NixOS doesn’t follow conventional package management workflows, but it supports SNMP (Simple Network Management Protocol) for agentless monitoring. This guide details installing SNMP on NixOS, configuring SNMP v2c or v3, and integrating it with Nagios XI for real-time monitoring of system metrics like CPU, memory, disk, and network usage as of March 2025.
Prerequisites
Ensure:
- A NixOS system (updated with
sudo nix-channel --update && sudo nixos-rebuild switch
) withsudo
or root access. - A running Nagios XI instance (latest version recommended).
- Network connectivity between NixOS and Nagios XI (UDP port 161 open).
- Access to edit
/etc/nixos/configuration.nix
.
Step 1: Install SNMP Packages
Option 1: Imperative Installation (For Testing)
nix-env -iA nixos.net-snmp
Verify:
snmpd --version
Option 2: Declarative Installation (Recommended)
Add to /etc/nixos/configuration.nix
:
environment.systemPackages = with pkgs; [ net-snmp ];
Apply changes:
sudo nixos-rebuild switch
Verify:
/run/current-system/sw/bin/snmpd --version
Step 2: Configure SNMP Access
Option 1: SNMP v2c
sudo mkdir -p /etc/snmp
sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.bak 2>/dev/null || true
echo "rocommunity Str0ngC0mmunity <Nagios-XI-IP>" | sudo tee /etc/snmp/snmpd.conf
Replace <Nagios-XI-IP>
with your Nagios XI server IP (e.g., 10.25.5.12
).
Option 2: SNMP v3 (Secure)
sudo systemctl stop snmpd.service
sudo net-snmp-create-v3-user -ro -a SHA -A Str0ng@uth3ntic@ti0n -x AES -X Str0ngPriv@cy nagios
sudo mkdir -p /etc/snmp
echo "rouser nagios authPriv" | sudo tee /etc/snmp/snmpd.conf
Step 3: Configure Firewall
Declarative Method (Recommended)
Add to /etc/nixos/configuration.nix
:
networking.firewall.allowedUDPPorts = [ 161 ];
Apply changes:
sudo nixos-rebuild switch
Verify:
sudo iptables -L -n | grep 161
Imperative Method (Temporary)
sudo iptables -I INPUT -p udp --dport 161 -j ACCEPT
sudo mkdir -p /etc/iptables
sudo iptables-save > /etc/iptables/rules.v4
Step 4: Enable SNMP Daemon on Boot
Add to /etc/nixos/configuration.nix
:
systemd.services.snmpd = {
description = "SNMP Daemon";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.net-snmp}/bin/snmpd -c /etc/snmp/snmpd.conf";
Restart = "on-failure";
};
};
Apply changes:
sudo nixos-rebuild switch
Verify:
sudo systemctl status snmpd.service
Step 5: Test SNMP Communication
Install SNMP tools on Nagios XI (if needed):
sudo dnf install net-snmp-utils -y
SNMP v2c
snmpwalk -v2c -c Str0ngC0mmunity <NixOS-IP>
SNMP v3
snmpwalk -v3 -u nagios -l authPriv -a SHA -A Str0ng@uth3ntic@ti0n -x AES -X Str0ngPriv@cy <NixOS-IP>
Expected output:
iso.3.6.1.2.1.1.1.0 = STRING: "Linux nixos-<hostname> <version> x86_64"
Step 6: Add Host to Nagios XI Using SNMP Wizard
- Log into Nagios XI
- Navigate to Configure > Configuration Wizards
- Select Linux SNMP
- Configure Host:
- IP:
192.168.0.31
- SNMP Version:
v2c
orv3
- v2c Community:
Str0ngC0mmunity
- v3 Username:
nagios
, Auth Protocol:SHA
, Auth Password:Str0ng@uth3ntic@ti0n
, Privacy Protocol:AES
, Privacy Password:Str0ngPriv@cy
- IP:
- Click Next, select metrics (CPU, memory, disk, etc.)
- Click Finish and apply
- Verify monitoring in Monitoring > Hosts
Troubleshooting
SNMP Not Responding
sudo systemctl status snmpd
ps aux | grep snmpd
sudo systemctl restart snmpd
Firewall Issue
sudo iptables -L -n
sudo nc -zu <NixOS-IP> 161
Log SNMP Output
sudo /run/current-system/sw/bin/snmpd -f -Lo -c /etc/snmp/snmpd.conf
Conclusion
You’ve configured SNMP on NixOS and integrated it with Nagios XI for agentless, real-time monitoring as of March 28, 2025. NixOS’s declarative nature requires explicit setup for SNMP, but this approach ensures reliability. For long-term stability, maintain all configurations (packages, firewall, services) in /etc/nixos/configuration.nix
. Explore further customization in the Nagios SNMP Guide, Net-SNMP Documentation, or NixOS Manual.
Share:
On this page
Related Articles
- Centralized Log Monitoring for AlmaLinux 9 with Nagios Log Server 2024R2: A Complete Guide
- Monitoring Pop!_OS 24.04 LTS with NCPA in Nagios XI: A Comprehensive Guide
- Monitoring Clear Linux with SNMP in Nagios XI: A Step-by-Step Guide
- How to Send Logs from Kali Linux to Nagios Log Server
- How to Configure SNMP on Kali Linux for Nagios XI