venerdì 19 dicembre 2014

SCRIPT PER IL CONTROLLO DELLA REGISTRAZIONE DEL TRUNK

il seguente script agisce quando un trunk va offline e lo notifica via email.
lo stesso va salvato in /var/lib/astrerisk/agi-bin.
chiamiamolo trunkcheck.sh e diamogli 

chown asterisk:asterisk trunkcheck.sh per impostare il proprietario
e
chmod +x trunkcheck.sh per dare i diritti di esecuzione

mentre in /etc/asterisk va creato un file chiamato trunkalerts_sip.conf. nel file va poi inserito l'ip che si ottiene dando il comando asterisk -rx "sip show registry"    

dal pannello di freepbx andare poi nelle impostazioni del trunk e alla voce "Monitor Trunk Failures" inserire il nome dello script, trunkcheck.sh

nel corpo dello script personalizzare la mail a cui inviare l'alert
poi aggiungere una riga in cron che faccia comunque girare lo script ogni minuto



#!/usr/bin/perl -w
use strict;
use warnings;
#no warnings; #Remark out to suppress ALL warnings, also add remark to above line.
#### email address must have \@ as perl needs to escape the @ symbol. Obviously you’ll need to edit these email addresses
my $alertemail = "marketing\@floorlab.it" ;
my $pbxdomain = "floorlab.it" ;
#### comment out whichever of the following two lines are not relevant for your server
checktrunk("sip");
#checktrunk("iax2");
################################################## 
##################################################
####
#### Trunk Alerts script written by Jim Hribnak Oct 7th 2007
#### if there is any questions please feel free to drop me an email at jimh at domain nucleus.com
####
################################################## 
##################################################
####
#### Script modified by Charles Pippin Feb 21st 2009 - Added counters for loop retry.
#### if there is any questions please feel free to drop me an email at cwpippin at domain gmail.com
####
################################################## 
##################################################
####
#### Script modified by Stephen Wilkey Mar 18th 2010
#### - moved email addressing details to the top of the script so that they are easier to customise
#### - original script assumed both iax2 and sip trunks and would fail if you didn’t have both – now the one you don’t want can be easily commented out at the top
#### - improved the documentation below about what files to create and what to include in those files in order to customise best to individual environments
#### - simplified the code to use the same code for both SIP and IAX2. PLEASE NOTE: the iax trunk alert file has now changed to having iax2 in the name. If you are upgrading from an older version you will need to rename the original iax trunk alert file.
################################################## 
##################################################
####
#### Create the following files in /etc/asterisk (if you want to only check sip trunks don’t create the other file etc)
#### - /etc/asterisk/trunkalerts_sip.conf
#### - /etc/asterisk/trunkalerts_iax2.conf
####
#### in the files below add the any unique entry from asterisk -rx "sip show registry" and
#### from asterisk -rx "iax2 show registry". The original specification was to use
#### the hostname, however if you have multiple trunks from the same supplier it is more
#### likely that the username might be unique. You don't need to be consistent either
#### - you can use hostname for some and username for others - as long as each
#### line of the show registry result is specified uniquely once by something
#### unique in that line for this script to grep on.
####
################################################## 
##################################################
####
sub checktrunk {
# the next line gets the trunktype parameter passed to the subroutine
my $trunktype=shift;
####
print "=============================================\n";
print "$trunktype Trunk information\n";
print "=============================================\n";
open(TRUNKLIST,"</etc/asterisk/trunkalerts_$trunktype.conf");
while (<TRUNKLIST>) {
chomp;
my $recheckcounter = 1;
my $upcounter = 5;
my $dncounter = 5;
until ($upcounter == 0) {
my $trunks = `/usr/sbin/asterisk -rx "$trunktype show registry" | grep \"$_\" | awk '{ print \$5 }'`;
#comment next line if you don't want to see the output
#print "$trunktype trunks = $trunks\n"; #Remove remark to see output from "sip show registry" command
if ($trunks =~ "Registered") {
$upcounter = $upcounter - 1;
#print $upcounter,"\n"; #Remove remark to see counter decrement
print "$_ is up\n" ; #Remove remark to see notification of trunk being "UP"
}
else {
$dncounter = $dncounter - 1;
#print $dncounter,"\n"; #Remove remark to see counter decrement once trunk is found to be down
print "$_ is down\n" ; #Remove remark to see notification of trunk being "DOWN"
if ($dncounter == 0) {
if ($recheckcounter == 1) {
# we now reload the trunks and force the check to occur again
`asterisk -rx "module reload"`;
print "Reloading trunks (will wait for reconnection before checking again\n";
# adjust the length of time on the next line (seconds) if you find it takes longer to re-establish
# trunk connections after a reload
`sleep 20`;
$recheckcounter = 0;
$dncounter = 5;
}
else
{
mailalert();
$upcounter = 0;
#print $upcounter,"\n"; #Remove remark to see counter decrement once trunk is found to be down
print "houston we have a problem\n";
print "$_ trunk is not registering\n";
$recheckcounter = 1;
}
}
}
}
}
#end of while loop (read trunk file)
}
################################################## 
##################################################
####
#### Email Subroutines
#### Change anywhere below where there is an email address an email address
#### must have \@ as perl needs to escape the @ symbol
####
################################################## 
##################################################
sub mailalert {
my $sendmail = "/usr/sbin/sendmail -t";
my $from= "FROM: <pbx\@$pbxdomain>\n";
my $reply_to = "Reply-to: <pbx\@$pbxdomain\n";
my $subject = "Subject: $_ is DOWN!!!!\n";
my $content = "PBX TRUNK $_ is DOWN!!!!\n";
my $send_to = "To:<$alertemail>\n";
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $from;
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL $content;
close(SENDMAIL);
print "An email has been sent!\n\n";
}

mercoledì 10 dicembre 2014

RIMUOVERE CACHE MODULI SCARICATI

Asterisk scarica in cache tutti i moduli che aggiorna. se per caso un archivio si danneggia durante il downlaod, al momento dell'aggiornamento asterisk lo rileverà come presente in locale, cercherà di usarlo e darà errore perchè il file è danneggito.
per rimuovere tali file cancellare il contenuto della cartella

/var/www/html/admin/modules/_cache

Post in evidenza

RISOLVERE PROBLEMA DISCONNESSIONE UNITA DI RETE

- lato server disattivare il timeout delle condivisioni dando da cmd il seguente comando net config server /autodisconnect:-1 - portare...