Perl Script for Asterisk Failed Peer Registrations
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.
[...] Read this article: Perl Script for Asterisk Failed Peer Registrations | TEAM FORREST Blog [...]
asteriskforce.com » Blog Archive » Perl Script for Asterisk Failed Peer Registrations | TEAM FORREST Blog - Just another WordPress weblog
12 Apr 10 at 8:39 pm
[...] 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) [...]
Automatically Block Failed SIP Peer Registrations | TEAM FORREST Blog
13 Apr 10 at 12:54 pm