X-UIDL: 1087444852.59418
X-Mozilla-Status: 0011
X-Mozilla-Status2: 00000000
Return-Path: <asterisk-users-bounces@lists.digium.com>
Received: from lists.digium.com (digium-69-16-138-164.phx1.puregig.net [69.16.138.164])
	by rocket.dynx.net (8.12.11/8.12.11) with ESMTP id iAT5jgK7002258
	for <pchammer@dynx.net>; Sun, 28 Nov 2004 21:45:43 -0800
Received: from [69.16.138.164] (localhost [127.0.0.1])
	by lists.digium.com (Postfix) with ESMTP
	id 328312FE873; Mon, 29 Nov 2004 00:26:42 -0600 (CST)
X-Original-To: asterisk-users@lists.digium.com
Delivered-To: asterisk-users@lists.digium.com
Received: from psmtp.com (exprod5mx115.postini.com [64.18.0.87])
	by lists.digium.com (Postfix) with SMTP id 720B92FE870
	for <asterisk-users@lists.digium.com>;
	Mon, 29 Nov 2004 00:26:40 -0600 (CST)
Received: from source ([69.53.58.186]) by exprod5mx115.postini.com
	([64.18.4.10]) with SMTP; Mon, 29 Nov 2004 01:26:43 EST
Received: (qmail 25773 invoked by uid 0); 29 Nov 2004 00:26:42 -0600
X-Remote-IP: 64.216.18.201
Received: from adsl-64-216-18-201.dsl.snantx.swbell.net (HELO ?192.168.1.2?)
	(64.216.18.201)
	by netserver.listbrokers.com with SMTP; 29 Nov 2004 00:26:42 -0600
Message-ID: <41AAC198.6070006@listbrokers.com>
Date: Mon, 29 Nov 2004 00:28:40 -0600
From: John Baker <JohnB@listbrokers.com>
Organization: List Brokers, Inc.
User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Asterisk Users Mailing List - Non-Commercial Discussion <asterisk-users@lists.digium.com>
Subject: Re: [Asterisk-Users] Polycom Reboot Script  PRI errors!!
References: <001701c4d5c8$e29a3930$2c02a8c0@gtcp4>
In-Reply-To: <001701c4d5c8$e29a3930$2c02a8c0@gtcp4>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-pstn-levels: (S:99.90000/99.90000 )
X-pstn-settings: 1 (0.1500:0.1500) gt3 gt2 gt1 
X-pstn-addresses: from <JohnB@listbrokers.com> [65/3] 
X-BeenThere: asterisk-users@lists.digium.com
X-Mailman-Version: 2.1.5
Precedence: list
Reply-To: Asterisk Users Mailing List - Non-Commercial Discussion <asterisk-users@lists.digium.com>
List-Id: Asterisk Users Mailing List - Non-Commercial Discussion
	<asterisk-users.lists.digium.com>
List-Unsubscribe: <http://lists.digium.com/mailman/listinfo/asterisk-users>,
	<mailto:asterisk-users-request@lists.digium.com?subject=unsubscribe>
List-Archive: <http://lists.digium.com/pipermail/asterisk-users>
List-Post: <mailto:asterisk-users@lists.digium.com>
List-Help: <mailto:asterisk-users-request@lists.digium.com?subject=help>
List-Subscribe: <http://lists.digium.com/mailman/listinfo/asterisk-users>,
	<mailto:asterisk-users-request@lists.digium.com?subject=subscribe>
Sender: asterisk-users-bounces@lists.digium.com
Errors-To: asterisk-users-bounces@lists.digium.com
X-Virus-Scanned: clamd / ClamAV version 0.73, clamav-milter version 0.73a
	on localhost
X-Virus-Status: Clean
X-Spam-Status: No, hits=0.0 required=5.0 tests=HOT_NASTY autolearn=no 
	version=2.63
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on 
	localhost.localdomain
Status: O
X-UID: 59418
Content-Length: 8273
X-Keywords:                                                                                                    

Kevin wrote:
> There is a reboot script posted on the wiki to reboot Polycom
> telephones.  When I execute this script, I get the following messages.
> I am concerned as this is causing issues with asterisk and the PRI.
> Does anyone have any ideas why this would be happening?
> 
> 
> 
> asterisk console:
> 
>     -- Remote UNIX connection
>     -- Remote UNIX connection disconnected
> 
> and in the Asterisk Log:
> 
> Nov 28 22:30:42 NOTICE[1099909936]: PRI got event: 6 on Primary
> D-channel of span 1
> Nov 28 22:43:08 NOTICE[1099909936]: PRI got event: 6 on Primary
> D-channel of span 1
> 
> 
> Script:
> 
> #!/usr/bin/perl -w
> 
> use Net::Ping;
> use Socket;
> 
> $polycompath = '/home/XXXX/';    # Where you keep your config files
> $arp         = '/sbin/arp';          # Location of arp command
> $sipserver   = '192.168.XXX.XXX';      # IP of asterisk server
> 
> $phone = shift;
> 
> checkphone("$phone");
> touch( arp2config("$phone") );
> 
> reboot_sip_phone( "$phone", "$sipserver", "Reboot" );
> 
> sub checkphone { # Checks for existence of phone, makes sure
>                  # it's in arp table
>     $activephone = shift;
> 
>     # Populate ARP table
>     print "Checking ARP table.\n";
>     $p = Net::Ping->new("icmp");
>     if ( $p->ping( $activephone, 2 ) ) {
>         print "$activephone is ";
>         print "reachable.\n";
>     }
>     else { die "Polycom at ", $activephone, " is not reachable!"; }
>     sleep(1);
>     $p->close();
> 
> }
> 
> sub arp2config {    # Gets mac address from arp table, converts
>                     # to a polycom config filename, makes sure
>                     # the config file exists
>     $arpip = shift;
>     open( ARP, "$arp -an|" ) || die "Couldn't open arp table: $!\n";
>     print "checking for polycom config name...", "\n";
>     while (<ARP>) {
>         chomp;
>         $addr = $_;
>         $ip   = $_;
>         $addr =~ s/.*
> ([\d\w]+:[\d\w]+:[\d\w]+:[\d\w]+:[\d\w]+:[\d\w]+).*/$1/;
>         $addr =~ s/://g;
>         $addr = lc($addr) . '.cfg';
>         $ip =~ s/.*?(\d+\.\d+\.\d+\.\d+).*/$1/;
>         if ( $ip eq $arpip ) {
>             last;
>         }
>     }
> 
>     $polycomconfig = "$polycompath" . "$addr";
> 
>     unless ( -e "$polycomconfig" ) {
>         print "sorry, polycom config file ", "$polycomconfig",
>           " is not found.\n\n";
>         exit;
>     }
> 
>     return $polycomconfig;
> }
> 
> sub touch {    # We need to touch the config files or the phone
>                # won't reboot - it depends on time synchronization
> 
>     print "touching config file ", $polycomconfig, "\n";
>     my $now = time;
>     local (*TMP);
>     foreach my $file (@_) {
>         utime( $now, $now, $file )
>           || open( TMP, ">>$file" )
>           || die ("$0: Couldn't touch file: $!\n");
>     }
> }
> 
> sub reboot_sip_phone {    # Send the phone a check-sync to reboot it
>     $phone_ip = shift;
> 
>     $local_ip = shift;
>     $sip_to   = shift;
>     $sip_from = "0";
>     $tm       = time();
>     $call_id  = $tm . "msgto$sip_to";
>     $httptime = `date -R`;
>     $MESG     = "NOTIFY sip:$sip_to\@$phone_ip:5060 SIP/2.0
> Via: SIP/2.0/UDP $local_ip
> From: <sip:$sip_from\@$local_ip>
> To: <sip:$sip_to\@$phone_ip>
> Event: check-sync
> Date: $httptime
> Call-ID: $call_id\@$local_ip
> CSeq: 1300 NOTIFY
> Contact: <sip:$sip_from\@$local_ip>
> Content-Length: 0
> 
> ";
> 
>     $proto = getprotobyname('udp');
>     socket( SOCKET, PF_INET, SOCK_DGRAM, $proto );
>     $iaddr = inet_aton("$phone_ip");
>     $paddr = sockaddr_in( 5060, $iaddr );
>     bind( SOCKET, $paddr );
>     $port = 5060;
> 
>     $hisiaddr = inet_aton($phone_ip);
>     $hispaddr = sockaddr_in( $port, $hisiaddr );
> 
>     if ( send( SOCKET, $MESG, 0, $hispaddr ) ) {
>         print "reboot of phone ", "$phone_ip", " was successful", "\n";
>     }
>     else { print "reboot of phone ", "$phone_ip", " failed", "\n"; }
> 
> }
> exit;
> 
> _______________________________________________
> Asterisk-Users mailing list
> Asterisk-Users@lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-users
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users
> 
> 


Kevin -

I rewrote this some time ago because of some issues with Polycom's 
latest bootroom/sip update.  Try this:

Also, serctl, part of the ser package, has a cisco_restart parameter 
that works on Polycoms as well.

John



#!/usr/bin/perl -w

use Net::Ping;
use Socket;

$polycompath = '/home/PlcmSpIp/';    # Where you keep your polycom files
$arp         = '/sbin/arp';          # Location of arp command
$sipserver   = '192.168.XXX.XXX';      # IP of asterisk server

$phone = shift;

checkphone("$phone");
touch( arp2config("$phone") );

reboot_sip_phone( "$phone", "$sipserver", get_extension($phone) );

sub checkphone {                     # Checks for existence of phone, 
makes sure
         # it's in arp table
     $activephone = shift;

     # Populate ARP table
     print "Checking ARP table.\n";
     $p = Net::Ping->new("icmp");
     if ( $p->ping( $activephone, 2 ) ) {
         print "$activephone is ";
         print "reachable.\n";
     }
     else { die "Polycom at ", $activephone, " is not reachable!"; }
     sleep(1);
     $p->close();

}

sub arp2config {    # Gets mac address from arp table, converts
                     # to a polycom config filename, makes sure
                     # the config file exists
     $arpip = shift;
     open( ARP, "$arp -an|" ) || die "Couldn't open arp table: $!\n";
     print "checking for polycom config name...", "\n";
     while (<ARP>) {
         chomp;
         $addr = $_;
         $ip   = $_;
         $addr =~ s/.* 
([\d\w]+:[\d\w]+:[\d\w]+:[\d\w]+:[\d\w]+:[\d\w]+).*/$1/;
         $addr =~ s/://g;
         $addr = lc($addr) . '.cfg';
         $ip =~ s/.*?(\d+\.\d+\.\d+\.\d+).*/$1/;
         if ( $ip eq $arpip ) {
             last;
         }
     }

     $polycomconfig = "$polycompath" . "$addr";

     unless ( -e "$polycomconfig" ) {
         print "sorry, polycom config file ", "$polycomconfig",
           " is not found.\n\n";
         exit;
     }

     return $polycomconfig;
}

sub get_extension {  # This returns the extension of the Sip
		     # phone IP address

     my @sippeers = `asterisk -rx \'sip show peers\'`;

     foreach $testline (@sippeers) {
         if ( $testline =~ m{\s+(.*?)\/.*$_[0].*}i ) {
             $extension = $1;
             last;
         }
     }
     return $extension;
}

sub touch {    # We need to touch the config files or the phone
                # won't reboot - it depends on time synchronization

     print "touching config file ", $polycomconfig, "\n";
     my $now = time;
     local (*TMP);
     foreach my $file (@_) {
         utime( $now, $now, $file )
           || open( TMP, ">>$file" )
           || die ("$0: Couldn't touch file: $!\n");
     }
}

sub reboot_sip_phone {    # Send the phone a check-sync to reboot it
     $phone_ip = shift;

     $local_ip = shift;
     $sip_to   = shift;
     $sip_from = "asterisk";
     $tm       = time();
     $call_id  = $tm . "msgto$sip_to";
     $httptime = `date -R`;
     $MESG     = "NOTIFY sip:$sip_to\@$phone_ip:5060 SIP/2.0
Via: SIP/2.0/UDP $local_ip
From: <sip:$sip_from\@$local_ip>
To: <sip:$sip_to\@$phone_ip>
Event: check-sync
Date: $httptime
Call-ID: $call_id\@$local_ip
CSeq: 1300 NOTIFY
Contact: <sip:$sip_from\@$local_ip>
Content-Length: 0

";

     $proto = getprotobyname('udp');
     socket( SOCKET, PF_INET, SOCK_DGRAM, $proto );
     $iaddr = inet_aton("$phone_ip");
     $paddr = sockaddr_in( 5060, $iaddr );
     bind( SOCKET, $paddr );
     $port = 5060;

     $hisiaddr = inet_aton($phone_ip);
     $hispaddr = sockaddr_in( $port, $hisiaddr );

     if ( send( SOCKET, $MESG, 0, $hispaddr ) ) {
         print "reboot of phone ", "$phone_ip", " was successful", "\n";
     }
     else { print "reboot of phone ", "$phone_ip", " failed", "\n"; }

}
exit;
_______________________________________________
Asterisk-Users mailing list
Asterisk-Users@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


