← All Tutorials

Monitoring Asterisk with SNMP & Nagios/Zabbix

Monitoring & Observability Intermediate 14 min read #58

Learn how to deploy enterprise-grade monitoring for your Asterisk/ViciDial system using SNMP, Nagios, and Zabbix to track calls, channels, and system health in real-time.

Prerequisites

Before implementing SNMP monitoring for your Asterisk system, ensure you have:

Understanding SNMP for Asterisk Monitoring

SNMP (Simple Network Management Protocol) provides a lightweight, standardized way to gather metrics from networked devices. For Asterisk systems, SNMP can expose:

The key advantage over direct API calls or log parsing is standardization — your Nagios/Zabbix installation already knows how to query SNMP, so integration becomes straightforward.

Section 1: Installing and Configuring SNMP on Asterisk

Installing Net-SNMP

Start by installing the SNMP daemon and utilities:

# CentOS/RHEL
yum install -y net-snmp net-snmp-utils net-snmp-devel

# Debian/Ubuntu
apt-get install -y snmp snmpd snmp-mibs-downloader

Enable and start the SNMP daemon:

systemctl enable snmpd
systemctl start snmpd

Verify SNMP is listening on port 161:

netstat -uln | grep 161
# Output should show: udp    0    0 0.0.0.0:161    0.0.0.0:*

Configuring SNMP Community and MIB

Edit the SNMP configuration file:

cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
vim /etc/snmp/snmpd.conf

Replace the configuration with production-safe settings:

# /etc/snmp/snmpd.conf - Asterisk SNMP Configuration

# Only allow monitoring server to query SNMP
rocommunity public 192.168.1.100         # Replace with your monitoring server IP
rocommunity6 public [::1]                 # IPv6 if applicable

# Basic system information
sysdescr "ViciDial Asterisk System - Production"
syscontact "[email protected]"
syslocation "Data Center 1"

# Process monitoring (optional, but useful)
proc asterisk

# Memory thresholds
includeAllDisks 10%

# Listen on all interfaces
agentAddress udp:161,udp6:[::1]:161

# MIB modules to load
mibs +ALL

# Traps/informs (if you want active notifications)
# trap2sink 192.168.1.100 public

# Allow only monitoring operations
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1
view systemonly included .1.3.6.1.4.1.22736

access ConfigGroup "" any noauth exact systemonly none none

Restart SNMP after configuration:

systemctl restart snmpd

Testing SNMP Connectivity

From your monitoring server, test connectivity:

snmpwalk -v2c -c public 192.168.X.X 1.3.6.1.2.1.1.1.0
# Output should return system description

If this fails, check firewall rules:

# On Asterisk server
firewall-cmd --permanent --add-service=snmp
firewall-cmd --reload

Section 2: Creating Custom SNMP OIDs for Asterisk Metrics

Asterisk doesn't expose native SNMP OIDs by default. We'll create custom OIDs using shell scripts that query Asterisk directly and feed data into SNMP's extend directive.

Installing Asterisk Monitoring Scripts

Create a dedicated directory for monitoring scripts:

mkdir -p /opt/asterisk-monitoring
chmod 755 /opt/asterisk-monitoring

Script 1: Active Channels Counter

This script counts currently active SIP channels:

cat > /opt/asterisk-monitoring/active_channels.sh << 'EOF'
#!/bin/bash
# Count active SIP channels via Asterisk CLI

ASTERISK_CLI="/usr/sbin/asterisk -rx"
COUNT=$($ASTERISK_CLI "sip show channels" | grep "active SIP" | awk '{print $1}')

if [ -z "$COUNT" ]; then
    echo 0
else
    echo "$COUNT"
fi
EOF

chmod +x /opt/asterisk-monitoring/active_channels.sh

Test it:

/opt/asterisk-monitoring/active_channels.sh
# Output: 45

Script 2: Queue Statistics

For ViciDial systems, fetch active queue metrics:

cat > /opt/asterisk-monitoring/queue_stats.sh << 'EOF'
#!/bin/bash
# Extract queue statistics from Asterisk

ASTERISK_CLI="/usr/sbin/asterisk -rx"

# Get total members in queue
MEMBERS=$($ASTERISK_CLI "queue show all" | grep "members" | awk -F'[()]' '{sum+=$2} END {print sum+0}')

# Get waiting callers
WAITING=$($ASTERISK_CLI "queue show all" | grep "waiting" | awk -F'[()]' '{sum+=$2} END {print sum+0}')

echo "${MEMBERS}:${WAITING}"
EOF

chmod +x /opt/asterisk-monitoring/queue_stats.sh

Script 3: ViciDial Agent Login Count

Query the database directly for logged-in agents:

cat > /opt/asterisk-monitoring/vicidial_agents.sh << 'EOF'
#!/bin/bash
# Count logged-in ViciDial agents from database

MYSQL_USER="root"
MYSQL_PASS="your_password_here"
MYSQL_DB="asterisk"

AGENTS=$(mysql -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DB -se \
"SELECT COUNT(*) FROM vicidial_users WHERE active='Y' AND user_level > 0;")

echo "${AGENTS:-0}"
EOF

chmod +x /opt/asterisk-monitoring/vicidial_agents.sh
chmod 600 /opt/asterisk-monitoring/vicidial_agents.sh  # Secure due to password

Script 4: Trunk/Carrier Status

Check active carriers in ViciDial:

cat > /opt/asterisk-monitoring/carrier_status.sh << 'EOF'
#!/bin/bash
# Monitor carrier connectivity status

MYSQL_USER="root"
MYSQL_PASS="your_password_here"
MYSQL_DB="asterisk"

# Count active carriers
ACTIVE=$(mysql -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DB -se \
"SELECT COUNT(*) FROM vicidial_carrier_log WHERE status='READY' ORDER BY carrier_id DESC LIMIT 1;")

TOTAL=$(mysql -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DB -se \
"SELECT COUNT(DISTINCT carrier_id) FROM vicidial_carrier_log;")

echo "${ACTIVE:-0}/${TOTAL:-0}"
EOF

chmod +x /opt/asterisk-monitoring/carrier_status.sh
chmod 600 /opt/asterisk-monitoring/carrier_status.sh

Integrating Scripts into SNMP

Add the following to /etc/snmp/snmpd.conf:

# Custom Asterisk OIDs via shell scripts
extend activeChannels /opt/asterisk-monitoring/active_channels.sh
extend queueStats /opt/asterisk-monitoring/queue_stats.sh
extend vicidialAgents /opt/asterisk-monitoring/vicidial_agents.sh
extend carrierStatus /opt/asterisk-monitoring/carrier_status.sh

# Add these to accessible view
view systemonly included .1.3.6.1.4.1.8072.1.3.2.3.1.1
view systemonly included .1.3.6.1.4.1.8072.1.3.2.4.1.2

Restart SNMP:

systemctl restart snmpd

Test OID retrieval from monitoring server:

snmpwalk -v2c -c public 192.168.X.X .1.3.6.1.4.1.8072.1.3.2
# Should list all extended OIDs

Section 3: Configuring Nagios for Asterisk Monitoring

Installing Nagios Check Plugins

Install the SNMP check plugin:

# CentOS/RHEL
yum install -y nagios-plugins-snmp

# Debian/Ubuntu
apt-get install -y nagios-plugins nagios-plugins-snmp

Creating Nagios Service Definitions

On your Nagios server, create a configuration file for Asterisk monitoring:

cat > /etc/nagios/objects/asterisk-checks.cfg << 'EOF'
# Asterisk/ViciDial SNMP Monitoring Definitions

define host{
    use                     linux-server
    host_name               asterisk-prod
    alias                   Production Asterisk/ViciDial
    address                 192.168.1.50
    max_check_attempts      3
    check_interval          5
    retry_interval          1
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     Active SIP Channels
    check_command           check_snmp_custom!activeChannels!200!300
    check_interval          1
    retry_interval          1
    contact_groups          ops_team
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     Queue Members
    check_command           check_snmp_queue_members
    check_interval          2
    contact_groups          ops_team
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     ViciDial Agents Online
    check_command           check_snmp_agents!10!15
    check_interval          2
    contact_groups          ops_team
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     Carrier Status
    check_command           check_snmp_carriers!1/2!2/3
    check_interval          5
    contact_groups          ops_team
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     Asterisk Process
    check_command           check_procs!1!1!asterisk
    contact_groups          ops_team
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     System CPU Load
    check_command           check_snmp_load!5.0,4.0,3.0!10.0,6.0,4.0
    check_interval          3
    contact_groups          ops_team
    }

define service{
    use                     local-service
    host_name               asterisk-prod
    service_description     Memory Utilization
    check_command           check_snmp_mem!80!90
    contact_groups          ops_team
    }
EOF

Creating Custom Nagios Check Commands

Add these command definitions to /etc/nagios/objects/commands.cfg:

# Custom Asterisk check commands

define command{
    command_name    check_snmp_custom
    command_line    $USER1$/check_snmp -H $HOSTADDRESS$ -o .1.3.6.1.4.1.8072.1.3.2.4.1.2.13 -w $ARG2$ -c $ARG3$ -s "$ARG1$"
    }

define command{
    command_name    check_snmp_queue_members
    command_line    $USER1$/check_snmp -H $HOSTADDRESS$ -o .1.3.6.1.4.1.8072.1.3.2.4.1.2.11 -w 50 -c 100
    }

define command{
    command_name    check_snmp_agents
    command_line    $USER1$/check_snmp -H $HOSTADDRESS$ -o .1.3.6.1.4.1.8072.1.3.2.4.1.2.15 -w $ARG1$ -c $ARG2$
    }

define command{
    command_name    check_snmp_carriers
    command_line    $USER1$/check_snmp -H $HOSTADDRESS$ -o .1.3.6.1.4.1.8072.1.3.2.4.1.2.16 -w '$ARG1$' -c '$ARG2$'
    }

define command{
    command_name    check_snmp_load
    command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$
    }

define command{
    command_name    check_snmp_mem
    command_line    $USER1$/check_snmp -H $HOSTADDRESS$ -o .1.3.6.1.4.1.2578.1.4.3 -w $ARG1$ -c $ARG2$
    }
EOF

Validate and reload Nagios:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
systemctl reload nagios

Section 4: Setting Up Zabbix Monitoring (Alternative)

If you prefer Zabbix over Nagios, follow this section instead.

Creating Zabbix SNMP Host

In the Zabbix web interface (http://zabbix-server/zabbix/):

  1. Navigate to Configuration > Hosts

  2. Click Create host

  3. Fill in:

    • Host name: asterisk-prod
    • Visible name: Production Asterisk/ViciDial
    • Groups: Select or create Asterisk
    • Interfaces:
      • Type: SNMP
      • IP address: 192.168.1.50
      • Port: 161
      • SNMP version: SNMPv2c
      • SNMP community: public
  4. Click Add

Creating Zabbix Items for Asterisk Metrics

Create items to map SNMP OIDs to Zabbix metrics. For each item:

  1. Open the Asterisk host
  2. Click Items > Create item
  3. Configure:

Item 1: Active Channels

Name: Asterisk Active Channels
Type: SNMP agent
SNMP OID: .1.3.6.1.4.1.8072.1.3.2.4.1.2.13
Value type: Numeric (unsigned)
Units: channels
Update interval: 60

Item 2: Queue Members

Name: Asterisk Queue Members
Type: SNMP agent
SNMP OID: .1.3.6.1.4.1.8072.1.3.2.4.1.2.11
Value type: Numeric (unsigned)
Update interval: 120

Item 3: ViciDial Agents

Name: ViciDial Agents Online
Type: SNMP agent
SNMP OID: .1.3.6.1.4.1.8072.1.3.2.4.1.2.15
Value type: Numeric (unsigned)
Update interval: 120

Item 4: System CPU Load

Name: System CPU Load
Type: SNMP agent
SNMP OID: .1.3.6.1.2.1.25.3.3.1.2.196608
Value type: Numeric (float)
Update interval: 180

Item 5: Memory Available

Name: Memory Available
Type: SNMP agent
SNMP OID: .1.3.6.1.2.1.25.2.3.1.6.1
Value type: Numeric (unsigned)
Units: B
Update interval: 180

Creating Zabbix Triggers for Alerts

Create triggers for critical conditions:

Trigger 1: High Channel Count

Name: Too many active channels (>250)
Severity: Average
Condition: {asterisk-prod:Asterisk Active Channels.last()} > 250

Trigger 2: Agents Below Minimum

Name: Insufficient agents online (<5)
Severity: High
Condition: {asterisk-prod:ViciDial Agents Online.last()} < 5

Trigger 3: Carrier Failure

Name: Primary carrier degraded
Severity: High
Condition: {asterisk-prod:Carrier Status.str(READY)} = 0

Creating Zabbix Dashboards

  1. Navigate to Dashboards > Create dashboard
  2. Name: Asterisk Real-Time Metrics
  3. Add widgets:
    • Graph: Asterisk Active Channels (1-hour view)
    • Graph: ViciDial Agents Online
    • Gauge: Memory Utilization (%)
    • Table: Latest data for all Asterisk items

Section 5: Advanced Monitoring Scenarios

Monitoring ViciDial Call Center Metrics

For ViciDial-specific monitoring, create a more sophisticated script querying the database:

cat > /opt/asterisk-monitoring/vicidial_metrics.sh << 'EOF'
#!/bin/bash
# Comprehensive ViciDial metrics for SNMP

MYSQL_USER="root"
MYSQL_PASS="password"
MYSQL_DB="asterisk"

get_metric() {
    mysql -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DB -se "$1" 2>/dev/null | head -1
}

# Calls in last hour
CALLS_HOUR=$(get_metric "SELECT COUNT(*) FROM vicidial_log WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR);")

# Average call duration (minutes)
AVG_DURATION=$(get_metric "SELECT AVG((LENGTH_IN_SEC_CALL + LENGTH_IN_SEC_WAIT) / 60) FROM vicidial_log WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR) AND LENGTH_IN_SEC_CALL > 0;")

# Abandon rate percentage
ABANDON=$(get_metric "SELECT (COUNT(CASE WHEN status='DROP' OR status='ABANDON' THEN 1 END) / COUNT(*) * 100) FROM vicidial_log WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR);")

# Active live agents
LIVE_AGENTS=$(get_metric "SELECT COUNT(*) FROM vicidial_live_agents WHERE status='LIVE';")

# Dials per minute (average)
DPM=$(get_metric "SELECT COUNT(*) / 60 FROM vicidial_log WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 MINUTE);")

# Output as colon-separated values for easy parsing
echo "${CALLS_HOUR}:${AVG_DURATION}:${ABANDON}:${LIVE_AGENTS}:${DPM}"
EOF

chmod +x /opt/asterisk-monitoring/vicidial_metrics.sh
chmod 600 /opt/asterisk-monitoring/vicidial_metrics.sh

Add to SNMP:

extend vicidialMetrics /opt/asterisk-monitoring/vicidial_metrics.sh

Monitoring Asterisk Dialplan Performance

Track slow extensions and problematic dial patterns:

cat > /opt/asterisk-monitoring/dialplan_perf.sh << 'EOF'
#!/bin/bash
# Monitor slow dialplan execution

LOG_FILE="/var/log/asterisk/messages"
TEMP_FILE="/tmp/asterisk_dialplan_perf.tmp"

# Find extensions taking >1000ms
grep -i "Execute.*ms" "$LOG_FILE" | tail -100 | \
awk -F'[()]' '$NF+0 > 1000 {print $NF}' | \
awk '{sum+=$1; count++} END {print (count>0?sum/count:0)}' > "$TEMP_FILE"

cat "$TEMP_FILE"
EOF

chmod +x /opt/asterisk-monitoring/dialplan_perf.sh

Monitoring SIP Trunk Health

Create a comprehensive trunk status script:

cat > /opt/asterisk-monitoring/trunk_health.sh << 'EOF'
#!/bin/bash
# Monitor SIP trunk quality and availability

ASTERISK_CLI="/usr/sbin/asterisk -rx"

# Check SIP peers
ONLINE=$($ASTERISK_CLI "sip show peers" | grep -c "OK")
OFFLINE=$($ASTERISK_CLI "sip show peers" | grep -c "UNREACHABLE\|UNKNOWN")
TOTAL=$(($ONLINE + $OFFLINE))

# Get registration status for each defined trunk
TRUNKS=$($ASTERISK_CLI "sip show registry" | tail -n +2)

echo "${ONLINE}/${TOTAL}:${OFFLINE}"
EOF

chmod +x /opt/asterisk-monitoring/trunk_health.sh

Section 6: Performance Optimization and Best Practices

Optimizing SNMP Polling Intervals

Set appropriate polling intervals to balance visibility and load:

Avoid polling too frequently as it increases Asterisk load:

# Monitor query impact
strace -e query asterisk -rx "sip show channels" 2>&1 | wc -l
# Aim for <50 lines of system calls per query

Securing SNMP Access

Restrict SNMP to monitoring server only:

# /etc/snmp/snmpd.conf
rocommunity public 192.168.1.100   # Monitoring server IP only
rocommunity public default removed  # Remove public access everywhere else

# Use SNMPv3 for production (recommended)
# rouser monitoring_user priv -V '1.3.6.1.4.1.8072.1.3.2'

Restart SNMP:

systemctl restart snmpd

Database Query Optimization

For ViciDial scripts, add proper indexing:

ALTER TABLE vicidial_log ADD INDEX call_date_idx (call_date);
ALTER TABLE vicidial_live_agents ADD INDEX status_idx (status);
ALTER TABLE vicidial_users ADD INDEX user_level_idx (user_level);

Cache script results to reduce database load:

cat > /opt/asterisk-monitoring/vicidial_agents_cached.sh << 'EOF'
#!/bin/bash
CACHE_FILE="/tmp/vicidial_agents.cache"
CACHE_TTL=120

if [ -f "$CACHE_FILE" ] && [ $(($(date +%s) - $(stat -c %Y "$CACHE_FILE"))) -lt $CACHE_TTL ]; then
    cat "$CACHE_FILE"
else
    /opt/asterisk-monitoring/vicidial_agents.sh > "$CACHE_FILE"
    cat "$CACHE_FILE"
fi
EOF

chmod +x /opt/asterisk-monitoring/vicidial_agents_cached.sh

Troubleshooting

SNMP Not Responding

Problem: snmpwalk times out

Solution:

# Check SNMP daemon is running
systemctl status snmpd

# Check firewall
firewall-cmd --list-all | grep snmp

# Allow SNMP through firewall
firewall-cmd --permanent --add-service=snmp
firewall-cmd --reload

# Check listening port
netstat -uln | grep :161

Scripts Return Empty Values

Problem: Extended SNMP OIDs return no data

Solution:

# Test script directly
/opt/asterisk-monitoring/active_channels.sh

# Check Asterisk connectivity
sudo /usr/sbin/asterisk -rx "sip show channels" | head -5

# Verify SNMP extend syntax
grep "extend" /etc/snmp/snmpd.conf

# Restart SNMP daemon
systemctl restart snmpd

# Test OID directly
snmpwalk -v2c -c public localhost .1.3.6.1.4.1.8072.1.3.2

High CPU Usage from Monitoring

Problem: Frequent SNMP polling causes high Asterisk CPU usage

Solution:

cat > /etc/cron.d/asterisk-metrics << 'EOF'
*/5 * * * * root /opt/asterisk-monitoring/vicidial_agents.sh > /tmp/agents.txt 2>/dev/null
*/5 * * * * root /opt/asterisk-monitoring/carrier_status.sh > /tmp/carriers.txt 2>/dev/null
EOF

Then modify scripts to read from file:

cat /tmp/agents.txt

Nagios/Zabbix Not Receiving Data

Problem: Items show "No data"

Solution:

# Verify host reachability from monitoring server
ping 192.168.1.50

# Test SNMP connectivity
snmpget -v2c -c public 192.168.1.50 1.3.6.1.2.1.1.1.0

# Check Nagios/Zabbix logs
tail -f /var/log/nagios/nagios.log
tail -f /var/log/zabbix/zabbix_server.log

# Verify OID syntax matches configuration
snmpwalk -v2c -c public 192.168.1.50 .1.3.6.1.4.1.8072.1.3.2

Permission Denied on MySQL Queries

Problem: Scripts return empty values or errors

Solution:

# Test MySQL connectivity
mysql -u root -p -e "SELECT 1;" asterisk

# Fix script permissions
chmod 600 /opt/asterisk-monitoring/*.sh
ls -la /opt/asterisk-monitoring/

# Ensure asterisk user can execute
sudo -u asterisk /opt/asterisk-monitoring/vicidial_agents.sh

Carrier Status Reports Incorrect Values

Problem: Carrier status shows 0/0 or wrong counts

Solution:

# Check ViciDial carrier table directly
mysql -u root -p asterisk -e "SELECT * FROM vicidial_carrier_log LIMIT 5;"

# Verify table structure
mysql -u root -p asterisk -e "DESCRIBE vicidial_carrier_log;"

# Check for recent carrier activity
mysql -u root -p asterisk -e "SELECT DISTINCT status FROM vicidial_carrier_log;";

SNMP Extend Timeout

Problem: Extended OIDs timeout in SNMP responses

Solution:

# /etc/snmp/snmpd.conf
# Increase timeout for long-running scripts
extendTimeout 30   # Default is 5 seconds

# Or add exec instead of extend for non-critical data
exec carriers /opt/asterisk-monitoring/carrier_status.sh

Summary

Monitoring Asterisk with SNMP and Nagios/Zabbix provides enterprise-grade visibility into your ViciDial call center infrastructure. This guide covered:

  1. SNMP Installation & Configuration — Setting up net-snmp with proper access controls
  2. Custom Monitoring Scripts — Creating shell scripts that expose Asterisk/ViciDial metrics via SNMP extend
  3. Nagios Integration — Defining hosts, services, and check commands for automated alerting
  4. Zabbix Integration — Creating items, triggers, and dashboards for real-time monitoring
  5. Advanced Metrics — ViciDial call center KPIs, trunk health, dialplan performance
  6. Optimization — Reducing monitoring overhead through caching and interval tuning
  7. Troubleshooting — Diagnosing common configuration and connectivity issues

Key Takeaways:

For production ViciDial systems handling thousands of concurrent calls, this monitoring setup provides the visibility needed to proactively detect and respond to issues before they impact call quality or customer experience.

Need expert help with your setup?

VoIP infrastructure consulting, AI voice agent integration, monitoring stacks, scaling — I've done it all in production.

Get a Free Consultation