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

venerdì 24 ottobre 2014

Flash Operator Panel 2 - errore installazione plugin

se dal manager non fa aggiungere i plugin è un problema di privilegi.
per risolvere dare


 chown asterisk.asterisk /var/www/html/fop2/* -R

lunedì 25 agosto 2014

percorsi cartelle di accesso frequente su asterisk

plugin superfecta

/var/www/html/admin/modules/superfecta/sources


backup

/var/spool/asterisk/backup


registrazioni telefonate

/var/spool/asterisk/monitor

freepbx + isymphony: abilitare gestione status DND

Per far si che si possa attivare e disattivare lo stato del DND dal pannello di isymphony è necessario attivare la voce "Enable Custom Device States".
Per attivarla accedere al pannello di freepbx, andare su "settings" e poi su "advanced settings", trovare la voce "Enable Custom Device States" e settarla su TRUE.
ricordarsi di cliccare sul baffo verde a destra per confermare la modifica.

martedì 22 aprile 2014

freepbx: come ripristinare interfaccia web che non appare più dopo crash

può capitare che dopo un crash l'interfaccia web non risulti più raggiungibile.
questo accade spesso perchè il servizio di mysql non riesce a ripartire.
per risolvere basta rimuovere il file /var/lib/mysql/mysql.sock e riavviare.

freepbx: rimuovere moduli disinstallati - Not Installed (Locally available)

in module admin, dopo aver disinstallato i moduli che non occorrono gli stessi vengono comunque elencati come Not Installed (Locally available).
per farli sparire del tutto basta andare in  /var/www/html/admin/modules e rimuovere la cartella del modulo

asterisk: paginebianche.it come sorgente di CID superfecta

cid superfecta permette di ricevere il nome del chiamante cercando in vari database. lo script non è più fornito con il modulo di paginebianche.it per motivi di copyright. chi volesse sperimentare le espressioni regolari può testare come funzionava il modulo (e poi rimuoverlo per non violare la legge).

-andare in /var/www/html/admin/modules/superfecta/sources e creare un file chiamato source-PagineBianche_IT.module

- aprire il file e incollarci il codice seguente

<?php

class PagineBianche_IT extends superfecta_base {

    public $description = "http://www.paginebianche.it - These listings include data from the Italian PagineBianche.";
    public $version_requirement = "2.11";

    function get_caller_id($thenumber, $run_param=array()) {

            $this->DebugPrint("Searching PagineBianche - {$thenumber} ... ");
            $url = "http://www.paginebianche.it/ricerca-da-numero?qs={$thenumber}";
#            $this->DebugPrint("{$url}");
         
            if ($this->SearchURL($url, '=<h2.class\=\"rgs\"[^>]*>(.*)</h2>=siU' , $match)) {
                $caller_id = $this->ExtractMatch($match);
 
#    $this->DebugPrint("{$caller_id}");  
 
     if ($this->SearchURL($url, '=class\=\"locality\"*>(.*)</span>=siU', $match1))
$caller_id .= " - ";
$caller_id .= $this->ExtractMatch($match1);
#                $caller_id .= " - {$thenumber}:";
# $caller_id .= $thenumber;

#    $this->DebugPrint("{$caller_id}");
}
        return($caller_id);
    }

}

freepbx: abilitare motore di sintesi vocale googleTTS

-scaricare il file perl da http://zaf.github.io/asterisk-googletts/ decomprimerlo e copiare il file googletts.cli. pl in /var/lib/asterisk/agi-bin
-entrare in ssh, dare chmod 777 e chown asterisk:asterisk al file e poi lanciarlo: se da errori di moduli perl mancanti, installare gli stessi da yum
-dare ilcomando di test per vedere se ci sono errori perl ./googletts-cli.pl -t "test sintesi" -o test.wav
-se la console da come errore un errore su HTTPS "Crypt::SSLeay or IO::Socket::SSL not installed"
dare i seguenti comandi
perl -MCPAN -e shell
install IO::Socket::SSL
rispondere si alle domande e terminare la configurazione di perl

-editare il file propolys-tts.agi modificando la sezione switch come segue

switch ($engine) {
        case 'text2wave':
                exec($enginebin." -f 8000 -o $wavefile $voice $textfile");
                break;
        case 'flite':
                exec($enginebin." -f $textfile -o $wavefile");
                break;
        case 'swift':
                exec($enginebin." -p audio/channels=1,audio/sampling-rate=8000 -o $wavefile -f $textfile");
                break;
        case 'googleTTS':
                exec($enginebin." -l it -f $textfile -r 8000 -o $wavefile");
                break;
        default:
        }

-aprire freepbx e andare in settings -> text to speech engines, cliccare su "add engine" dare come nome al  motore googleTTS e mettere /var/lib/asterisk/agi-bin/googletts-cli.pl come percorso poi salvare

-andare in application -> text to speech e scegliere nella tendina choose an engine il motore google appena aggiunto. se la tendina è vuota si deve disinstallare e reinstallare il modulo text to speech da admin -> module admin.
nel campo text scrivere il testo che si vuole sia letto: FONDAMENTALE SCRIVERE IL TESTO SENZA PREMERE INVIO, IN CASO CONTRARIO LA SINTESI NON FUNZIONERA'.

la linea di codice  exec($enginebin." -l it -f $textfile -r 8000 -o $wavefile"); comprende il parametro della lingua. pertanto inserendo piu volte il motore con nomi diversi e aggiungendo case ulteriori con diverse lingue è possibile realizzare annunci multilingua 


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...