Reply

Retrieve "Pending Changes" via API?

Techie
Posts: 14
505     0

To all the InfoBlox API Experts here ...

 

Is there a way to retrieve a list of "Pending Changes" via API? Via "console - restart services", you can see a list of pending changes. I'd like to get access to that data via API so that I can pull and store it in a Change Control / Incident Ticket prior to issuing an automated restart, but I've been unsuccessful so far. Smiley Sad

 

Thank you!

Re: Retrieve "Pending Changes" via API?

[ Edited ]
Adviser
Posts: 162
505     0

Hello There,

 

So there's no direct call to pull outstanding changes to be processed. But here's a python script that will let you pull changes since a specific EPOCH time. For example, if you want to pull all changes since the last time you know a restart was done(Say June 1, 2021 5:30:00 AM GMT), then your input EPOCH time input to the script would be : 1622505600.

 

This website will help you with the Date-Epoch conversion. Just put in the date there & get the epoch value -> put this in as the input when you run the script. 

 

Sample output :

 

  **Changes since Thu Jul 15 17:23:20 2021 **

{
"_ref": "grid:servicerestart:request:changedobject/b25lLnJlc3RhcnRfcmVxdWVzdF9jaGFuZ2VkX29iamVjdCQxMTI:changedobject",
"action": "CREATED",
"changed_time": 1626374119,
"object_name": "yolo.com",
"object_type": "zone_auth",
"user_name": "admin"
}
{
"_ref": "grid:servicerestart:request:changedobject/b25lLnJlc3RhcnRfcmVxdWVzdF9jaGFuZ2VkX29iamVjdCQxMTM:changedobject",
"action": "CREATED",
"changed_time": 1626378655,
"object_name": "sss.com",
"object_type": "zone_auth",
"user_name": "admin"
}

Code :

 

# Find pending changes since X time in epoch.

import requests
import urllib3
import json
from os import system, name
import datetime


def clear():
    if name == 'nt':
        _ = system('cls')
    else:
        _ = system('clear')


urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

gm_ip = input("\n\nEnter Grid Mater's IP :")
type(gm_ip)
gm_user = input("\nEnter user name :")
type(gm_user)
gm_password = input("\nEnter password :")
type(gm_password)

clear()
epoch_start_time = input("\nEnter the start of Epoch :")
urL = 'https://' + gm_ip + '/wapi/v2.9/grid:servicerestart:request:changedobject?_return_fields=action,object_name,changed_time,object_type,user_name'

response = requests.get(urL, auth=(gm_user, gm_password), verify=False)
mid_value = response.content
response_native = json.loads(mid_value)

clear()
time_value = datetime.datetime.fromtimestamp(int(epoch_start_time)).strftime('%c')
print(f"\n\t\t**Changes since {time_value} **")

for change in response_native:
    if float(change['changed_time']) > float(epoch_start_time):
        readable_dictionary = json.dumps(change, indent=2)
        print(f"{readable_dictionary}")
    else:
        continue

I've tested & verified changes back till June 1, 2021. Hope this would help

 

Best regards,

Mohammed Alman

Re: Retrieve "Pending Changes" via API?

Techie
Posts: 14
506     0

Fantastic. Thank you! This got me what I needed.

 

Running several tests on my GRID, this call *does* appear to only pull outstanding changes. As soon as I request a restart, the list becomes empty again. So this is exactly what I needed!

Showing results for 
Search instead for 
Did you mean: 

Recommended for You