TEAMFORREST

Asterisk, VoIP, and IT Consulting

Perl Script for Asterisk Failed Peer Registrations

with 2 comments

I guess this might be better titled as the Quick and Dirty Perl Script… but here we go:

#!/usr/bin/perl -w
use strict;
use warnings;
my (@failhost);

open (MYINPUTFILE, "/var/log/asterisk/$ARGV[0]") or die "\n", $!, "Does log file file exist\?\n\n";

while (<MYINPUTFILE>) {
	my ($line) = $_;
	chomp($line);
	if ($line =~ m/\' failed for \'(.*?)\' - No matching peer found/) {
		push(@failhost,$1);
	}
}

if (@failhost) {
	&count_unique(@failhost);
} else {
	print "no failed registrations.\n";
}

sub count_unique {
    my @array = @_;
    my %count;
    map { $count{$_}++ } @array;

	#print them out:

    map {print "$_ = ${count{$_}}\n"} sort keys(%count);

}

And while we duck from @Merlyn’s criticisms (although we love his criticism), the basic usage is:

perl [Whatever you named it].pl messages
or perl [Whatever you named it].pl messages.1

Results look like:

184.73.53.22 = 13586
64.76.45.100 = 9895
78.46.87.14 = 9960

Or “no failed registrations.” if you have no failed attempts.

Written by Team Forrest

April 12th, 2010 at 6:46 pm

2 Responses to 'Perl Script for Asterisk Failed Peer Registrations'

Subscribe to comments with RSS or TrackBack to 'Perl Script for Asterisk Failed Peer Registrations'.

  1. [...] Read this article: Perl Script for Asterisk Failed Peer Registrations | TEAM FORREST Blog [...]

  2. [...] we posted a little script for quickly checking your asterisk log for failed peer registrations. Building on that script, and with the use of iptables and cron, you can easily (and automatically) [...]

Leave a Reply