Set up network monitoring with Nagios Core 4.5 and SNMP for infrastructure alerting

Intermediate 45 min Apr 12, 2026 244 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Configure Nagios Core 4.5 with SNMP monitoring to track network devices, servers, and services with automated alerting. Set up custom monitoring templates, notification systems, and dashboards for comprehensive infrastructure visibility.

Prerequisites

  • Root or sudo access
  • At least 2GB RAM
  • SNMP-enabled network devices
  • Email server for notifications

What this solves

Network infrastructure monitoring requires real-time visibility into device health, performance metrics, and service availability. Nagios Core 4.5 with SNMP integration provides comprehensive monitoring for routers, switches, servers, and applications with customizable alerting and reporting capabilities.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions and security patches.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install build dependencies

Install the required development tools and libraries needed to compile Nagios Core from source.

sudo apt install -y build-essential gcc glibc-dev make unzip apache2 apache2-utils php libapache2-mod-php7.4 libgd-dev libssl-dev autoconf automake libtool openssl libssl-dev
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y httpd httpd-tools php php-cli gcc glibc-devel make unzip gd-devel openssl-devel automake autoconf libtool

Install SNMP tools and libraries

Install SNMP utilities and development libraries for network device monitoring capabilities.

sudo apt install -y snmp snmp-mibs-downloader libsnmp-dev
sudo dnf install -y net-snmp net-snmp-utils net-snmp-devel

Create nagios user and group

Create dedicated system accounts for Nagios with proper permissions for security isolation.

sudo groupadd nagios
sudo useradd -g nagios -d /usr/local/nagios -s /bin/bash nagios
sudo usermod -a -G nagios www-data

Download and compile Nagios Core 4.5

Download the Nagios Core 4.5 source code and compile it with SNMP support enabled.

cd /tmp
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.5.0.tar.gz
tar -xzf nagios-4.5.0.tar.gz
cd nagioscore-nagios-4.5.0

Configure and compile Nagios

Configure the build with appropriate options and compile the Nagios Core binary.

sudo ./configure --with-nagios-group=nagios --with-command-group=nagios --with-httpd-conf=/etc/apache2/sites-available --with-lockfile=/var/run/nagios.lock
sudo make all

Install Nagios binaries and configuration

Install the compiled Nagios binaries, configuration files, and web interface components.

sudo make install
sudo make install-commandmode
sudo make install-config
sudo make install-webconf

Download and install Nagios plugins

Install the standard Nagios plugins that provide monitoring checks for various services and systems.

cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.0.tar.gz
tar -xzf release-2.4.0.tar.gz
cd nagios-plugins-release-2.4.0
sudo ./tools/setup
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make && sudo make install

Configure Apache web server

Enable required Apache modules and configure the web interface for Nagios access.

sudo a2enmod cgi rewrite
sudo a2ensite nagios
sudo systemctl restart apache2
sudo systemctl enable --now httpd
sudo cp /etc/httpd/conf.d/nagios.conf.example /etc/httpd/conf.d/nagios.conf
sudo systemctl restart httpd

Create Nagios web interface user

Create an administrative user account for accessing the Nagios web interface with authentication.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Note: Enter a strong password when prompted. This account will have full administrative access to Nagios.

Set correct file permissions

Configure proper ownership and permissions for Nagios files and directories for security.

sudo chown -R nagios:nagios /usr/local/nagios/
sudo chmod 755 /usr/local/nagios/etc
sudo chmod 644 /usr/local/nagios/etc/*.cfg
sudo chmod 755 /usr/local/nagios/var
Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions.

Configure SNMP community settings

Set up SNMP community strings and access permissions for network device monitoring.

# Disable loading of all MIBs by default
mibs :

Add your custom community string

defCommunity public

Create systemd service file

Create a systemd service file to manage Nagios as a system service with automatic startup.

[Unit]
Description=Nagios Core 4.5
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
ExecReload=/bin/kill -HUP $MAINPID
User=nagios
Group=nagios

[Install]
WantedBy=multi-user.target

Configure SNMP monitoring

Create SNMP host template

Define a reusable host template for SNMP-enabled network devices with common monitoring parameters.

# Add to existing templates.cfg
define host{
    name                    snmp-device
    use                     generic-host
    check_command           check-host-alive
    max_check_attempts      3
    check_interval          5
    retry_interval          1
    check_period            24x7
    contact_groups          admins
    notification_interval   30
    notification_period     24x7
    register                0
}

Configure SNMP commands

Define SNMP monitoring commands for checking device status, interface utilization, and system resources.

# Add SNMP monitoring commands
define command{
    command_name    check_snmp_interface
    command_line    /usr/local/nagios/libexec/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o $ARG2$ -w $ARG3$ -c $ARG4$
}

define command{
    command_name    check_snmp_cpu
    command_line    /usr/local/nagios/libexec/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o 1.3.6.1.4.1.2021.11.9.0 -w $ARG2$ -c $ARG3$
}

define command{
    command_name    check_snmp_memory
    command_line    /usr/local/nagios/libexec/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o 1.3.6.1.4.1.2021.4.6.0 -w $ARG2$ -c $ARG3$
}

Create network device configuration

Configure monitoring for specific network devices like switches and routers using SNMP.

# Network switch monitoring
define host{
    use                     snmp-device
    host_name              core-switch-01
    alias                  Core Network Switch 01
    address                203.0.113.10
    contact_groups         admins
}

define service{
    use                     generic-service
    host_name              core-switch-01
    service_description    Interface eth0/1 Status
    check_command          check_snmp_interface!public!1.3.6.1.2.1.2.2.1.8.1!1!1
}

define service{
    use                     generic-service
    host_name              core-switch-01
    service_description    CPU Utilization
    check_command          check_snmp_cpu!public!80!90
}

Set up alerting and notifications

Configure email notifications

Set up email alerting for critical infrastructure events and service failures.

sudo apt install -y mailutils postfix
sudo dnf install -y mailx postfix

Configure contact definitions

Define contact groups and notification methods for different types of alerts and escalation levels.

define contact{
    contact_name                    admin
    use                            generic-contact
    alias                          System Administrator
    email                          admin@example.com
    host_notifications_enabled     1
    service_notifications_enabled  1
    host_notification_period       24x7
    service_notification_period    24x7
    host_notification_options      d,u,r,f,s
    service_notification_options   w,u,c,r,f,s
}

define contactgroup{
    contactgroup_name       network-admins
    alias                   Network Administrators
    members                 admin
}

Configure notification commands

Set up email notification commands for host and service alerts with detailed information.

# Add notification commands
define command{
    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" " Nagios \n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s " $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ " $CONTACTEMAIL$
}

define command{
    command_name    notify-service-by-email
    command_line    /usr/bin/printf "%b" " Nagios \n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s " $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ " $CONTACTEMAIL$
}

Enable and start Nagios service

Enable the Nagios service for automatic startup and verify the configuration before starting.

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
sudo systemctl daemon-reload
sudo systemctl enable --now nagios
sudo systemctl status nagios

Create monitoring dashboards

Configure service groups

Organize monitored services into logical groups for easier dashboard navigation and reporting.

define servicegroup{
    servicegroup_name       network-services
    alias                   Network Infrastructure Services
    members                 core-switch-01,Interface eth0/1 Status,core-switch-01,CPU Utilization
}

define servicegroup{
    servicegroup_name       system-resources
    alias                   System Resource Monitoring
    members                 localhost,CPU Load,localhost,Memory Usage
}

Configure host groups

Group hosts by function or location for organized monitoring views and bulk operations.

define hostgroup{
    hostgroup_name          network-devices
    alias                   Network Infrastructure
    members                 core-switch-01
}

define hostgroup{
    hostgroup_name          linux-servers
    alias                   Linux Servers
    members                 localhost
}

Configure performance data collection

Enable performance data collection for trending and capacity planning analysis.

# Enable performance data processing
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
host_perfdata_file=/usr/local/nagios/var/host-perfdata
service_perfdata_file=/usr/local/nagios/var/service-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$

Verify your setup

Test your Nagios installation and SNMP monitoring configuration to ensure everything works correctly.

# Verify Nagios configuration syntax
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Check service status

sudo systemctl status nagios sudo systemctl status apache2 # or httpd on RHEL-based systems

Test SNMP connectivity to a device

snmpwalk -v2c -c public 203.0.113.10 1.3.6.1.2.1.1.1.0

Verify web interface access

curl -I http://localhost/nagios/

Access the Nagios web interface at http://your-server-ip/nagios/ and log in with the nagiosadmin credentials you created. You should see the main dashboard with host and service monitoring status.

Common issues

SymptomCauseFix
Apache 403 Forbidden errorIncorrect file permissionssudo chown -R nagios:www-data /usr/local/nagios
SNMP timeout errorsFirewall blocking SNMP portOpen UDP port 161: sudo ufw allow 161/udp
Nagios service won't startConfiguration syntax errorCheck config: sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Email notifications not workingPostfix not configuredConfigure postfix: sudo dpkg-reconfigure postfix
Performance data not collectedPerfdata processing disabledEnable in nagios.cfg: process_performance_data=1
Web interface shows no dataNagios service not runningStart service: sudo systemctl start nagios

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.