A Python script to connect to your NetApp Cloud Insights tenant, collect all the Datasources, and export as a CSV.
Save the script as say GetCiDatasources.py and run from your prompt as> python GetCiDatasources.py (remembering to set the highlighted bits as per your environment.)
The Script
## IMPORT NECESSARY STUFF ##
import csv
import json
import urllib3
import requests
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
## REST API GET ##
api_key = 'ENTER_YOUR_API_KEY_HERE'
yourTenant = 'YOUR_TENANT' # This is the bit that comes before .cloudinsights.netapp.com
url = 'https://' + yourTenant + '.cloudinsights.netapp.com/rest/v1/collector/datasources'
headers = {'X-CloudInsights-ApiKey': '{key}'.format(key=api_key)}
jsondata = requests.get(url, headers=headers, verify = False).json()
## INITIALIZE A FILE FOR THE CSV OUTPUT ##
output = open('CiDatasources.csv',mode='w',newline='')
writer = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
headings = ['name','status','vendor','model','foundationIp','lastSuccessfullyAcquired']
writer.writerow(['CI Tenant'] + headings)
## PARSE THE JSONDATA TO CSV ##
for dsource in jsondata:
row=[]
row.append(yourTenant)
for column in headings:
row.append(dsource[column])
writer.writerow(row)
## CLOSE THE CSV ##
output.close()
Comments
Post a Comment