Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!

Network Change & Configuration Management


Forced discovery through a PERL script

Posts: 12
3459     0



I am trying to write a PERL script that will force Netmri to do a "Discover Now" on an ip (ideally a series of ips) of devices that are newly added to the network.  Normally, the discovery process can take up to 24 hours for the full process to run. This is not ideal.  Until a device is fully discovered, we are unable to evaluate it with our policies or run remediation scripts against it. This causes us extra paperwork and process to circle back and remediate policy violations that should have been addressed immediately.

I am new to Perl and the API but I was able to borrow the script from this thread: and it seems to perform the behaviour I want.  However, I need to enhance this to be useful to my users.  A couple of questions: 

- I would like the user to be able to specify an ip (or a list of IPs) to have a 'Discover now' performed.   I have this built into Script-variables but I'm not clear on how to pass this to the script to use. (Just calling the variable name isn't working)

- The script creates a static entry for the device through the broker/discovery_setting;  We already have the ranges configured in the Ranges tab in Discovery Settings.  Will this overlap cause a problem?  Is there another method to remove the static entry after the device is discovered?  "my $devices = $easy->broker->discovery_setting->remove({"??

- Is this a bad idea? Will it cause issues down the road?

TL;DR - Need a script to force an immediate discovery of a device or a series of devices. 


#!/usr/bin/perl -w

# Script-Filter:
# true
# Script-Login:
# false
# Script-Variables:
# $mgmt_ip ipaddress "Management IP"

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       => '',
      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 => ''
if($@) {
   # Will appear in the Custom Log
   $easy->_log_message_no_login("WARNING", "Device Discover Failed: " . $@);


Hi Chris, you could just call

Posts: 127
3459     0

Hi Chris, you could just call me Smiley Happy

Having given this some thought in the past, one way to do this is to have a discover script in the sandbox that looks for a file on a share drive with the list of devices you want to discover.  The script could be a cron job that fires up every X minutes or hours and checks for a file to process. 

I really didn't think this was that big of a deal waiting for netmri to discover the devices within 24 hours.  If you are seeing that it is not finding the new devices within that time period then there are some other issues at hand.  Give me a call and we can discuss.



I can't bug you for

Posts: 12
3459     0

I can't bug you for EVERYTHING! Smiley Happy

The group was discussing the new worflows here and how we can streamline our provisioning/install process, while still having some check and balances in place to make sure we keep people from doing 'bad' things.  The job engine seemed to make the most sense as it requires an approval process to kick it off. 

It's also a learning process for me.  I had been poking at trying to get this to work before the new year, figured now was a good time to pick it back up and see if we can put it to good use.

Chris, I set something like

Posts: 408
3459     0

Chris, I set something like that up for a customer and there is no problem with it.


Follow me on LinkedIn:

Re: Forced discovery through a PERL script

Posts: 6
3459     0



I have the same need. Seems like the UI ought to offer a "Discover Now" that allows the user to specify the IP address. Anyway, I copied your script, changed the IP address, and tried to run it. I'm a newbie at this, so I didn't know the basic mechanism. I RTFM'd and went to "Config Management" -> "Job Management", "Scripts" "Add" and created a new script named "Discover device". I did "Run now" and it provided a field form me to enter the "Management IP", but that seems meaningless - the script doesn't use it. I clicked through the prompts and was forced to provide a Device Group, so I chose one at random. When I finished, it seemed to be running, but as near as I can tell it was doing "Discover Now" on all the devices in the device group.


Where should I go for documentation on how to do this? I'm quite familiar with Perl, but I want to know...


1. How do I use Script Variables?

2. How do I communicate errors to the outside word?

3. Where are log messages logged?

4. Why do I need to specify a Device Group?

5. Why does the script need to specify a range?

Showing results for 
Search instead for 
Do you mean 

Recommended for You