Asterisk Log Analyzer

Monitoring -- Last reviewed 2026-03-29 logging debugging analysis administration Found this useful? Upvote it. ×

Asterisk Log Analyzer

Parses /var/log/asterisk/full to produce a quick summary of call activity: total calls, answer rates, busiest hours, and top callers. Useful for daily reports or troubleshooting.

Usage

# Analyze today's log
./log-analyzer.sh

# Analyze a specific date
./log-analyzer.sh 2026-02-14

# Analyze a different log file
LOG_FILE=/var/log/asterisk/full.1 ./log-analyzer.sh

Script

#!/bin/bash
set -euo pipefail

# Configuration
LOG_FILE="${LOG_FILE:-/var/log/asterisk/full}"
TARGET_DATE="${1:-$(date +%Y-%m-%d)}"

echo "=== Asterisk Call Report for ${TARGET_DATE} ==="
echo ""

if [ ! -f "${LOG_FILE}" ]; then
    echo "Error: Log file not found: ${LOG_FILE}"
    exit 1
fi

# Extract lines for the target date
DAY_LOG=$(grep "^\[${TARGET_DATE}" "${LOG_FILE}" || true)

if [ -z "${DAY_LOG}" ]; then
    echo "No log entries found for ${TARGET_DATE}"
    exit 0
fi

# Count call events
TOTAL_CALLS=$(echo "${DAY_LOG}" | grep -c "Dial\|Queue(" || true)
ANSWERED=$(echo "${DAY_LOG}" | grep -c "DIALSTATUS=ANSWER\|QUEUESTATUS=COMPLETED" || true)
NOANSWER=$(echo "${DAY_LOG}" | grep -c "DIALSTATUS=NOANSWER\|DIALSTATUS=CANCEL" || true)
BUSY=$(echo "${DAY_LOG}" | grep -c "DIALSTATUS=BUSY" || true)
FAILED=$(echo "${DAY_LOG}" | grep -c "DIALSTATUS=CONGESTION\|DIALSTATUS=CHANUNAVAIL" || true)

echo "Call Summary"
echo "  Total dial attempts: ${TOTAL_CALLS}"
echo "  Answered:            ${ANSWERED}"
echo "  No answer/cancel:    ${NOANSWER}"
echo "  Busy:                ${BUSY}"
echo "  Failed:              ${FAILED}"
if [ "${TOTAL_CALLS}" -gt 0 ]; then
    ANSWER_RATE=$((ANSWERED * 100 / TOTAL_CALLS))
    echo "  Answer rate:         ${ANSWER_RATE}%"
fi
echo ""

# Busiest hours
echo "Calls by Hour"
echo "${DAY_LOG}" | grep "Dial\|Queue(" \
    | grep -oP "^\[\d{4}-\d{2}-\d{2} \K\d{2}" \
    | sort | uniq -c | sort -rn | head -5 \
    | while read COUNT HOUR; do
        printf "  %s:00 - %s:59  %s calls\n" "${HOUR}" "${HOUR}" "${COUNT}"
    done
echo ""

# Top 10 callers (by caller ID number)
echo "Top Callers"
echo "${DAY_LOG}" | grep -oP 'CALLERID\(num\)=\K[0-9+]+' \
    | sort | uniq -c | sort -rn | head -10 \
    | while read COUNT NUMBER; do
        printf "  %-18s %s calls\n" "${NUMBER}" "${COUNT}"
    done
echo ""

# Errors and warnings
ERROR_COUNT=$(echo "${DAY_LOG}" | grep -ic "ERROR\|WARNING" || true)
echo "Errors/Warnings: ${ERROR_COUNT}"
if [ "${ERROR_COUNT}" -gt 0 ]; then
    echo "  Recent errors:"
    echo "${DAY_LOG}" | grep -i "ERROR\|WARNING" | tail -5 | sed 's/^/    /'
fi

How it works

  1. Log format: Asterisk's full log prefixes every line with [YYYY-MM-DD HH:MM:SS]. The script greps for the target date to extract a single day's entries.
  2. DIALSTATUS counting: The dialplan logs DIALSTATUS=ANSWER, DIALSTATUS=NOANSWER, etc. via NoOp() or verbose output. The script counts occurrences of each status value.
  3. Hour extraction: grep -oP "^\[\d{4}-\d{2}-\d{2} \K\d{2}" uses a Perl regex lookbehind to extract just the hour (HH) from each timestamp, then uniq -c tallies them.
  4. Caller ID extraction: Looks for CALLERID(num)= patterns in the log to identify the most active callers.

Tips

User Notes

No notes yet. Be the first to contribute a tip or example.

Contribute a note

Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.

Moderated before publishing. Email never shown.

Related Snippets