Blogs

Aruba Activate User Guide

By j.easley posted Mar 23, 2017 09:24 AM

  
1 comment
7 views

Comments

Jul 20, 2017 11:39 AM

 Hello Jamie

 

I'm doing a very simple python 3 Script to query the activate inventory.

The problem is that the server is ignoring the body json filters, although URL filters are working.

 

According to the doc, I wrote the code below.

Json body filter is completely ignored, and if I omit the URL filter the response is so big I get HTTP 504.

Everything is working but the body Mac device filter.

 

Could you give a hand?

Thank you very much

 

 

import os, sys, re, argparse
import urllib.request
import urllib
import json
import traceback


line="https://activate.arubanetworks.com"
string_oauth={"credential_0" : "XXXXX","credential_1": "XXXXXX"}
jsonbody_url=urllib.parse.urlencode(string_oauth)
jsonbody_bytes = jsonbody_url.encode("utf-8")

print('Autenticando en : ',line)
req=urllib.request.Request(url=line+"/LOGIN",data=jsonbody_bytes,method='POST')
#construimos y enviamos consulta http
try:
f=urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
if hasattr(e, 'code'):
print('ERROR HTTP ', e.code)

if hasattr(e, 'detail'):
print('Reason: ', e.detail)
print("autenticación failed:Closing Application")
sys.exit(e.code)
else:
print("Authentication succeed")
cookie=f.getheader('Set-Cookie')

string_query={"devices" : [ "34:FC:B9:CE:12:30" , "20:4C:03:14:24:9C" ]}
json_alta_guest=json.dumps(string_query)
json_alta_guest_bytes=json_alta_guest.encode('utf-8')
req=urllib.request.Request(line+"/api/ext/inventory.json?action=query&addDate=06-15-2017",data=json_alta_guest_bytes,headers={"Cookie" : cookie,
"Content-Type": "Application/json", "charset":"UTF-8",
"Connection": "Keep-Alive"},method='POST')

try:
f=urllib.request.urlopen(req)

except urllib.error.HTTPError as e:
var=e.read().decode("utf-8")
print("HTTP "+str(e.code)+" "+"
")

else:

print(f.headers)
data = json.loads(f.read().decode('utf-8'))
print(data)