Connecting Tech Pros Worldwide Forums | Help | Site Map

is there a perl mechanism to ping a network element before issuing SNMP commands?

Newbie
 
Join Date: Feb 2008
Posts: 12
#1: Mar 14 '08
Since I found the site by googling, I will post a new question in addition to my follow-on response, with belief it will aid others. And increased crossing of fingers it will aid in receiving a response.

Cutting to the chase.....

i can use a system call to issue a ping to network element easily enough

Ie, system("/directory1/directory2/command like i was in CLI");

how can i harvest the response from the remote element to logically decide the next move?

am i on the right track in thinking you can use the if or else logic with a command line response?


Hutch

numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,571
#2: Mar 14 '08

re: is there a perl mechanism to ping a network element before issuing SNMP commands?


Quote:

Originally Posted by hutch75

Since I found the site by googling, I will post a new question in addition to my follow-on response, with belief it will aid others. And increased crossing of fingers it will aid in receiving a response.

Cutting to the chase.....

i can use a system call to issue a ping to network element easily enough

Ie, system("/directory1/directory2/command like i was in CLI");

how can i harvest the response from the remote element to logically decide the next move?

am i on the right track in thinking you can use the if or else logic with a command line response?


Hutch

Have you searched CPAN to see what modules are available? You may find one that will work for you.

Regards,

Jeff
Newbie
 
Join Date: Feb 2008
Posts: 12
#3: Mar 14 '08

re: is there a perl mechanism to ping a network element before issuing SNMP commands?


Thanks Mate, I was trying to steer clear of any modules. The SA won't allow any use of XYZ beyond basic perl functionality. Don't ask my=[me]-edit why. I'm just wearing the development hat as a one-off here.

Just looking for basic perl functionality to do the task at hand.

Cheers,

Hutch
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,571
#4: Mar 14 '08

re: is there a perl mechanism to ping a network element before issuing SNMP commands?


Quote:

Originally Posted by hutch75

Thanks Mate, I was trying to steer clear of any modules. The SA won't allow any use of XYZ beyond basic perl functionality. Don't ask my=[me]-edit why. I'm just wearing the development hat as a one-off here.

Just looking for basic perl functionality to do the task at hand.

Cheers,

Hutch

Well then, you have only a couple of choices.

First, you could just use the system function to ping the remote host:

Expand|Select|Wrap|Line Numbers
  1.  
  2. system("pint remote_host");
  3.  
or, you could download the a module that can do what you are looking for and copy the code out of it directly and use it that way (that way you don't have to install the module).

Choice is yours.

Regards,

Jeff
Newbie
 
Join Date: Mar 2008
Posts: 2
#5: Mar 14 '08

re: is there a perl mechanism to ping a network element before issuing SNMP commands?


How about:

Expand|Select|Wrap|Line Numbers
  1. use Net::Ping;
  2. $host="myServer";
  3. $p = Net::Ping->new();
  4. if($p->ping($host)){
  5.   print "$host is alive.\n";
  6. }else{
  7.   print "$host is down.\n";
  8. }
  9. $p->close();
Reply