Re: Please support run command script Perl for Junos on HP NA (1142 Views)
Reply
Regular Visitor
titandng
Posts: 5
Registered: ‎10-31-2012
Message 1 of 12 (1,222 Views)

Please support run command script Perl for Junos on HP NA

Hi all,

I currently use one script to apply for Junos devices:

###########

 

use Socket;
$iaddr = gethostbyname("$tc_device_ip$");
$telnet_port = 23;
$sin = sockaddr_in( $telnet_port, $iaddr );
socket( DEV, PF_INET, SOCK_STREAM, getprotobyname('tcp') );
connect( DEV, $sin ) || die "Can't connect to $tc_device_hostname$: $!\n";
sendln("");
sendln("$tc_device_username$");
sendln("$tc_device_password$");

sendln("");
sendln("exit");
close(DEV);
exit;

sub sendln {
my ($line) = @_;
$line .= "\n";
syswrite(DEV,$line,length($line));
while (<DEV>) {
print;
die "Failed to execute command\n"
if (/\% (Unrecognized|Invalid|.*uthorization failed)/);
last if (/name:/ ||
/word:/ ||
/>/ ||
/\#/);
}
}

 

 

###########

But, the implementation is not done

with this script, I have good application for using Cisco IOS devices

 

Thanks

titandnd

HP Expert
traian_vila
Posts: 81
Registered: ‎05-16-2012
Message 2 of 12 (1,215 Views)

Re: Please support run command script Perl for Junos on HP NA

Hi titandnd,

 

If you need to extend this script, I suggest you to start with a more consistent one (in terms of error handling and modules use), automatically converted by NA from a device session.

Please try to do the following:

1. In NA select a Juniper device (using a Junos driver) you need to run the script against.
2. Connect via Proxy using telnet or SSH.
3. Issue on the device a simple show command.
4. Close the session.
5. Then go to Device home page, View Telnet/SSH Sessions, choose the last one, click “View Full Telnet/SSH session” and then on the right of the screen choose “Convert to Perl Script”. Give it a name and hit save.

This would be a good script to start with. For details about how to properly use the NA perl API please consult the following document (it's for the latest NA 9.20 version but you can choose it for your current one):

 

http://support.openview.hp.com/selfsolve/document/KM1401806/binary/NA9.20_API%20Reference.pdf

 

Kind regards,

Traian

HP Network Automation
Technical Solutions Consultant
Occasional Visitor
ndphuitc
Posts: 1
Registered: ‎11-05-2012
Message 3 of 12 (1,199 Views)

Re: Please support run command script Perl for Junos on HP NA

Thanks for feedback,

I have followed your instructions,  have created a simple script file for the following Juniper router:

#############

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Opsware::NAS::Connect;

my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');
my $device = '#$tc_device_id$';
my @output;

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port);

$con->login();
$con->connect( $device ) or die "Failed to connect.";

$con->cmd("terminal length 0");

 
print "\n";
@output = $con->cmd("");
print join("\n", @output);

#print "ping 10.192.0.11\n";
#@output = $con->cmd("ping 10.192.0.11");
#print join("\n", @output);


 
@output = $con->disconnect();

$con->logout();
undef $con;
exit(0);

##############

 

However, when performing this script, NA error message as follows:

timed-out waiting for command prompt at C:/Perl/site/lib/Opsware/NAS/Connect.pm line 955

 


Session log:
Created temporary file C:\WINDOWS\TEMP\t081555.t180
Executing command: C:\perl\bin\perl.exe C:\WINDOWS\TEMP\t081555.t180
timed-out waiting for command prompt at C:/Perl/site/lib/Opsware/NAS/Connect.pm line 955
Deleted temporary file  C:\WINDOWS\TEMP\t081555.t180

....

Best Ragards

 

HP Expert
traian_vila
Posts: 81
Registered: ‎05-16-2012
Message 4 of 12 (1,191 Views)

Re: Please support run command script Perl for Junos on HP NA

Hello,

 

What NA version are you running ? (Admin - Help - About HP Network Automation).

Also please let us know what driver is assigned for this Juniper device in View - Device Detail - Device Home.

 

Thank you,

Traian

HP Network Automation
Technical Solutions Consultant
Regular Visitor
titandng
Posts: 5
Registered: ‎10-31-2012
Message 5 of 12 (1,185 Views)

Re: Please support run command script Perl for Junos on HP NA

HI,

I am using HP NA version 9.10

Junos driver is used as follows: Juniper routers, EX series switches, OS version 5.5, 6.x, 7.x, 8.x, 9.x

Thanks for support

Best ragards

HP Expert
traian_vila
Posts: 81
Registered: ‎05-16-2012
Message 6 of 12 (1,178 Views)

Re: Please support run command script Perl for Junos on HP NA

Hi,

 

Please remove the following line, it is a Cisco command and I suspect that's the place where it hangs (this was automatically inserted by NA while it was converting the device session):

 

$con->cmd("terminal length 0");

 

If you still have problems please insert the following debug option in the script:

 

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port, -debug => 25);

 

Run the script with "Store complete session log enabled" and send us the whole task session log.

 

Kind regards,

Traian

HP Network Automation
Technical Solutions Consultant
Regular Visitor
titandng
Posts: 5
Registered: ‎10-31-2012
Message 7 of 12 (1,176 Views)

Re: Please support run command script Perl for Junos on HP NA

Hi Traian vila,

I've been following your support, with the following script:

 

#######################

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Opsware::NAS::Connect;

my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');
my $device = '#$tc_device_id$';
my @output;

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port, -debug => 25);

$con->login();
$con->connect( $device ) or die "Failed to connect.";


print "\n";
@output = $con->cmd("");
print join("\n", @output);

#print "ping 10.192.0.11\n";
#@output = $con->cmd("ping 10.192.0.11");
#print join("\n", @output);



@output = $con->disconnect();

$con->logout();
undef $con;
exit(0);

###############

However, faulty implementation is as follows:

 

--- Created new Opsware::NAS::Connect object, id=2 with conntype=__TELNET__
--- RESET prompt rx to: (?^m:^(?:ONA|NAS|CWNCM|NCM|NA)\>\s*$)
timed-out waiting for command prompt at C:/Perl/site/lib/Opsware/NAS/Connect.pm line 955




Session log:
Created temporary file C:\WINDOWS\TEMP\t171659.t159
Executing command: C:\perl\bin\perl.exe C:\WINDOWS\TEMP\t171659.t159 
--- Created new Opsware::NAS::Connect object, id=2 with conntype=__TELNET__
--- RESET prompt rx to: (?^m:^(?:ONA|NAS|CWNCM|NCM|NA)\>\s*$)
timed-out waiting for command prompt at C:/Perl/site/lib/Opsware/NAS/Connect.pm line 955
Deleted temporary file  C:\WINDOWS\TEMP\t171659.t159

 

Thanks very much

Best ragards

 

HP Expert
traian_vila
Posts: 81
Registered: ‎05-16-2012
Message 8 of 12 (1,172 Views)

Re: Please support run command script Perl for Junos on HP NA

Hi,

 

It looks like the script is not able to connect to NA proxy with telnet.

Can you please check in Admin - Administrative Settings - Telnet/SSH - Telnet Server what is the Telnet Server Port filled there.

On the NA Windows sever, open a cmd and try to connect with telnet to localhost on the above port: telnet localhost 23 (or 8023).

 

Let us know what is the output.

 

Also please send us the troubleshoot.zip bundle: Go to Admin->Troubleshooting, click "Download Troubleshooting Information" or click "Send Troubleshooting information" and check all options including "Wrapper logs including the last 0 historical files.

 

Thank you,

Traian

HP Network Automation
Technical Solutions Consultant
Regular Visitor
titandng
Posts: 5
Registered: ‎10-31-2012
Message 9 of 12 (1,168 Views)

Re: Please support run command script Perl for Junos on HP NA

Hello,

 

I checked the telnet server configuration parameters in the Administrator menu, and find the correct configuration parameters (image attached).
I also have download file your troubleshooting as requested, hope it will help in your support for me
Thanks very much

 Best Ragards

HP Expert
traian_vila
Posts: 81
Registered: ‎05-16-2012
Message 10 of 12 (1,154 Views)

Re: Please support run command script Perl for Junos on HP NA

Hello,

 

What happens when you try to connect to localhost with telnet ?

- from the NA Windows server machine, open a cmd and send the following command: "telnet localhost"

 

If you cannot connect to the NA proxy, most probably it is an environmental problem (telnet port 23 blocked maybe).

If you are able to connect and you get the "NA Login:" please open a support case and we will investigate it further.

 

Thank you,

Traian

HP Network Automation
Technical Solutions Consultant
Regular Visitor
titandng
Posts: 5
Registered: ‎10-31-2012
Message 11 of 12 (1,152 Views)

Re: Please support run command script Perl for Junos on HP NA

Hi,

I have successfully telnet from the client to the NA server(attach file), So connected to Port 23 to the NA server was ok

Please help me to do the next

Thank very much

 

HP Expert
traian_vila
Posts: 81
Registered: ‎05-16-2012
Message 12 of 12 (1,142 Views)

Re: Please support run command script Perl for Junos on HP NA

Hi,

 

Try to use the NA server IP instaed of localhost in the connect part:

 

my($host, $port, $user, $pass) = ('10.192.67.24','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');

 

Please open a support case as we will need to do a thorough investigation.

 

Thank you,

Traian

HP Network Automation
Technical Solutions Consultant
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.