A very short introduction into using Python and the InfoBlox Python libraries to interact with the REST API to give you a starting point for development.
The easiest approach is to use the InfoBlox-Client library in Python, it is possible to use “requests” and then parse the output, but this approach seems a bit more straightforward.
Setup virtualenv and Install InfoBlox Modules
The below assumes you already have Python 2.7 (or above) and VirtualEnv installed.
cd ~ mkdir venv cd venv virtualenv infoblox source /home/<username>/venv/infoblox/bin/activate
Now install the infoblox-client Python modules into your Virtual Environment:
pip install infoblox-client
You can now use the library in your scripts, see the script: https://github.com/tristanhself/general/blob/6939e27031e6d8343497d4f42f403a818fcfbd30/infoblox/infobloxapi_create_txt_record.py
Creating a DMARC or SPF Record Using the Script
To use the script you can pass arguments, these as follows:
-e = Endpoint FQDN of your InfoBlox appliance.
-u and -p = Username and Password of a user with rights to CRUD objects.
-c = Create if exists, set to “True” or “False”.
-x = Update if exists, set to “True” or “False”.
-v = The view, if you run split DNS, you may have multiple views, enter the relevant name here.
-n = The actual DNS domain you wish to add.
-t = The text body of the TXT record.
-o = Description (comment) of the record.
So let’s see an example to create a DMARC record:
./infobloxapi_create_txt_record.py -e infoblox1.domain.com -u <username> -p <password> -c True -x True -v external -n "_dmarc.domain.com" -t "v=DMARC1;p=none;fo=1;rua=mailto:firstname.lastname@example.org;ruf=mailto:email@example.com" -o "Email DMARC record, detailing the email domain security posture and reporting information."
And then an example to create an SPF record:
./infobloxapi_create_txt_record.py -e infoblox1.domain.com -u <username> -p <password> -c True -x True -v external -n "domain.com" -t "\"v=spf1 -all\"" -o "Email SPF record, detailing the authorised SMTP sender IP addresses for the domain."
Notice the escapes on the text record itself, if you are including spaces within the record.
Hopefully that script is of help to see how to use the InfoBlox API and manipulating it via the infoblox-client Python Library.