Whenever you add a new network into IPAM you have to manually add it into NetMRI for it to be discovered.
Why do we have to do this when NetMRI is an Automation tool? I’m so glad you asked.
The following is going to walk you through how to setup IPAM and NetMRI together to solve this issue. We will define a new Extensible Attribute (EA) that will control if a network has to be added to NetMRI for discovery. Then we will deploy a script on NetMRI that will check NIOS for newly created networks marked for discovery. Finally we will define a recurring job on NetMRI so that every hour the script will check if any new networks need to be added to the discovery settings.
Creating and Using the Extensible Attribute
Log in to Infoblox IPAM, click on Administration -> Extensible Attributes -> the “+” to add a new EA. We will name it “NetMRI” and set the type to “List”, add the Values “Yes, No, Done” then click “Save & Close”
Example:
Now we create the network in IPAM under Data Management, IPAM, Click the “+” button.
At the end of the wizard you will be prompted which Extensible Attributes you want to assign to this network. Add the “NetMRI” EA and set the value to “Yes”. Later our automation script running on the NetMRI appliance will be look for all networks were the EA “NetMRI” equals “Yes”
NetMRI Script to add the network
We are going to use a Python script in NetMRI to make an WAPI call to NIOS, it will look at IPAM data to find the relevant networks that need to be added.
The first API call is using the “GET” method and WAPI endpoint /network to find the network with the value “Yes”
The 2nd call will add these networks to NetMRI discovery ranges using the DiscoverySettings broker.
The 3rd call uses “PUT” to update the NetMRI EA on the IPAM side to change the value from “Yes” to “Done”
Here is the script:
# BEGIN-SCRIPT-BLOCK # # Script-Login: # false # Script-Filter: # true # # Script-Variables: # $gmuser string ‘Grid Master Username’ # $gmpassword password ‘Grid Master Password’ # $gmipaddress string ‘192.168.1.2’ # # END-SCRIPT-BLOCK from infoblox_netmri.easy import NetMRIEasy import requests, json requests.packages.urllib3.disable_warnings() # This values will be provided by NetMRI before execution defaults = { ‘api_url’: api_url, ‘http_username’: http_username, ‘http_password’: http_password, ‘job_id’: job_id, ‘device_id’: device_id, ‘batch_id’: batch_id } # Create NetMRI context manager. It will close session after execution myeasy = NetMRIEasy(**defaults) headers = {‘Content-type’: ‘application/json’} # We are going to look for any Network Objects with an EA of NetMRI “Add” # querystring = {“_return_fields+”:“extattrs”,“*NetMRI:”:“Yes”} url = “https://{}/wapi/v2.7/network”.format(gmipaddress) r = requests.request(“GET”, url, verify=False, headers=headers, params=querystring, auth=(gmuser, gmpassword)) broker = myeasy.broker(‘DiscoverySetting’) data = json.loads(r.text) for entry in data: print(entry[‘network’]) ip = entry[‘network’] ref = entry[‘_ref’] print(ref) ip = ip.rstrip(‘\r\n’) broker = myeasy.broker(‘DiscoverySetting’) add_ip_to_ds = { “range_value”: ip, “range_type”: ‘CIDR’, “discovery_status”: ‘INCLUDE’, “virtual_network_id”: ‘1’ } broker.create(**add_ip_to_ds) update_url = “https://{}/wapi/v2.7/”.format(gmipaddress) url2 = update_url + ref payload={‘extattrs+’: {‘NetMRI’: {‘value’: Done}}} update = requests.request(“PUT”, url2, verify=False, headers=headers, json=payload, auth=(gmuser, gmpassword)) print(update.content) ResultsNow let’s run the script and see what happens. Here is in NetMRI -> Settings -> Discovery Settings -> Ranges As you can see the network from NIOS was added Now let’s check IPAM for the network EA, to see if it was updated Let’s AUTOMATE itIn order to keep track of networks as they are added to IPAM we are going to add it to NetMRI as a scheduled job to run once an hour. Config Management → Job Management → Scheduled Jobs → + Choose the Script on the right side(mine is called “1 – NIOS Sync 2”), give it a name and Approved
Now we need to add the User account, Password and IP/DNS name.
Now we set it to run every hour on the hour You can find the scheduled tasks in the NetMRI UI under Config Management, Job Management, Scheduled Jobs. ConclusionIt’s easy to get data from NIOS or any other product that accepts API calls and use that data in NetMRI. Here’s a related blog: Get networks from IPAM and add to NetMRI for Discovery. |