Asterisk: Monitoring Your E1 or T1 With Nagios

Home » Asterisk Tips » Asterisk: Monitoring Your E1 or T1 With Nagios
Asterisk Tips No Comments

E1 monitoring/T1 monitoring is a need that we have on a daily basis because the client’s business depends on it. Here you have an interesting script in PERL that will allow you to monitor your E1/T1 with Nagios. Passing the name of the port as an argument will allow you to use it even if it is not yet connected to a telco. Using the Nagios Remote Plugin Executor on the Asterisk server you can execute it. Additionally, it will report bad ports to you in order to avoid the guessing process.

 E1/T1 monitoring script in Asterisk

#!/usr/bin/perl -w

# Copyright (C) 2010 Local Matters, Inc.
# http://www.localmatters.com/
# Author: Joel C. Maslak
#
# Licensed under GPL version 3
#

use strict;
use Carp;

my %ignore;

MAIN: {
    my @out = `/usr/sbin/dahdi_scan`;

    for my $ig (@ARGV) {
        $ignore{$ig} = 1;
    }

    my $alarm;
    my $desc;
    my @alarms;

    for my $line (@out) {

        chomp($line);

        if ($line =~ /^alarms=/) {
            $alarm = $line;
            $alarm =~ s/^alarms=//;
        }

        if ($line =~ /^description=/) {
            $desc = $line;
            $desc =~ s/^description=//;

            if (!defined($ignore{$desc})) {
                if ($alarm ne ‘OK’) {
                    push @alarms, “$desc: $alarm Alarm”;
                }
            }
        }
    }

    if (scalar(@alarms) > 0) {
        my $out = join ‘; ‘, @alarms;
        print “Circuits in alarm: $outn”;
        exit(2);
    } else {
        print “All monitored circuits OKn”;
        exit(0);
    }
}

Thanks to Joel C. Maslak for this great contribution