Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

Network Change & Configuration Management

Reply
Highlighted
Accepted Solution

How to skip unreachable device during script run?

Authority
Posts: 40
7238     0

Hi All,

Is it possible to skip devices, which are determined as "Unreachable" in the last 24 hours, during script run?

I get a few errors when netmri tries to log in to the device and results in an "timeout waiting for device" error.

Those devices are mostly decommissioned.

 

I understand that netmri holds the information in its database for a certain number of days and I wouldn't want to change that setting.

 

Thanks,

Rahul

 

 

 

 

Highlighted

Re: How to skip unreachable device during script run?

Posts: 75
7239     0

I have the same problem and I also don't want to modify the global settings for when a device is removed from the database.  Have you tried updating the groups you are running the script against?

 

Susan

Highlighted

Re: How to skip unreachable device during script run?

Authority
Posts: 40
7239     0

Hi Susan,

Not sure what you mean by "updating" the group. I schedule a job for all devices which failed for a particular "Issue"/"policy-compliance". There needs to be a way to filter/exclude performing policy compliance on unreachable devices.

 

Thanks,

Rahul

Highlighted

Re: How to skip unreachable device during script run?

[ Edited ]
Adviser
Posts: 53
7239     0

Unfortunately, there isn't a simple way to accomplish this. That said, you could accomplish this with a Perl script by doing the following:

 

1. Set the Script-Login attribute to false (instructs the job engine not to auto-login to the device).

2. Inside the script, ping the device to verify it is up.

3. If up, manually establish the device connection (vs. having the job engine auto-bootstrap things).

 

Following is an example that demonstrates the concept – please note, this has not been tested.

 

Thanks,

- Chris

 

 

# BEGIN-SCRIPT-BLOCK

#

# Script-Filter: $Vendor == "Cisco"

# Script-Login:  false

#

# END-SCRIPT-BLOCK

 

use NetMRI_Easy;

use NetMRI::API;

 

#

# Try to ping the device to determine if it is up or down

#

 

my $status = system("ping -n -c 1 $ipaddress");

 

if($status) {

   print "The device is down...";

 

   #

   # Note, the following line will cause the job to end and the job status will be marked as OK

   #

 

   exit(0);

}

 

#

# Otherwise, the device is up so estabilsh a connection and execute the command "show version"

#

 

my $netmri = new NetMRI_Easy;

 

my $device = $netmri->device;

 

my $dis = $netmri->broker->dis_session->open({

   DeviceID => $device->DeviceID,

   job_id => 0})->{dis_session};

 

my $cli = $netmri->broker->dis_session->open_connection({

   DeviceID => $device->DeviceID,

   id => $dis->SessionID});

 

my $response = $netmri->broker->cli_connection->send_command({

   id => $dis->SessionID,

   DeviceID => $device->DeviceID,

   command => "show version"});

 

$netmri->broker->dis_session->close({

   id => $dis->SessionID});

 

 

Highlighted

Re: How to skip unreachable device during script run?

Authority
Posts: 40
7239     0

Hi Chris,

Thanks for the solution. This would certainly help.

I need to test this..But I believe once you have a netmri_easy object created, the moment you issue

$easy->send_command(), the necessary session and connection are automatically established.

 

Thanks,

Rahul

Highlighted

Re: How to skip unreachable device during script run?

[ Edited ]
Adviser
Posts: 53
7239     0

That is correct, but, in the above script, the send_command takes place after the ping check for availability.

Highlighted

Re: How to skip unreachable device during script run?

Adviser
Posts: 53
7239     0

Oh never mind, I understand what you meant now. Yes, you may be able to make things more efficient - would need to test it out.

Highlighted

Re: How to skip unreachable device during script run?

Adviser
Posts: 353
7239     0

The only problem with this is that if a device is just down due to some intermittent issue, this will still execute as OK.

 

If you want to filter out the devices that have only not been reachable for some amount of time (say 24 or more hours) then you could look at the data collection status for the device:

 

 

my $dc = $device->data_collection_status->{data_collection_status};

 my $ts = $dc->SystemTimestamp;

 # $ts now has the timestamp of the last time system MIB was polled in yyyy-mm-dd hh:mm:ss format
# you can exit with an error if it is, say, in the last 24 hours
# and exit(0) otherwise

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You