Network Management

Reply
Occasional Contributor I

Activate API management

 

Hello all,

 

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 all devices in the directory

Everything is working but the Json body Mac device filter.

 

Could you give a hand?

Thank you very much

 

 

import os, sys, re, argparse
import urllib.parse
import getpass
import urllib.request
import urllib
import json
import traceback
import pprint



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 fallida:Cerrando Aplicacion")
sys.exit(e.code)
else:
print("solicitud aprobada")
cookie=f.getheader('Set-Cookie')

f.read()

string_query={"devices" : "34:FC:B9:CE:12:E4"}
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&deviceFilter=basicData&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)+" "+"\n")

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

Aruba Employee

Re: Activate API management

Hi,

 

Try this Curl command from any ofyour linux server it will pull all the whitelist devices from activate.

 

#curl -3 -b Activate-cookie.txt 'https://activate.arubanetworks.com/api/ext/inventory.json?action=whitelist'

 

Regards,

Pavan

Occasional Contributor I

Re: Activate API management

Hello Pavan,

Curl is not an option in my enviroment, but I tried the url on my script and worked. The problem is that we have also controllers and switches we want to query about.

I'm interested in getting all device of data matching a certain mac_address, or, if possible, a serial number, do you know any url request which allows to do that?

 

Would like to solve the json body filter anyway, anybody has more ideas?

Aruba Employee

Re: Activate API management

Hi,

 

from where you want to pull the controller and switch inventory details Activate or Airwave?

 

Regards,

Pavan

Occasional Contributor I

Re: Activate API management

<Hello Pavan

 

Activate

Guru Elite

Re: Activate API management

Pass the MAC as form-urlencoded:

{ "devices" : [ "AA:BB:CC:11:22:33" ] } 

 


Tim Cappalli | Aruba Security TME
@timcappalli | timcappalli.me | ACMX #367 / ACCX #480
Aruba Employee

Re: Activate API management

Hi,

 

I have attached Aruba Activate guide , Check Inventory APIs from page 36 for more details.

 

Regards,

Pavan

 

If my post addresses your query give kudos:)

Occasional Contributor I

Re: Activate API management

Hello TIm,

 

I already tried:

 

string_query={"devices" : [ "34:FC:B9:CE:14:7E"]}
jsonbody_url=urllib.parse.urlencode(string_query)
json_alta_guest_bytes=jsonbody_url.encode("utf-8")
req=urllib.request.Request(line+"/api/ext/inventory.json?action=query&deviceFilter=basicData&addDate=06-16-2017",data=json_alta_guest_bytes,headers={"Cookie" : cookie,
"Content-Type": "application/x-www-form-urlencoded", "charset":"UTF-8","Content-length":len(json_alta_guest_bytes),
"Connection": "Keep-Alive"},method='POST')

 

and no effect. I left the other version because is the same method I use to manage ClearPass Json API, so that's the reason I think the code is correct.

 

I tried with an APi that only accepts jsond body filters(folder update API):


string_query={"devices" : [{"mac" : "20:4C:03:04:31:80",
"deviceName" : "nombre de prueba",
"folderName": "XXXXX"
}]}
#activate.arubanetworks.com/api/ext/inventory.json?action=update.

#string_query={"devices" : [ "34:FC:B9:CE:14:7E"]}
#json_alta_guest=json.dumps(string_query)
json_alta_guest=urllib.parse.urlencode(string_query)
datos=json_alta_guest.encode('utf-8')

req=urllib.request.Request(line+"/api/ext/inventory.json?action=update",data=datos,headers={"Cookie" : cookie,
"charset":"UTF-8","Content-length":len(datos),"Host": "activate.arubanetworks.com",
"Connection": "keep-alive"},method='POST')

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

 

 

and this is the server reponse:

errors': [{'key': 'json', 'errMessage': 'json POST parameter must be supplied for update action}]

 

Do you have any way to check what's the error detected in the server to return such error message?

As I said, the way I build the request is the same I use for Clearpass guest API, so I think the problem is not the request I'm sending...maybe a header missing?

 

Occasional Contributor I

Re: Activate API management

Hello Pavan, 

I already read the doc before writing the code, that's the reason I posted the case.

 

thank you all for the support

Occasional Contributor I

Re: Activate API management

Hello TIm,

 

I also tried Urlenconding the data before sending with no luck. The code I posted is pretty much the same I use to manage the Clearpass API, so I think the code is ok. I could have overlook something though.

 

string_query={"devices" : [ "34:FC:B9:CE:14:7E"]}

jsonbody_url=urllib.parse.urlencode(string_query)
json_alta_guest_bytes=jsonbody_url.encode("utf-8")
req=urllib.request.Request(line+"/api/ext/inventory.json?action=query&deviceFilter=basicData&addDate=06-16-2017",data=json_alta_guest_bytes,headers={"Cookie" : cookie,
"Content-Type": "application/x-www-form-urlencoded", "charset":"UTF-8","Content-length":len(json_alta_guest_bytes),
"Connection": "Keep-Alive"},method='POST')

 

In case it helps, I tried with an APi that only accepts json body filters (folder update API)

 

string_query={"devices" : [{"mac" : "20:4C:03:04:31:80",
"deviceName" : "nombre de prueba",
"folderName": "XXXX"}]}

json_alta_guest=urllib.parse.urlencode(string_query)
datos=json_alta_guest.encode('utf-8')

req=urllib.request.Request(line+"/api/ext/inventory.json?action=update",data=datos,headers={"Cookie" : cookie,
"charset":"UTF-8","Content-length":len(datos),"Host": "activate.arubanetworks.com",
"Connection": "keep-alive","Accept-Encoding":"deflate, br","Origin":"https://activate.arubanetworks.com",
"Referer":"https://activate.arubanetworks.com/registration/","Accept-Language":"es-ES,es;q=0.8"},method='POST')

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

 

 

and this is the server response:

 

-----errors': [{'key': 'json', 'errMessage': 'json POST parameter must be supplied for update action.'}]}

 

Do you have any way to check what's the reason the server returns this error?

 

I tried with the other version too:

string_query={"devices" : [{"mac" : "20:4C:03:04:31:80",
"deviceName" : "nombre de prueba",
"folderName": "XXXX"}]}
json_alta_guest=json.dumps(string_query)
datos=json_alta_guest.encode('utf-8')

req=urllib.request.Request(line+"/api/ext/inventory.json?action=update",data=datos,headers={"Cookie" : cookie,
"charset":"UTF-8","Content-length":len(datos),"Host": "activate.arubanetworks.com",
"Connection": "keep-alive","Accept-Encoding":"deflate, br","Origin":"https://activate.arubanetworks.com",
"Referer":"https://activate.arubanetworks.com/registration/","Accept-Language":"es-ES,es;q=0.8","Accept":"*/*"},method='POST')

 

and same server response

 

Thank you very much

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: