Introducing SOC Insights for BloxOne Threat Defense: Boost your SOC efficiency with AI-driven insights to eliminate manual work and accelerate investigation and response times. Read the blog announcement here.

API & Integration, DevOps,NetOps,SecOps

Reply

How to obtain the parent network object for an IP address in one call

[ Edited ]
New Member
Posts: 5
11322     2

I am fairly new to Infoblox and the WAPI, but I have a pretty good understanding of it.  I am trying to retrieve the network object of an individual IP address (because I have multiple EAs defined on the network that I don't want to duplicate on the Ipv4address or ipv6address meta objects)

 

If I have the following networks defined with different values for comments, EAs, etc.

120.130.140.0/28

120.130.140.16/28

120.130.140.32/28

 

I want to search for an IP address 120.130.140.4 and get its associated network object (120.130.140.0/28)  in one call.  Is there a way to do it?

 

I know I can do a

1) query on http://host/wapi/v2.9/ipv4address?ip_address=120.130.140.4 

2) get the value of the network object in the returned json (returnedNetworkVal)

3) then do a query on http://host/wapi/v2.9/network?network=returnedNetworkVal&_return_fields%2B=extattrs

 

I don't want to do 2 separate calls.  Is there a way to accomplish this with a single WAPI call?

Thanks in advance.

 

Re: How to obtain the parent network object for an IP address in one call

Moderator
Moderator
Posts: 287
11322     2

You can do this with multiple REST body requests with substitution, combined into one call.

 

Here's a curl example, the request body would look the same no matter what language you use.  I chose to return the extensible attributes along with the network default attributes.  You could customize the request to add additional fields, as needed:

 

curl -k -u admin:infoblox -H "Content-Type: application/json" -X POST 'https://192.168.1.2/wapi/v2.2/request' -d \
'[{
"method": "GET",
"object": "ipv4address",
"data": {"ip_address": "192.168.199.42"},
"args": {"_return_fields":"network"},
"assign_state": {"my_net": "network" },
"enable_substitution": true,
"discard": true
},
{
"method": "GET",
"object": "network",
"enable_substitution": true,
"data": { "network": "##STATE:my_net:##"},
"args": {"_return_fields+":"extattrs"},
"discard": false
},
{
"method": "STATE:DISPLAY"
}]'

And here's the response:

 

[
    [
        {
            "_ref": "network/ZG5zLm5ldHdvcmskMTAuOS4xNi4wLzI0LzA:192.168.199.0/24/default", 
            "extattrs": {
                "Data Center": {
                    "value": "NYC"
                }, 
                "My Date": {
                    "value": "2017-12-18T11:01:00Z"
                }, 
                "Network Type": {
                    "value": "Data Center"
                }, 
                "VLAN Name": {
                    "value": "This is a datacenter vlan"
                }
            }
        }
    ], 
    {
        "my_net": "10.9.16.0/24"
    }
]

Re: How to obtain the parent network object for an IP address in one call

New Member
Posts: 5
11323     2

MRichard,

 

Thank you so much for the example on how to do this.  This is exactly what I was looking for.   So, can you do multiple Gets (for different objects) if you use the format you have given?

 

Can you also do a Get from one object, do an update of  adifferent object using a Put all within the same body?

 

thanks a bunch

Re: How to obtain the parent network object for an IP address in one call

Moderator
Moderator
Posts: 287
11323     2

Yes, the possibilities are endless!

 

Here's another example, changing a hostname on an existing host record.  First we need to find it.  Then we need to update it.

 

[{
    "method": "STATE:ASSIGN",
    "data": { "old_hostname": "oldname.example.org",
    		  "new_hostname": "newname.example.org",
    		  "dns_view": "Internal" }
 },
 {
    "method": "GET",
    "object": "record:host",
    "data": {"name": "##STATE:old_hostname:##", 
        	 "view": "##STATE:dns_view:##"
        	},
	"assign_state": {"host_ref": "_ref" },
    "enable_substitution": true,
    "discard": true
 },
 {
	"method": "PUT",
	"object": "##STATE:host_ref:##",
	"enable_substitution": true,
	"data": { "name": "##STATE:new_hostname:##"},
	"discard": true
 },
 {
    "method": "STATE:DISPLAY"
}]

Re: How to obtain the parent network object for an IP address in one call

[ Edited ]
New Member
Posts: 1
11323     2

Thanks for the example
It's really useful information for my progect  

 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You