A Python script to connect to multiple NetApp OnCommand Insight Servers in turn, and collect all the Datasources. Perhaps useful if you're doing a consolidation exercise (like many OCI to one CI), and you want to compare what you've got left in all your OCI servers, to what you've now got in CI.
Save the script as say GetOciDatasources.py and run from your prompt as> python GetOciDatasources.py (remembering to set the highlighted bits as per your environment.)
The Script
## IMPORT THE ESSENTIALS ##
import requests
from base64 import b64encode
import csv
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
## SETUP CREDENTIALS FOR THE OCI SERVERS (ASSUMING ALL THE SAME) ##
userAndPass = b64encode(b"USERNAME:PASSWORD").decode("ascii")
headers = {'Authorization':'Basic %s' % userAndPass}
## CREATE A LIST OF OCI SERVERS ##
OCIS=[]
OCIS.append("OCI_SERVER1_FQDN")
OCIS.append("OCI_SERVER2_FQDN")
OCIS.append("OCI_SERVER3_FQDN")
## INITIALIZE A FILE FOR THE CSV OUTPUT ##
output = open('OciDatasources.csv',mode='w',newline='')
writer = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(['OCI Server','DS Name','Status','Vendor','Model','FoundationIp','LastAcquired'])
## CYCLE THROUGH THE OCIS COLLECTING THE ANNOTATION RULES ##
for OCI in OCIS:
method = "GET"
baseurl = "https://" + OCI + "/rest/v1/"
api = "admin/datasources"
response = requests.request(method,baseurl + api, headers = headers, verify = False)
json_data = json.loads(response.text)
for dsource in json_data:
row=[]
row.append(OCI)
row.append(dsource["name"])
row.append(dsource["status"])
row.append(dsource["vendor"])
row.append(dsource["model"])
row.append(dsource["foundationIp"])
row.append(dsource["lastSuccessfullyAcquired"])
writer.writerow(row)
## CLOSE THE CSV ##
output.close()
Comments
Post a Comment