Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!
North America | Europe | Middle East/Africa | Asia-Pacific

Network Change & Configuration Management

Reply

How to check disco is completed via Perl API ?

BBaudoux
Techie
Posts: 14
5295     0

Hello,

I'm using Perl API with Network Automation to launch discoveries. API discover_now works fine, but disco takes a while to complete (as expected).

The question is: how can I get the status (still via Perl API) of a running discovery to be sure it complete before launching the next one?

It sounds like you are not

Adviser
Posts: 353
5296     0

It sounds like you are not using the "discover" API from the Devices controller, but maybe the "discover_now" API from the Discovery Statuses controller. The Device controller API is much better for scripts; the other one is really geared towards the UI. See perldoc NetMRI::API::Broker:Smiley Very Happyevice.

 

The "discover" API will give you more information and will also block until discovery completes, though you may have to set the timeout on the client if the discoveries are taking a long time (it will depend on how many credentials you have defined, etc.). See perldoc NetMRI::API for details on how to do that.

 

Thanks John,

BBaudoux
Techie
Posts: 14
5296     0

Thanks John,

I'm indeed using 'discover_now'.  When I read you, 'discover' looks more exciting.  I will give it a try.

Thanks a lot,

Bernard.

 

Does it work?

KZhou_2
Techie
Posts: 7
5296     0

Hi Bernard,

Does the solution John provided work for you? I was also looking for running discovery based on CIDR range (not the indivitaul device) using Perl API.

Really appreciated if you can share your script. My email address is kzhou@empowered.ca.

Thanks a lot.

Kevin

 

 

Here is an example for Static

Adviser
Posts: 412
5296     0

Here is an example for Static, you can change it for CIDR

my $devices = $client->broker->discovery_settings->create({
  range_value    => '10.10.10.1',
  range_type     => 'STATIC',
  discovery_status => 'INCLUDE',
});

my $discover = $client->broker->device->discover({
        ip_address      => '10.10.10.1',
});

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Hi Sif,

KZhou_2
Techie
Posts: 7
5296     0

Hi Sif,

Thanks. Since I am new to this solution, when I run the script, I was getting the following error:

NetMRI devices/discovery-failed Unable to perform initial device discovery. http://<NetMRI_IP>/api/2.9/devices/discover.json at DiscoveryDevice.pl line 34.

 

Here is my scrpt:

#!/usr/bin/perl -w

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
# true
#
# Script-Variables:
# $command word "show version"
#
# END-SCRIPT-BLOCK
use strict;
use warnings;
use NetMRI::API;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

#Authentication for connecting NetMRI-VM server
my $client = new  NetMRI::API({
       api_version => 2.9,
       url => 'http://<NetMRI_IP>',
       username => 'admin',
       password => 'xxxxxxxxxx',
});

# my $broker = $client->broker->discovery_setting;

my $devices = $client->broker->discovery_setting->create({
      range_value    => '192.168.100.15',
      range_type     => 'STATIC',
      discovery_status => 'INCLUDE',
    });

my $discover = $client->broker->device->discover({
            ip_address      => '192.168.100.15',
    });

 

 

Kevin,

BBaudoux
Techie
Posts: 14
5296     0

Kevin,

my script has never run satisfactorily.  The API returns a return code which is supposed (according to the doc) be a boolean.  The problem is that it returns a value of '5' which is not documented and which I cannot understand.

Bernard.

 

Re: Script Problems

Adviser
Posts: 53
5296     0

Hi Kevin,

Few things.

First, the script above was likely auto-croaking because the static include 192.168.100.15 already existed in the system (it should have worked on the first run though if the setting wasn't in the system yet). Many of the client API routines auto-croak on failures, which, in turn, cause the script/job to exit. It is a good idea to wrap calls like this in try/catch blocks in situations where you'd like the script to continue on in the event an error occurs. You could even log a message to this effect.

Second, it looks like this is a script that was designed to run on-box (i.e. on the NetMRI appliance)? If so, I'd strongly recommend using NetMRI_Easy instead of NetMRI::API. With NetMRI_Easy, a server URL, username and password do not need to be provided, and, in most cases, it makes performing many tasks easier.

Third, it looks like this script was designed to discover a device that does not already exist in NetMRI. Although it is necessary to pick a device as the job starting point (i.e. to kick it off), it really isn't necessary to login to *this* device in this situation since the script isn't doing anything with it. This auto-login to the target device is implicit behavior when running jobs, however, you can override this behavior by setting the "Script-Login: false" attribute.

I'm attaching a modified version of the above script that demonstrates all of this.

Hope this helps.

Thanks,

- Chris

 

#!/usr/bin/perl -w

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
# true
#
# Script-Login:
# false
#
# Script-Variables:
# $command word "show version"
#
# END-SCRIPT-BLOCK

use strict;
use warnings;
use NetMRI_Easy 0.6;

my $easy = new NetMRI_Easy({ api_version => 2.9 });

eval {
   my $devices = $easy->broker->discovery_setting->create({
      range_value       => '192.168.100.15',
      range_type        => 'STATIC',
      discovery_status => 'INCLUDE'
    });
};
if($@) {
   # Will appear in the Custom Log
   $easy->_log_message_no_login("WARNING", "Discovery Setting Create Failed: " . $@);
}

eval {
   my $discover = $easy->broker->device->discover({
      ip_address => '192.168.100.15'
   });
};
if($@) {
   # Will appear in the Custom Log
   $easy->_log_message_no_login("WARNING", "Device Discover Failed: " . $@);
}

 

Re: Script Problems

KZhou_2
Techie
Posts: 7
5296     0

Hi Chris,

Thanks a lot for the detailed explaination of how the script works.And for sure I will keep in mind to use the "try/catch blocks" for best practice in my scripts. The modified script works inside NetMRI with exisitng devices. Next step for me would be to make the script for CIDR range not just static IP. Also would like to try from outside of NetMRI with initial discovery.

Thanks again for your help.

Kevin

Did you ever resolve your

Authority
Posts: 36
5296     0

Did you ever resolve your issue?

We're having the same problem but our return code is 3 altough it gives back an device ID. Could it be linked to a "multi collector" setup? On a VM test environment this seems to be working just fine.
This is wat we get back from a API call like this:
https://netmri/api/2.10/devices/discover?ip_address=10.xxx.xxx.xxx

<response>
<system_info type="int">0</system_info>
<confirm_type type="int">0</confirm_type>
<fingerprint type="int">0</fingerprint>
<identification type="int">0</identification>
<returncode type="int">3</returncode>
<DeviceID>9222614916506409822</DeviceID>
<snmp_credentials type="int">0</snmp_credentials>
<cli_credentials type="int">0</cli_credentials>
<config_collection type="int">0</config_collection>
<ip_address>10.xxx.xxx.xxx</ip_address>
<initial type="int">1</initial>
<device nil="true"/>
</response>
Showing results for 
Search instead for 
Do you mean 

Recommended for You