02-01-2017 01:18 PM
I have been successfully using the API to add and remove hosts but now I want to do a check before adding to make sure there isn't a host associated with a specific IP and if there is to delete it, then add the new host. I am doing this in a python webhooks app that is used by Scalr with Openstack. Given it is python I have looked to this page(https://github.com/Infoblox-Development/Infoblox-API-Python/blob/master/infoblox.py) for examples. I found the method get_host_by_ip in this document but have not been able to make it work. In this example, the url has "network_view" but I have no idea how to get this to include in the call. Any suggestions? Thanks.
02-01-2017 01:54 PM
You may want to look at https://github.com/infobloxopen/infoblox-client which is more actively maintained.
02-02-2017 05:52 AM
Thanks for the response. I have tried "default" previously but unfortunately it didn't work and I don't see a drop down in the UI. Thanks for the new code reference. I'll see what I can find there.
02-02-2017 06:43 AM - edited 02-02-2017 06:51 AM
I tried network_view as default again and got this error: "Network View 'default' not found". I found this in the IPAM tab (image below) and was able to drill down from the network listed to the IP address I was trying to get. It seems like the Network View is "default" so I don't know why that error is being thrown. Any suggestions? Thanks.
02-02-2017 09:28 AM
02-02-2017 11:43 AM
network_view is an option field. You can usually leave it out unless you have more than one net view.
if it is missing, the API will just use the 'default' view and modify the records in there.
a code snippet would help to diagnose any further issues.
03-07-2017 12:49 PM
Sorry for the long delay in reply. I had other tasks take priority.
This is part of a webhooks app used with Scalr, so the code is getting the IP from an input payload provided by Scalr in the first line.
external_ip = self.payload["data"]["SCALR_EXTERNAL_IP"] response = self.__get_host_for_ip(self.url + "ipv4address?ip_address='" + external_ip + "'") if (response is None): log_message("Nothing was returned.") else: log_message("Response: " + response) def __get_host_for_ip(self, get_url): r = requests.get(url=get_url, auth=(self.username, self.password), verify=False) r_json = r.json() if r.status_code == 200 or r.status_code == 201: #Verify that there is an r_json object if r_json: log_message("Got a response") host_ref = r_json['_ref'] log_message("host_ref: " + host_ref) return host_ref else: return None else: if 'text' in r_json: log_message("!!!!! EXCEPTION in Infoblox Get Host for IP (1): " + r_json['text']) else: log_message("!!!!! EXCEPTION in Infoblox Get Host for IP (2): %s" % e)
I get the following output from this code:
URL parameter: https://10.9.0.224/wapi/v1.2.1/ipv4address?ip_address='10.48.87.95' !!!!! EXCEPTION in Infoblox Get Host for IP (1): A network was not found for this address.
Is there anything else I need to add to the url sent via requests? Thanks.
07-19-2017 08:29 AM
It just took a while to unravel the problem.
You're getting this error because of the way your Grid data is set up.
The API code looks to be correct, there is just no good data on the system.
To search for hosts by addresses you hve to have a network defined in IPAM for that address space.
You can't just search for a host by ip address, well, not by using /ipv4address.
if you create a network 10.48.0.0/16 it will probably work.
But, you could also search hosts by the ipaddress, with something like this:
However that will only return hosts, not any other DNS records that use that address. searching /ipv4address is the way to get all matching object types.
07-19-2017 08:33 AM
Does the user you uses have the read permission on the parent network?