Skip to content

Instantly share code, notes, and snippets.

@bockor
Last active March 3, 2021 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bockor/8264a1ae4bf54e2fbc00121dc8dd0e67 to your computer and use it in GitHub Desktop.
Save bockor/8264a1ae4bf54e2fbc00121dc8dd0e67 to your computer and use it in GitHub Desktop.
infoblox notes // ipam utilization + tls/ssl unsecure messages surpression
import requests
import urllib3
import json
# Surpress SSL/TLS >Insecure Warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
session = requests.Session()
session.auth = ('admin', 'infoblox')
session.verify = False
url = 'https://192.168.1.222/wapi/v2.10.3/'
headers = {'Content-type': 'application/json'}
data = {
'ipv4addr' : '10.0.1.2',
'mac':'00:12:51:12:3b:56',
}
r = session.post(url + 'fixedaddress', json=data, headers=headers, verify=False)
response = r.json()
print(response)
"""
# https://community.infoblox.com/t5/API-Integration/WAPI-IPAM-Statistics/td-p/1483
# Import the required Python modules.
import requests
import json
import csv
# Set parameters to access the Infoblox API for your own grid master.
url = 'https://192.168.1.222/wapi/v2.10.3/'
id = 'admin'
pw = 'infoblox'
valid_cert = False # False if self-signed certificate
# Retrieve all network objects (up to a max of 5000).
r = requests.get(url + 'network',
params={'_max_results': str(5000)},
auth=(id, pw),
verify=valid_cert)
if r.status_code != requests.codes.ok:
print 'Request failed with error code ', r.status_code
exit()
networks = r.json()
# For each network count all used addresses (up to a max of 5000).
stats = []
for network in networks:
# Retrieve used ipv4address objects for this network.
r = requests.get(url + 'ipv4address',
params={'network': network['network'],
'network_view': network['network_view'],
'status': 'USED',
'_max_results': str(5000)},
auth=(id, pw),
verify=valid_cert)
if r.status_code != requests.codes.ok:
print 'Request failed with error code ', r.status_code
exit()
ipv4addresses = r.json()
# Count the number of ipv4address objects and save the count.
used = len(ipv4addresses)
prefix = int(network['network'].split('/')[1])
size = 2**(32-prefix) - 2
pct_used = round((100. * used) / size, 1)
stats.append((network['network'],
network['network_view'],
size,
used,
pct_used))
# Export the results.
with open('ipam-stats.csv', 'wb') as out_file:
out_csv = csv.writer(out_file,
delimiter=',',
quotechar='"',
quoting=csv.QUOTE_MINIMAL)
out_csv.writerow(['network',
'network_view',
'size',
'used',
'pct_used'])
for item in stats:
out_csv.writerow(list(item))
"""
"""
curl -k1 -u admin:infoblox -H "Content-Type: application/json" -X GET 'https://192.168.1.222/wapi/v2.10.3/ipam:statistics?_return_fields=network%2Ccidr%2Cnetwork_view%2Cutilization'
Utilization is for some reason in int and not float, so 948 = 94,8%
[
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:default/10.0.0.0/24",
"cidr": 24,
"network": "10.0.0.0",
"network_view": "default",
"utilization": 55
},
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4xLjAvMjQvMA:default/10.0.1.0/24",
"cidr": 24,
"network": "10.0.1.0",
"network_view": "default",
"utilization": 3
},
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4yLjAvMjQvMA:default/10.0.2.0/24",
"cidr": 24,
"network": "10.0.2.0",
"network_view": "default",
"utilization": 3
}
]
Filter on network_view:
curl -k1 -u admin:infoblox -H "Content-Type: application/json" -X GET 'https://192.168.1.222/wapi/v2.10.3/ipam:statistics?network_view=default&_return_fields=network%2Ccidr%2Cutilization'
[
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:default/10.0.0.0/24",
"cidr": 24,
"network": "10.0.0.0",
"utilization": 55
},
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4xLjAvMjQvMA:default/10.0.1.0/24",
"cidr": 24,
"network": "10.0.1.0",
"utilization": 7
},
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4yLjAvMjQvMA:default/10.0.2.0/24",
"cidr": 24,
"network": "10.0.2.0",
"utilization": 3
},
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4zLjAvMjUvMA:default/10.0.3.0/25",
"cidr": 25,
"network": "10.0.3.0",
"utilization": 0
},
{
"_ref": "ipam:statistics/ZG5zLm5ldHdvcmskMTAuMC4zLjEyOC8yNi8w:default/10.0.3.128/26",
"cidr": 26,
"network": "10.0.3.128",
"utilization": 0
}
]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment