Skip to content

Instantly share code, notes, and snippets.

@kod3r
Forked from jirah/RESPONSE_TIME_READ.py
Last active September 19, 2015 02:27
Show Gist options
  • Save kod3r/b0e923292b3afa317bc4 to your computer and use it in GitHub Desktop.
Save kod3r/b0e923292b3afa317bc4 to your computer and use it in GitHub Desktop.
Print Response Time READ Operations on a VMAX, using Unisphere API.
#!/usr/bin/python
import requests, json, pprint, time, socket
CARBON_SERVER = '0.0.0.0'
CARBON_PORT = 2003
def send_msg(message):
#print 'sending message: %s' % message
sock = socket.socket()
sock.connect((CARBON_SERVER, CARBON_PORT))
sock.sendall(message)
sock.close()
target_url = "https://192.168.28.4:8443/univmax/restapi/performance/Array/metrics"
requestObj = {'arrayParam':
{'endDate': int(time.time()*1000), #End time to specify is now.
'startDate': int(time.time()*1000)-(3600*1000), #start time is 60 minutes before that
'metrics': ['RESPONSE_TIME_READ'], #array of what metrics we want
'symmetrixId': '000000000123' #symmetrix ID (full 12 digits)
}
}
requestJSON = json.dumps(requestObj, sort_keys=True, indent=4) #turn this into a JSON string
#print requestJSON
headers = {'content-type': 'application/json','accept':'application/json'} #set the headers for how we want the response
#make the actual request, specifying the URL, the JSON from above, standard basic auth, the headers and not to verify the SSL cert.
r = requests.post(target_url, requestJSON, auth=('user', 'password'), headers=headers, verify=False)
#take the raw response text and deserialize it into a python object.
try:
responseObj = json.loads(r.text)
except:
print "Exception"
print r.text
#print json.dumps(responseObj, sort_keys=False, indent=4)
#make sure we actually get a value back.
#data = None
if len(responseObj["iterator"]["resultList"]["result"]) > 0:
data = float(responseObj["iterator"]["resultList"]["result"][0]['RESPONSE_TIME_READ'])
line = 'Symmetrix.System.RESPONSE_TIME_READ.123 %d %d' % (data, int(time.time()))
send_msg(line)
print line
else:
print "Short response"
pprint.pprint(responseObj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment