Big news! The community will be moving to a new platform April 21. Read more.
Big news! The community will be moving to a new platform April 21. Read more.
Vice Admiral
Vice Admiral
693 views

perl script using Opsware::NAS::Connect to connect on port 8022

I was wondering if the Opsware::NAS::Connect module can support an SSH connection to the NA proxy?

my existing scripts use the following lines: ( forcing me to keep the telnet server enabled)

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

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

I have tried using $tc_proxy_ssh_port$  but that failed.

what is the correct way to use perl scripts without using telnet to connect to the proxy?

 

0 Likes
10 Replies
Fleet Admiral
Fleet Admiral

hi @iamnoone,

if you add the -debug => 25

to the script do you see the cause of failure?, the connect.pm does support the usage of SSH,

Example:

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

BR,

Pedro A. Batista
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the THUMB at the bottom left of the post and show your appreciation.
Vice Admiral
Vice Admiral

Thanks for the -debug => 25 option, that will come in handy.

Is there a different module that already exists within NA's Perl installation that will use SSH?

My goal is to be able to run an advanced Perl script within an NA command script that does not require the Telnet proxy server to be enabled.  

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

Hi,

There are several things to consider.

1.  For the script with ssh proxy you need

- set the $port as $tc_proxy_ssh_port$

- add the option -ssh => 'true' or -ssh => 1 to 

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

 

2. Pre-requisites

 - Perl Net::SSH::Expect module installed

- if you use the new Connect.pm module Perl IO::Pty module

- NA proxy ssh enabled and listening

Cheers,

Marius Herculea

 

 

 

 

 

Marius Herculea
HP SW Technical Consultant

Cloud and Automation Professional Services

Vice Admiral
Vice Admiral

Excellent.

forgive my inexperience:  trying to load the modules but it can't find the gcc compiler. 

I don't want to break HP NA,   can you tell me the steps to load the modules (running unix HP NA) ?  do I need to intall gcc? will that impact HP NA in any way?  or is there a path to a compiler that will work?

 

0 Likes
Fleet Admiral Fleet Admiral
Fleet Admiral

Hi,

Here's a link that may be useful - though there are still more options like using yum (google yum install perl modules)

http://www.thegeekstuff.com/2008/09/how-to-install-perl-modules-manually-and-using-cpan-command/

Depending on how your sys admins / security work, you may or may not be able to use cpan, so knowing the manual option is good.  

Now, connect.pm (or client.pm) would get installed as part of NA or a patch or HF.  

The biggest key is to be patient, many (most) modules you'll be installing will have other dependencies, so if you are doing this manually, you'll find yourself having to stop the install of one module to go download another and install it and then go back to the first module.  This is why it's nice to use other tools (cpan, yum) as that can do this sort of thing for you.  But, they aren't always allowed to run in some companies / environments.  

Hope this helps,

Chris

Fleet Admiral
Fleet Admiral

I have installed the gcc compiler successfully without harming NA in any way,

I have a RedHat 5 :

[root@localhost ~]$rpm -q --whatprovides gcc
gcc-4.1.2-55.el5
gcc-4.1.2-55.el5

and a RedHat 7

[root@localhost ~]# rpm -q --whatprovides gcc
gcc-4.8.5-4.el7.x86_64
gcc-4.8.5-4.el7.x86_64

BR,

Pedro A. Batista
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the THUMB at the bottom left of the post and show your appreciation.
Vice Admiral
Vice Admiral

Thanks for the help.. The last couple posts were very helpfull.   (gcc and perl modules loaded fine!!)

I am getting closer...   I am hung up on making the SSH connection.

getting generic SSHProccessError.  I tried SSH'ing from the command line to the proxy to test. works from external (putty) but not while on the server (ssh user@na-ipaddress -p 8022) itself due to "no matching mac found"

script looks like this, just incase you see something obvious:

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

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

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

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

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

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

@output = $con->disconnect();

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

 

0 Likes
Fleet Admiral Fleet Admiral
Fleet Admiral

Just something I wanted to check, when you tried this from the server, what value did you use for the NA IP Address:

ssh user@na-ipaddress -p 8022

Try 127.0.0.1

I seem to recall having this same sort of issue - I couldn't connect to the NA Proxy when I was on the server if I used the server's IP (what I'd use for say Putty).  

When you run your script in NA, what error / message do you get?  

Maybe odd question, but have you tried or do you run any scripts that use client instead of connect?  Just curious if you're logging into the proxy but not getting to the device.  

-Chris

Vice Admiral
Vice Admiral

127.0.0.1 returns the same error.

The error from the failed script:

SSHProcessError The process was terminated. at /usr/local/share/perl5/Opsware/NAS/Connect.pm line 950

which if I'm reading it right is an If statement for a TELNET connection.

I have not used client, are they interchangeable or do I need to change the connect statement?

 

 

0 Likes
Vice Admiral
Vice Admiral

called away... I will pick it back up in the morning.....

Huge thanks for all the help so far!!!!!!!!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.