#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    7
    Rep Power
    0

    Net::Telnet not capturing all chars from Avaya Definity switch


    I am writing a basic script to talk back and forth to an Avaya Definity switch. It uses a paging terminal, emulating AT&T 513. I am sending it the same commands as I would if I telnetted manually. However it won't capture all the output in perl from the telnet handle into a variable. If I do an Output_log I get strings of numbers that don't look anything like whats going on. However if I do a Dump_log straight to hex, then I see all the info I am trying to capture. I have no idea where the '2779119' is coming from. Note that this is running on a Windows machine, Activestate perl 5.8.1, under Cygwin. Any help or insight is greatly appriciated!

    Code:
    #!perl
    #telnet interaction sctipt for Avaya Definity systems
    use strict;
    use Net::Telnet;
    
    my $loop = 1;
    my $username = 'reports';
    my $password = 'asdf1234';
    my $cancel = hex('1B') . hex('4F') . hex('77');
    my $enter_and_save = hex('1B') . hex('53') . hex('42');
    my $next = hex('1B') . hex('5B') . hex('55');
    my $prev = hex('1B') . hex('5B') . hex('56');
    
    my $t = new Net::Telnet (	Timeout => 10,
                      	Prompt => '/[:\]]/',
                      	Host => $ARGV[0],
                      	Port => $ARGV[1],
                      	Output_Log => 'telnet_dump',
                      	Dump_Log => 'dump.hex'
                      	);
    $t->open();
    
    #Login: reports
    #Password:
    $t->login(	Name=> $username,
    		Password => $password
    		);
    
    #System: G3rV11    Software Version: R011r.03.0.526.5
    #Terminal Type (513, 715, 4410, 4425, VT220): [513]
    my @lines = $t->cmd("513\n");
    print @lines;
    print "\nCOMMAND: ";
    
    while($loop){
    	#Logged in and at 'Command:'
    	my $cmd = <STDIN>;
    	chomp $cmd;
    	print "EXECUTING ($cmd)\n";
    
    	if($cmd =~ /logoff/){
    		$loop = 0;
    		last;
    	}
    	my @cmd = $t->cmd($cmd);
    
    	#This section will scroll through mutiple pages of output
    	#and place them into a single array for screen output
    	my $line = grep(/Page   1 of   1/,@cmd);
    	my $page_display = 0;
    	$page_display = 1 if ($line =~ /Page/);
    	while( $page_display ){
    		@cmd = (@cmd,$t->cmd($next));
    		my @test = grep(/Page/,@cmd);
    		$test[$#test] =~ /Page\s+(\d+)\s+of\s+(\d+)/;
    		$page_display = 0 if ($1 == $2);
    	}
    
    	@cmd = (@cmd,$t->cmd($cancel));
    	#print @cmd;
    	foreach my $x (@cmd){
    		#attempt to strip out unprintable chars???
    		$x =~ tr/\000-\011\013-\014\015-\037/ /;
    		print $x
    	}
    	print "\nCOMMAND: ";
    }
    
    #escape current command prompt
    @lines = $t->cmd($cancel);
    #execute logoff command
    @lines = $t->cmd("logoff");
    #Remote Access Administered
    #*** Busied out resource detected; verify if release is needed! ***
    #Proceed With Logoff: [n]
    @lines = $t->cmd("y");
    
    exit( $t->close() );
    Here is the text dump (telnet_dump):
    reports
    aolms77
    513


    2779119
    513
    2779119
    disp errors
    2779119
    2779119
    logoff
    y
    Here is the hex dump (I chopped off a bit):
    dump.hex
    < 0x00000: 1b 5b 31 3b 31 48 1b 5b 30 4a 0a 0d 4c 6f 67 69 .[1;1H.[0J..Logi
    < 0x00010: 6e 3a 20 n:

    > 0x00000: 72 65 70 6f 72 74 73 0d 0a reports..

    < 0x00000: 72 65 70 6f 72 74 73 reports

    < 0x00000: 0a 0d 50 61 73 73 77 6f 72 64 3a 20 ..Password:

    > 0x00000: 61 6f 6c 6d 73 37 37 0d 0a aolms77..

    < 0x00000: 20 20 20 20 20 20 20

    < 0x00000: 0a 0d 0a 0d 53 79 73 74 65 6d 3a 20 47 33 72 56 ....System: G3rV
    < 0x00010: 31 31 20 20 20 20 53 6f 66 74 77 61 72 65 20 56 11 Software V
    < 0x00020: 65 72 73 69 6f 6e 3a 20 52 30 31 31 72 2e 30 33 ersion: R011r.03
    < 0x00030: 2e 30 2e 35 32 36 2e 35 1b 5b 42 0a 0d 54 65 72 .0.526.5.[B..Ter
    < 0x00040: 6d 69 6e 61 6c 20 54 79 70 65 20 28 35 31 33 2c minal Type (513.
    < 0x00050: 20 37 31 35 2c 20 34 34 31 30 2c 20 34 34 32 35 715. 4410. 4425
    < 0x00060: 2c 20 56 54 32 32 30 29 3a 20 5b 35 31 33 5d 20 . VT220): [513]

    > 0x00000: 35 31 33 0d 0a 0d 0a 513....

    > 0x00000: 0d 0a ..

    > 0x00000: 32 37 37 39 31 31 39 0d 0a 2779119..

    > 0x00000: 35 31 33 0d 0a 513..

    < 0x00000: 35 31 33 1b 5b 32 3b 30 48 20 1b 5b 37 39 62 1b 513.[2;0H .[79b.
    < 0x00010: 5b 31 47 1b 5b 33 3b 31 48 1b 5b 30 4a 1b 5b 32 [1G.[3;1H.[0J.[2
    < 0x00020: 4a 1b 5b 32 3b 32 32 72 1b 3c 1b 5b 32 31 3b 33 J.[2;22r.<.[21;3
    < 0x00030: 7c 1b 53 42 1b 5b 31 30 3b 31 7c 1b 5b 38 3b 30 |.SB.[10;1|.[8;0
    < 0x00040: 7c 1b 5b 31 33 3b 30 7c 1b 5b 31 39 3b 31 7c 1b |.[13;0|.[19;1|.
    < 0x00050: 5b 3f 39 39 68 1b 5b 31 3b 31 48 1b 5b 30 3b 37 [?99h.[1;1H.[0;7
    < 0x002c0: 1b 5b 31 47 43 6f 6d 6d 61 6e 64 3a 20 1b 5b 32 .[1GCommand: .[2
    < 0x002d0: 34 3b 31 48 20 1b 5b 37 39 62 1b 5b 31 47 43 6f 4;1H .[79b.[1GCo
    < 0x002e0: 6d 6d 61 6e 64 3a 20 1b 5b 32 34 3b 31 48 20 1b mmand: .[24;1H .
    < 0x002f0: 5b 37 39 62 1b 5b 31 47 43 6f 6d 6d 61 6e 64 3a [79b.[1GCommand:
    < 0x00300: 20 32 37 37 39 31 31 39 1b 37 1b 5b 32 33 3b 30 2779119.7.[23;0
    < 0x00310: 48 1b 5b 30 3b 37 6d 20 1b 5b 37 39 62 1b 5b 31 H.[0;7m .[79b.[1
    < 0x00320: 47 1b 5b 30 6d 1b 5b 32 33 3b 30 48 1b 5b 30 3b G.[0m.[23;0H.[0;
    < 0x00330: 37 6d 1b 5b 30 3b 37 6d 22 32 37 37 39 31 31 39 7m.[0;7m"2779119
    < 0x00340: 22 20 69 73 20 61 6e 20 69 6e 76 61 6c 69 64 20 " is an invalid
    < 0x00350: 65 6e 74 72 79 3b 20 70 6c 65 61 73 65 20 70 72 entry; please pr
    < 0x00360: 65 73 73 20 48 45 4c 50 1b 5b 30 6d 1b 38 1b 5b ess HELP.[0m.8.[
    < 0x00370: 32 34 3b 31 48 20 1b 5b 37 39 62 1b 5b 31 47 43 24;1H .[79b.[1GC
    < 0x00380: 6f 6d 6d 61 6e 64 3a 20 ommand:

    > 0x00000: 32 37 37 39 31 31 39 0d 0a 2779119..

    > 0x00000: 64 69 73 70 20 65 72 72 6f 72 73 0d 0a disp errors..

    > 0x00000: 32 37 37 39 31 31 39 0d 0a 2779119..

    > 0x00000: 32 37 37 39 31 31 39 0d 0a 2779119..

    < 0x00220: 20 42 1b 5b 30 6d 1b 38 1b 5b 31 3b 35 38 48 1b B.[0m.8.[1;58H.
    < 0x00230: 5b 30 3b 37 6d 50 61 67 65 20 20 20 31 20 6f 66 [0;7mPage 1 of
    < 0x00240: 20 20 20 31 1b 5b 30 6d 1b 5b 32 3b 33 35 48 45 1.[0m.[2;35HE
    < 0x00250: 52 52 4f 52 20 52 45 50 4f 52 54 1b 5b 34 3b 37 RROR REPORT.[4;7
    < 0x00260: 48 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6f HThe following o
    < 0x00270: 70 74 69 6f 6e 73 20 63 6f 6e 74 72 6f 6c 20 77 ptions control w
    < 0x00280: 68 69 63 68 20 65 72 72 6f 72 73 20 77 69 6c 6c hich errors will
    < 0x00290: 20 62 65 20 64 69 73 70 6c 61 79 65 64 2e 1b 5b be displayed..[
    < 0x002a0: 35 3b 31 30 48 45 52 52 4f 52 20 54 59 50 45 53 5;10HERROR TYPES
    < 0x002b0: 1b 5b 37 3b 31 33 48 45 72 72 6f 72 20 54 79 70 .[7;13HError Typ
    < 0x002c0: 65 3a 20 1b 5b 37 3b 32 35 48 1b 5b 30 3b 34 6d e: .[7;25H.[0;4m
    < 0x002d0: 20 20 20 20 20 1b 5b 30 6d 1b 5b 37 3b 33 39 48 .[0m.[7;39H
    < 0x002e0: 45 72 72 6f 72 20 4c 69 73 74 3a 20 1b 5b 37 3b Error List: .[7;
    < 0x002f0: 35 31 48 1b 5b 30 3b 34 6d 61 63 74 69 76 65 2d 51H.[0;4mactive-
    < 0x00300: 61 6c 61 72 6d 73 20 1b 5b 30 6d 1b 5b 31 30 3b alarms .[0m.[10;
    < 0x00310: 31 30 48 52 45 50 4f 52 54 20 50 45 52 49 4f 44 10HREPORT PERIOD
    < 0x00320: 1b 5b 31 32 3b 31 33 48 49 6e 74 65 72 76 61 6c .[12;13HInterval
    < 0x00330: 3a 20 1b 5b 31 32 3b 32 33 48 1b 5b 30 3b 34 6d : .[12;23H.[0;4m
    < 0x00340: 61 1b 5b 30 6d 1b 5b 31 32 3b 33 30 48 46 72 6f a.[0m.[12;30HFro
    < 0x00350: 6d 3a 20 1b 5b 31 32 3b 33 36 48 1b 5b 30 3b

    > 0x00000: 6c 6f 67 6f 66 66 0d 0a logoff..

    > 0x00000: 79 0d 0a y..
    Last edited by rage007; March 5th, 2004 at 05:23 PM.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    1
    Rep Power
    0
    I don't know if you're still working on this or not but the numbers are coming from your hex codes. I'm not sure why hex() isn't working right. I'm working on the same sort of thing and the way I'm doing codes is below and it's getting the expected results.

    Code:
    my %control_lookup = ( "cancel"    => "\x1bOP",    #F1
                           "refresh"   => "\x1bOQ",    #F2
                           "enter"     => "\x1bOR",    #F3
                           "clear"     => "\x1bOS",    #F4
                           "help"      => "\x1bOT",    #F5
                           "goto_page" => "\x1bOU",    #F6
                           "next_page" => "\x1bOV",    #F7
                           "prev_page" => "\x1bOW",     #F8
                           "tab"       => "\t"
                           );
    P.S. Your original post sent me downt the right path for finding the escape sequences... .Thanks.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    2
    Rep Power
    0
    Hi, jackattack/rage007
    Have you found a solution to the script issue? I have used your script on linux and get the same thing happening, return data is going to the dump.hex file but not returned to the array?

    I notice that the olny thing that I can get returned is the 'Terminal Type (513, 715, 4410, 4425, VT220, NTT, W2KTT, SUNT)' so ocne a terminal type is set it is stuck in the hex dump?

    any ideas?
    thanks
    Dakka
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Portland, Oregon, USA
    Posts
    1
    Rep Power
    0
    I just found this post...I'm glad to see some other people are in the same boat, trying to get a more useful interface to the Definity switch. I have written a few Perl scripts which connect to my G3r switch and perform some simple functions. This has allowed me to automate some routine administration tasks, such as changing coverage paths and VDNs/vectors, via a web interface.

    The first version of the script used Device::SerialPort to connect to the switch via a serial Data Module. I then adapted this script to work over an IP connection. My latest version still uses the IP connection, but runs as a daemon on a Linux box. The daemon opens a Telnet session with the switch, then listens for commands on a TCP port. It's essentially a gateway between the switch and some other scripts I've written. It's still very limited and needs a lot of work, but might be a good place to start if you're not getting anywhere with your current script.

    If anyone is interested, let me know and I'll clean up the source code and send you a copy.

    I'd love to see some open-source tools for Definity switch maintenance...maybe we should create an informal users' group and start writing some tools... anyone interested?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    1
    Rep Power
    0
    Hi, I'm very insteresting on your scripts. I would like to automate some works to my Definity but I don`t really know how to make the telnet correctly. I have test the code shown in this page but it don't really works fine.
    I have some ideas but it depend on how telnet works.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    2
    Rep Power
    0
    I ended up getting the code to work, 1st major issue is that getting a session open to the terminal is extemely flakey. quite often the TCP conencts immediately but either the terminal will indicate that resources are busy, or after entering the username password it will time out.
    I ended up embedding the connection into a routine that is called by a loop, while the flags are incorrect it will keep attempting until it gets a result (also have a max count set at 10 ) some times it takes 5 attempts to get connected). Can now get a reliable connection.
    Next issue is after sending command you cannot be sure that the output will be stored into array, this resulted in using "@ret = $t->waitfor('/expr/');" for every command

    My main interest to start with was logging license levels and graphing them with RRD, this required navigating thru 5 "display capability" pages and extracting the appropriate numbers from the ANSI rubbish that gets returned, took a while but it works fine now.

    Have extended this to check certain agent logins that we use for diverting queue's, this then alerts to a NAGIOS platform.

    will keep expanding as my one off cases pop up.

    Cheers
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Talking Telnet to Avaya


    Originally Posted by rackm0unt
    I just found this post...I'm glad to see some other people are in the same boat, trying to get a more useful interface to the Definity switch. I have written a few Perl scripts which connect to my G3r switch and perform some simple functions. This has allowed me to automate some routine administration tasks, such as changing coverage paths and VDNs/vectors, via a web interface.

    The first version of the script used Device::SerialPort to connect to the switch via a serial Data Module. I then adapted this script to work over an IP connection. My latest version still uses the IP connection, but runs as a daemon on a Linux box. The daemon opens a Telnet session with the switch, then listens for commands on a TCP port. It's essentially a gateway between the switch and some other scripts I've written. It's still very limited and needs a lot of work, but might be a good place to start if you're not getting anywhere with your current script.

    If anyone is interested, let me know and I'll clean up the source code and send you a copy.

    I'd love to see some open-source tools for Definity switch maintenance...maybe we should create an informal users' group and start writing some tools... anyone interested?
    Hi rackm0unt ,

    I'm very interested about You scripting , I create a script for the wbcms historical data capture for agents , skill .
    It is very primitive , but working .
    Now I'd like to implement a script to capture the monitor bcms skill COMMAND .
    Could You give me some info , I seen You implemented scripts to make some changes into vectors etc ...

    Thanks a lot
  14. #8
  15. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    User rackm0unt posted exactly one time, and that was eight years ago. It will be very interesting to see if he replies.

IMN logo majestic logo threadwatch logo seochat tools logo