-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqueryprime.py
executable file
·51 lines (42 loc) · 1.67 KB
/
queryprime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
try:
import configparser
except:
import ConfigParser as configparser
from pprint import pprint
import json
import requests
import argparse
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def api_request(path, config):
url = 'https://' + config.get('PRIME', 'API_HOST') + path
out = dict()
r = requests.get(
url,
verify=False,
auth=(config.get('PRIME', 'API_USER'), config.get('PRIME', 'API_PASSWORD')))
try:
out['json_response'] = r.json()
except ValueError:
out['error'] = 'An error occured. Please check back again later.'
out['error_detail'] = 'Unexpected response from controller. Not json!'
return out
def main():
config = configparser.ConfigParser()
config.read('config.ini')
host = config.get('PRIME', 'API_HOST')
ap_data = api_request('/webacs/api/v2/data/AccessPoints.json?.full=true&.maxResults=1000',
config)['json_response']['queryResponse']['entity']
dump_data = [{"mac": ap['accessPointsDTO']['macAddress'],
"ip": ap['accessPointsDTO']['ipAddress'],
"name": ap['accessPointsDTO'].get('name', ''),
"location": ap['accessPointsDTO']['location'],
"clients": ap['accessPointsDTO']['clientCount'],
"clients2.4": ap['accessPointsDTO']['clientCount_2_4GHz'],
"clients5": ap['accessPointsDTO']['clientCount_5GHz'],
} for ap in ap_data if 'location' in ap['accessPointsDTO']]
dump_data.sort(key=lambda d: d['name'])
print(json.dumps(dump_data))
if __name__ == '__main__':
main()