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
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
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
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
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
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
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
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
| Symptom | Cause | Fix |
|---|---|---|
| Apache 403 Forbidden error | Incorrect file permissions | sudo chown -R nagios:www-data /usr/local/nagios |
| SNMP timeout errors | Firewall blocking SNMP port | Open UDP port 161: sudo ufw allow 161/udp |
| Nagios service won't start | Configuration syntax error | Check config: sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |
| Email notifications not working | Postfix not configured | Configure postfix: sudo dpkg-reconfigure postfix |
| Performance data not collected | Perfdata processing disabled | Enable in nagios.cfg: process_performance_data=1 |
| Web interface shows no data | Nagios service not running | Start service: sudo systemctl start nagios |
Next steps
- Integrate Nagios Core 4.5 with Grafana dashboards for advanced monitoring visualization
- Implement SNMP device auto-discovery with network scanning and automated inventory management
- Configure network monitoring with SNMP and Grafana dashboards for infrastructure visibility
- Set up Nagios high availability cluster with failover and load balancing
- Configure Nagios custom plugins development for specialized monitoring requirements
Automated install script
Run this to automate the entire setup
#!/usr/bin/env bash
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Default values
NAGIOS_USER="nagios"
NAGIOS_GROUP="nagios"
NAGIOS_HOME="/usr/local/nagios"
WEB_USER=""
# Usage function
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Install Nagios Core 4.5 with SNMP monitoring"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 1
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
usage
;;
esac
done
# Error handler
cleanup() {
echo -e "${RED}Installation failed! Cleaning up...${NC}"
systemctl stop nagios 2>/dev/null || true
systemctl stop httpd 2>/dev/null || true
systemctl stop apache2 2>/dev/null || true
userdel -r $NAGIOS_USER 2>/dev/null || true
groupdel $NAGIOS_GROUP 2>/dev/null || true
rm -rf $NAGIOS_HOME 2>/dev/null || true
echo -e "${YELLOW}Cleanup completed${NC}"
}
trap cleanup ERR
# Check if running as root or with sudo
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}This script must be run as root or with sudo${NC}"
exit 1
fi
# Detect distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu|debian)
PKG_MGR="apt"
PKG_INSTALL="apt install -y"
PKG_UPDATE="apt update && apt upgrade -y"
WEB_SERVICE="apache2"
WEB_USER="www-data"
WEB_CONF_DIR="/etc/apache2/sites-available"
HTPASSWD_PATH="/usr/local/nagios/etc/htpasswd.users"
;;
almalinux|rocky|centos|rhel|ol|fedora)
PKG_MGR="dnf"
PKG_INSTALL="dnf install -y"
PKG_UPDATE="dnf update -y"
WEB_SERVICE="httpd"
WEB_USER="apache"
WEB_CONF_DIR="/etc/httpd/conf.d"
HTPASSWD_PATH="/usr/local/nagios/etc/htpasswd.users"
;;
amzn)
PKG_MGR="yum"
PKG_INSTALL="yum install -y"
PKG_UPDATE="yum update -y"
WEB_SERVICE="httpd"
WEB_USER="apache"
WEB_CONF_DIR="/etc/httpd/conf.d"
HTPASSWD_PATH="/usr/local/nagios/etc/htpasswd.users"
;;
*)
echo -e "${RED}Unsupported distribution: $ID${NC}"
exit 1
;;
esac
else
echo -e "${RED}Cannot detect distribution. /etc/os-release not found${NC}"
exit 1
fi
echo -e "${GREEN}Installing Nagios Core 4.5 with SNMP on $PRETTY_NAME${NC}"
# Step 1: Update system packages
echo -e "${YELLOW}[1/12] Updating system packages...${NC}"
$PKG_UPDATE
# Step 2: Install build dependencies
echo -e "${YELLOW}[2/12] Installing build dependencies...${NC}"
if [[ "$PKG_MGR" == "apt" ]]; then
$PKG_INSTALL build-essential gcc glibc-dev make unzip apache2 apache2-utils php libapache2-mod-php libgd-dev libssl-dev autoconf automake libtool openssl wget tar
elif [[ "$PKG_MGR" == "dnf" ]]; then
dnf groupinstall -y "Development Tools"
$PKG_INSTALL httpd httpd-tools php php-cli gcc glibc-devel make unzip gd-devel openssl-devel automake autoconf libtool wget tar
else
yum groupinstall -y "Development Tools"
$PKG_INSTALL httpd httpd-tools php php-cli gcc glibc-devel make unzip gd-devel openssl-devel automake autoconf libtool wget tar
fi
# Step 3: Install SNMP tools and libraries
echo -e "${YELLOW}[3/12] Installing SNMP tools and libraries...${NC}"
if [[ "$PKG_MGR" == "apt" ]]; then
$PKG_INSTALL snmp snmp-mibs-downloader libsnmp-dev
else
$PKG_INSTALL net-snmp net-snmp-utils net-snmp-devel
fi
# Step 4: Create nagios user and group
echo -e "${YELLOW}[4/12] Creating nagios user and group...${NC}"
groupadd $NAGIOS_GROUP || true
useradd -g $NAGIOS_GROUP -d $NAGIOS_HOME -s /bin/bash $NAGIOS_USER || true
usermod -a -G $NAGIOS_GROUP $WEB_USER
# Step 5: Download Nagios Core 4.5
echo -e "${YELLOW}[5/12] Downloading Nagios Core 4.5...${NC}"
cd /tmp
wget -O nagios-4.5.0.tar.gz 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
# Step 6: Configure and compile Nagios
echo -e "${YELLOW}[6/12] Configuring and compiling Nagios...${NC}"
./configure --with-nagios-group=$NAGIOS_GROUP --with-command-group=$NAGIOS_GROUP --with-httpd-conf=$WEB_CONF_DIR --with-lockfile=/var/run/nagios.lock
make all
# Step 7: Install Nagios
echo -e "${YELLOW}[7/12] Installing Nagios binaries and configuration...${NC}"
make install
make install-commandmode
make install-config
make install-webconf
# Step 8: Download and install Nagios plugins
echo -e "${YELLOW}[8/12] Installing Nagios plugins...${NC}"
cd /tmp
wget -O nagios-plugins-2.4.0.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.0.tar.gz
tar -xzf nagios-plugins-2.4.0.tar.gz
cd nagios-plugins-release-2.4.0
./tools/setup
./configure --with-nagios-user=$NAGIOS_USER --with-nagios-group=$NAGIOS_GROUP
make && make install
# Step 9: Configure web server
echo -e "${YELLOW}[9/12] Configuring web server...${NC}"
if [[ "$PKG_MGR" == "apt" ]]; then
a2enmod cgi rewrite
a2ensite nagios
systemctl enable $WEB_SERVICE
systemctl restart $WEB_SERVICE
else
systemctl enable --now $WEB_SERVICE
if [ -f /etc/httpd/conf.d/nagios.conf.example ]; then
cp /etc/httpd/conf.d/nagios.conf.example /etc/httpd/conf.d/nagios.conf
fi
systemctl restart $WEB_SERVICE
fi
# Step 10: Create Nagios web interface user
echo -e "${YELLOW}[10/12] Creating web interface user...${NC}"
echo -e "${YELLOW}Please enter a password for the nagiosadmin user:${NC}"
htpasswd -c $HTPASSWD_PATH nagiosadmin
# Step 11: Set correct file permissions
echo -e "${YELLOW}[11/12] Setting file permissions...${NC}"
chown -R $NAGIOS_USER:$NAGIOS_GROUP $NAGIOS_HOME/
chmod 755 $NAGIOS_HOME/etc
chmod 644 $NAGIOS_HOME/etc/*.cfg
chmod 755 $NAGIOS_HOME/var
chmod 644 $HTPASSWD_PATH
# Create systemd service file
cat > /etc/systemd/system/nagios.service << 'EOF'
[Unit]
Description=Nagios Core 4.5.0
Documentation=https://www.nagios.org/documentation/
After=network.target
[Service]
Type=forking
User=nagios
Group=nagios
ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
[Install]
WantedBy=multi-user.target
EOF
# Step 12: Start and enable services
echo -e "${YELLOW}[12/12] Starting and enabling services...${NC}"
systemctl daemon-reload
systemctl enable nagios
systemctl start nagios
# Configure firewall
if command -v firewall-cmd >/dev/null 2>&1 && systemctl is-active firewalld >/dev/null 2>&1; then
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
echo -e "${GREEN}Firewall configured for HTTP access${NC}"
elif command -v ufw >/dev/null 2>&1; then
ufw allow Apache
echo -e "${GREEN}UFW configured for Apache access${NC}"
fi
# Verification
echo -e "${YELLOW}Verifying installation...${NC}"
if systemctl is-active --quiet nagios; then
echo -e "${GREEN}✓ Nagios service is running${NC}"
else
echo -e "${RED}✗ Nagios service is not running${NC}"
exit 1
fi
if systemctl is-active --quiet $WEB_SERVICE; then
echo -e "${GREEN}✓ Web server is running${NC}"
else
echo -e "${RED}✗ Web server is not running${NC}"
exit 1
fi
if [ -f $NAGIOS_HOME/bin/nagios ]; then
echo -e "${GREEN}✓ Nagios binary installed${NC}"
else
echo -e "${RED}✗ Nagios binary not found${NC}"
exit 1
fi
echo -e "${GREEN}"
echo "================================================================"
echo "Nagios Core 4.5 installation completed successfully!"
echo "================================================================"
echo "Web Interface: http://$(hostname -I | awk '{print $1}')/nagios"
echo "Username: nagiosadmin"
echo "Password: (the one you set during installation)"
echo ""
echo "Service commands:"
echo " sudo systemctl start|stop|restart|status nagios"
echo " sudo systemctl start|stop|restart|status $WEB_SERVICE"
echo ""
echo "Configuration files:"
echo " Main config: $NAGIOS_HOME/etc/nagios.cfg"
echo " Host configs: $NAGIOS_HOME/etc/objects/"
echo "================================================================"
echo -e "${NC}"
Review the script before running. Execute with: bash install.sh