The CreatorCon Call for Content is officially open! Get started here.

Infoblox get next IP address via REST

poyntzj
Kilo Sage

I was looking as part of an orchestration process to get the next available IP address from our Infoblox server.

I have used John-James Andersons Scriptable RESTMessage Library

Scriptable RESTMessage Library for ServiceNow-John James Andersen

 

The rest of this message are the small Background scripts that I have used that will get me the next IP and reserve it for my server.

Before impementation it will need some work, but until I know our data in our Infoblox is 100% we are going to allocate the IP address manually.

If we do decide to automate, I will add the updated code.

 

You use this REST message to get the _ref for the network you are searching for

 

var r = new RESTMessageScripted("get","https://infobloxserver/wapi/v1.4.1/network?network=10.0.0.0/24");
r.setBasicAuth("username","password");
r.setMIDServer("MIDServer");
r.execute();
var k = 1;
var response = r.getResponse();
this.debug("Initial response: " + response);
this.debug("Going to loop for a response from MID Server");
while (response == null) {
       this.debug("waiting … " + k + " seconds");
       response = r.getResponse(1000); //wait 1 second before looking for the response
       k++;

       if (k > 30) {
               gs.log("ERROR: Web Service did not respond after 30 seconds", this.LOGGER_SOURCE);
               break; // service did not respond after 30 tries
       }
}
gs.print(response.getBody())

 

and you will get the following reply

 

*** Script: [
       {
               "_ref": "network/ZG5zLm5ldHdvcmskMTAuMTkzLjE1Mi4wLzI0LzA:10.0.0.0/24/default", 
               "comment": "Comment about network", 
               "network": "10.0.0.0/24", 
               "network_view": "default"
       }
]

you will need to get the _ref from the response and then encode that into the following REST message so you can get the free IP address

(replace the network/ZG5zLm5ldHdvcmskMTAuMTkzLjE1Mi4wLzI0LzA with whatever is returned above)

 

 

var r = new RESTMessageScripted("post","https://infobloxserver/wapi/v1.4.1/network/ZG5zLm5ldHdvcmskMTAuMTkzLjE1Mi4wLzI0LzA?_function=next_available_ip");
r.addHeader("content-type", "application/json");
r.setContent('{"num":1}');
r.setBasicAuth("username","password");
r.setMIDServer("MIDServer");
r.execute();
var k = 1;
var response = r.getResponse();
this.debug("Initial response: " + response);
this.debug("Going to loop for a response from MID Server");
while (response == null) {
       this.debug("waiting … " + k + " seconds");
       response = r.getResponse(1000); //wait 1 second before looking for the response
       k++;

       if (k > 30) {
               gs.log("ERROR: Web Service did not respond after 30 seconds", this.LOGGER_SOURCE);
               break; // service did not respond after 30 tries
       }
}
gs.print(response.getBody())

 

And you will get the response

 

*** Script: {
       "ips": [
               "10.0.0.67"
       ]
}

Now you have the next IP address, use the next REST message using the IP address from the above and the name of your server

 

 

var r = new RESTMessageScripted("post","https://infobloxserver/wapi/v1.4.1/fixedaddress");
r.setContent('{"ipv4addr":"10.0.0.67","name":"lonipmp01101b","match_client":"RESERVED"}');
r.setBasicAuth("username","password");
r.setMIDServer("MIDServer");
r.execute();
var k = 1;
var response = r.getResponse();
this.debug("Initial response: " + response);
this.debug("Going to loop for a response from MID Server");
while (response == null) {
       this.debug("waiting … " + k + " seconds");
       response = r.getResponse(1000); //wait 1 second before looking for the response
       k++;

       if (k > 30) {
               gs.log("ERROR: Web Service did not respond after 30 seconds", this.LOGGER_SOURCE);
               break; // service did not respond after 30 tries
       }
}
gs.print(response.getBody())

 

and if successful, you will see the following

 

*** Script: "fixedaddress/ZG5zLmZpeGVkX2FkZHJlc3MkMTAuMTkzLjE1Mi42Ny4wLi4:10.0.0.67/default"

 

Hope it helps somebody

9 REPLIES 9

rebecca_dias
ServiceNow Employee
ServiceNow Employee

As a heads up, we have provided an OOB Activity Pack for InfoBlox DNS, DHCP, and IPAM automation in Geneva. It will likely save you some code. We have started discussing this at snugs. If you would like to learn more about this please email me directly at rebecca.dias@servicenow.com.



I am the product manager for Orchestration.


tx


becky


Hi,



Could you please provide me some documents/steps to build the infoblox integration through REST API.


Thanks in Adv.



Regards,


Santosh


Sindhuja10
Kilo Expert

Hi poyntzj,

I am trying to connect to InfoBlox to get a domain name. I have created a REST message, but I get a Connection refused error. But with the same URL and credentials I am able to connect through postman. Is there anything else to be added apart from the REST message.

 

Not at that client any longer.  As long as it works in postman it should work in Servicenow.

Only things I can think of are ACL on the IP address or a configuraiton issue in  your settings.

is your REST going via a MID server ?

As Rebecca pointed out in this thread, there  is now an activity pack to integrate with InfoBlox.

I can appreciate that these are good but sometimes somewhat limited (my current client we may want to pass some new attributes to Azure, but the activity does not cater for that and is not visible to edit / clone)

Hello Sindhuja,

What is the error message ?

Because during a former integration between Infoblox and ServiceNow I met an issue linked to SNI protocol. May be it's the same.