login | register
Mon 06 of Oct, 2008 [18:40 UTC]

voip-info.org

History

Polycom reboot hardphone script

Created by: mflorell,Last modification on Thu 16 of Nov, 2006 [21:10 UTC] by dayssincethedoor
You can download the perl script here:

http://www.freedomphones.net/polycom/files/PolyReboot.pl-script

See here for revised version.

With an IP address as a single argument, this script will reboot the Polycom
500 or 600 phone with that IP address.

You must have a cfg file in the Polycom style, i.e., 00ab00cd00ef.cfg - all
lower case. Further, you need to use ftp for your remote cfg loading,
because with ftp synchronization, the phones check the ctimes of the cfg
files against what's in their cache when receiving a check-sync in order to
determine if rebooting is necessary. With tftp synchronization, this script
won't work.

I tested this script. It works on my Polycoms. I have the latest bootrom
and the SIP 1.1.0 software version.

As written this script must be executed on the FTP server.

CVS-HEAD-03/08/05 and Polycom SIP version 1.5.2


I'm not sure when they were interduced, but the above are the versions I'm using and tested.
In your sip.cfg make sure that:

voIpProt.SIP.specialEvent.checkSync.alwaysReboot="1" is set to 1 (0 will only reboot if files on the FTP server have
changed)

In your /etc/asterisk/sip_notify.conf make sure you have:

[polycom-check-cfg]
Event=>check-sync
Content-Length=>0

now on the CLI you can enter:
sip notify polycom-check-cfg xxxx
where xxx is the sip account in sip.conf

This will work even if you don't use an FTP server with the Polycom phones.

Rebooting Polycom Phones from within a dialplan


You can use this from within a dailplan as well. Make sure to pick a password that is very secure. Seems silly to have to call asterisk from itself inorder to do this but it works. I have 200 polycom phones with extensions from 3000 to 3199. This loops through and tells them all to reboot. On an opteron system this takes about 30 seconds to send all the messages out. This is very useful if you have a bunch of phones and are rolling out new features. I either do this late at night or page everyone and let them know an hour before hand.

; Extension RESETPHONES (73738746637) - resets all polycom phones from 3000 - 3199
exten => 73738746637,1,Answer()
exten => 73738746637,2,Authenticate(65) ;get the password
exten => 73738746637,3,Playback(queue-holdtime) ;let them know it will take a while
exten => 73738746637,4,Playback(digits/30)
exten => 73738746637,5,Playback(queue-seconds)
exten => 73738746637,6,Set(COUNT=0) ;start counting
exten => 73738746637,7,GotoIf($["${COUNT}" = "${CALLERID(num):1}"]?9) ;dont reboot the caller... yet
exten => 73738746637,8,System(/usr/sbin/asterisk -rx "sip notify polycom-check-cfg 3${COUNT}") ;reboot a phone
exten => 73738746637,9,Set(COUNT=${MATH(${COUNT}+1,i)}) ;increment the count
exten => 73738746637,10,GotoIf($["${COUNT}" != "200"]?7) ;check if we have rebooted the 200 phones
exten => 73738746637,11,Playback(tt-weasels) ;let them know something happened
exten => 73738746637,12,Playback(queue-thankyou)
exten => 73738746637,13,System(/usr/sbin/asterisk -rx "sip notify polycom-check-cfg ${CALLERID(num)}") ;reboot the caller
exten => 73738746637,14,Hangup()

This would be much cleaner and probably faster if there was a command that you could pass an notify event and a phone and would send it out. Something like SipNotify(). At present this has to make a socket connection to asterisk for each phone which takes some time. If you have maybe 20 - 30 phones the "sip notify" command in the CLI can take mulitple peers but you cannot pass an argument longer than 256 characters to it.

You can also reboot individual phones like so:

;Extension RESET30XX (7373830XX) - resets a particular phone in the range 3000 - 3099
exten => _7373830XX,1,Answer()
exten => _7373830XX,n,Authenticate(45376)
exten => _7373830XX,n,System(/usr/sbin/asterisk -rx "sip notify polycom-check-cfg ${EXTEN:5}")
exten => _7373830XX,n,Hangup()

;Extension RESET31XX (7373831XX) - resets a particular phone in the range 3100 - 3199
exten => _7373831XX,1,Answer()
exten => _7373831XX,n,Authenticate(45376)
exten => _7373831XX,n,System(/usr/sbin/asterisk -rx "sip notify polycom-check-cfg ${EXTEN:5}")
exten => _7373831XX,n,Hangup()

This is useful if need to change some settings on a phone, for instance when a new employee comes. You can make the changes on the provisioning server, then reboot the phone without having to go to a remote office.

If you want the phones to always reboot make sure to set

voIpProt.SIP.specialEvent.checkSync.alwaysReboot="1"

in the sip.cfg file, otherwise set

voIpProt.SIP.specialEvent.checkSync.alwaysReboot="0"

and they will only reboot when the config files change on your provisioning server.

Rebooting Polycom phones from a closed Asterisk PBX


For those people who do not have access to the Asterisk CLI (ie Switchvox) the following script will give you the ability to still reboot your Polycom phones, as long as they are provisioned. This script MUST be executed on your provisioning server. If you use this script, remember to change the 3 variables towards the top to reflect your setup.

Image


The above script assumes that you're using firmware 2.0.*
Simply touching the cfg file is no longer enough for the phone to reboot, as the phone will checksum all the cfg files before it reboots.


Polycom Phones


Comments

Comments Filter
222

333Re: Re: Reboot script..revised

by bmacauley, Saturday 17 of September, 2005 [20:45:43 UTC]
there was a slight bug...here is the corrected version...

  1. !/usr/bin/perl -w

use Net::Ping;
use Socket;

$polycompath = '/home/poly/'; # Where you keep your polycom files
$arp = '/usr/sbin/arp'; # Location of arp command
$sipserver = '192.168.52.1'; # IP of asterisk server

$phone = shift;

checkphone("$phone");
touch( arp2config("$phone") );
$thisextension=get_extension($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 () {
        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) {
$extension=$testline;
          if ( $testline =~m{$_0}){
            $extension =~ m{(^.*)/};
            $extension = $1
            last;
        }
    }
print "extension: $extension\n";
    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:
To:
Event: check-sync
Date: $httptime
Call-ID: $call_id\@$local_ip
CSeq: 1300 NOTIFY
Contact:
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 );
print "SIP message sent:\n$MESG\n";
    if ( send( SOCKET, $MESG, 0, $hispaddr ) ) {
        print "reboot of phone ", "$phone_ip", "(extension:","$extension",")"," was successful", "\n";
    }
    else { print "reboot of phone ", "$phone_ip", " failed", "\n"; }

}
exit;
222

333Re: Reboot script..revised

by bmacauley, Saturday 17 of September, 2005 [20:42:55 UTC]
I had quite a few problems getting this script(s) to work on Asterisk-1.0.7 on Debian 3.1.
On further investigation it turned out that the regex routine in the 'get_extension' sub-routine wasn't picking up the extension number. Also the arp command on Debian is in the '/usr/sbin/ directory.

My revised script is as follows...

  1. !/usr/bin/perl -w

use Net::Ping;
use Socket;

$polycompath = '/home/PlcmSpIp/'; # Where you keep your polycom files
$arp = '/usr/sbin/arp'; # Location of arp command
$sipserver = '192.168.52.1'; # IP of asterisk server

$phone = shift;

checkphone("$phone");
touch( arp2config("$phone") );
$thisextension=get_extension($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 () {
        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) {
$extension=$testline;
          if ( $testline =~m{$_0}){
            $extension =~ m{(^.*)/};
            last;
        }
    }
print "extension: $extension\n";
    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:
To:
Event: check-sync
Date: $httptime
Call-ID: $call_id\@$local_ip
CSeq: 1300 NOTIFY
Contact:
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 );
print "SIP message sent:\n$MESG\n";
    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;

222

333Easy Reboot Script

by TheAeroGroup, Saturday 07 of May, 2005 [05:13:39 UTC]
The version of asterisk I am running (Asterisk CVS-HEAD-04/27/05-08:07:15) has the capability to reboot phones built right in.

-- sip_notify.conf --

; Reboot Polycom Phone
polycom-check-cfg
Event=>check-sync
Content-Length=>0

; Untested (Reboot Sipura Phone)
sipura-check-cfg
Event=>resync
Content-Length=>0

; Untested (Reboot GrandStream Phone)
grandstream-check-cfg
Event=>sys-control

; Untested (Reboot Cisco Phone)
cisco-check-cfg
Event=>check-sync
Content-Length=>0

-- At the Asterisk Console do the following...

  • CLI> sip notify polycom-check-cfg xxx

where xxx is the peer name


Note: xxx-check-cfg are all contexts in brackets.