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

Network Change & Configuration Management

Reply
Highlighted
Accepted Solution

CCS script to collect DATA from different devices and process them

Posts: 8
10570     0

Hello, I would need to recover i.e. MAC list from a switch and compare them with similar output ind a second device, 

 

I can't run a script against more than one device so,

Is it possble to check a value found on first device, on second one, in a recursive way?

 

I.E. I run a script to get MAC list from device A. OK. I can [[capture]] every MAC, but now I need to check that MAC (every one) on a second device.

 

Is that possible with CCS scriptoing?

 

(I've seen I could write MAC list from first script to a file, but seem is not possible to "read" that filefor second stage.)

 

Thanks in advance.

 

Highlighted

Re: CCS script to collect DATA from different devices and process them

Authority
Posts: 30
10571     0

Instead of writing to a file... you should be able to write the data into either custom data fields in NetMRI, or a NetMRI List, both should then be something you can check against in the follow-on script.

Highlighted

Re: CCS script to collect DATA from different devices and process them

Posts: 8
10571     0

But first output from script is dynamic. I mean I do not have a static list to check it against.

 

I had to connect to device A, "fill" that list, and on that script or another one, connect to a device B and check against that filled list.Is that possible?

 

Regards.

Highlighted

Re: CCS script to collect DATA from different devices and process them

Authority
Posts: 30
10571     0

May depend on whether there is a repeatable pattern to compare device B to the correct device A... but all the data from device A can be listed in the "list" with the Device A key value for look up or placed in Device's A NetMRI database record as a custom data field, which allows unique data per individual device.

Better approach:  If it is always two devices you are comparing at a time, use the feature in the Perl scripting library that allows a single job session to connect to 2 or more devices simultaneaously and compare data from each and/or take action on 1 or both (or neither).  I am not a programmer to know the commands and usage, but the capability is there as a function in a packaged NetMRI perl library.

 


@CSánchez-Barbud wrote:

But first output from script is dynamic. I mean I do not have a static list to check it against.

 

I had to connect to device A, "fill" that list, and on that script or another one, connect to a device B and check against that filled list.Is that possible?

 

Regards.



ands, but the features is in that library prepackaged in NetMRI.

Highlighted

Re: CCS script to collect DATA from different devices and process them

Authority
Posts: 32
10571     0

@Lou_Nardo is correct -- It is not possible for a single CCS script to run commands on more than one target device, and it seems like it would be non-trivial to use Lists to accomplish your goal.  Best bet is to use the Perl API.  You can use the "dis_session" and "cli_connection" brokers to manually open and close connections to the desired devices.

 

It can get pretty intricate, as there are a lot of different failure conditions that you probably would want a robust script to check for -- but the "short version" looks something like this:

 

use NetMRI::API::Client;
 
my $netmri = new NetMRI::API::Client ({
	api_version => 3,
        UserName => $http_username,
        Password => $http_password,
        URL => $api_url
});

print "+++ Creating DIS Session...\n";
my $session_id = $netmri->broker->dis_session->open ({
     job_id => "$job_id"
})->{dis_session}->{SessionID};

print "+++ Opening CLI Connection to device...\n";
$netmri->broker->cli_connection->open ({
     id => $session_id,
     device_id => $device_id
});

print "+++ Sending command...\n";
$response = $netmri->broker->cli_connection->send_command (
     id => $session_id,
     device_id => $device_id,
     command => "show version"
)->{command_response};
print "\n\nReceived data from device:\n$response\n\n";

print "+++ Closing CLI connection...\n";
$netmri->broker->cli_connection->close ({
     id => $session_id,
     device_id => $device_id
});

print "+++ Closing DIS Session...\n";
$netmri->broker->dis_session->close ({
     id => $session_id
});

You could then essentially repeat the same process for a different device, save the output to a different variable, and compare/parse them in whatever ways you wanted to.

Highlighted

Re: CCS script to collect DATA from different devices and process them

Adviser
Posts: 353
10571     0

You can also create multiple NetMRI_Easy instances that connect to different devices. There is a demo on how to do that in the Perl Tutorial.

 

https://your-netmri/api/docs/tutorial

 

It is the second-to-last tutorial in there is "Connecting to Multiple Devices in a Script". 

 

John

 

Highlighted

Re: CCS script to collect DATA from different devices and process them

Posts: 8
10571     0

Thanks very much. It's a very good starting point for me.

Highlighted

Re: CCS script to collect DATA from different devices and process them

Authority
Posts: 32
10571     0

John is right, using NetMRI_Easy is much more straightforward than what I was proposing.  Really shouldn't need to use NetMRI::API directly unless you're doing things that can't be done using NetMRI_Easy.  :-)

 

Highlighted

Re: CCS script to collect DATA from different devices and process them

Expert
Posts: 127
10571     0

John - Does that tutorial script run for you?  It won't for me.  It always fails when opening the session for the first neighbor.  Here is the error I get -

 

2016-11-07 21:17:21 [INFO ] *** e-ntac-gold-drt03*** [error] 2016-11-07 21:17:33 [ERROR ] ERROR: 'SERVER general/cli-error Device handler init for device 8580947 failed: api_open_session failure, buf: *** ERROR: Connection closed by foreign host *** http://netmri/api/3/cli_connections/open.json at /mnt/host/lib/NetMRI_Easy.pm line 732 '

 

I've tried different devices, logged into each manually to make sure it was nothing wrong with the router.

 

If you get a chance can you try the script out on your test system and see if it works?  Any diection here would be helpful.  I know Rahul struggled with this also and never got it to work.

 

Thanks.

Highlighted

Re: CCS script to collect DATA from different devices and process them

Adviser
Posts: 353
10571     0

I just tried it and it worked for me. See attached.

 

One thing - you should try not to run it against two devices that are neighbors of one another at the same time. If you do, there is a chance for a deadlock condition since we only allow one connection to a device at a time.

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You