Skip to content

Commit

Permalink
Update mspinventory.py with JSON Web Token(JWT)
Browse files Browse the repository at this point in the history
  • Loading branch information
indhradhanush authored Apr 19, 2023
1 parent c04449a commit 550163d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/mspinventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

def mspinventory():
s = requests.Session()
tenant_id = apilogin(s)
r1 = s.post('https://' + rks_domain + '/api/viewmodel/tenant/' + tenant_id +'/ec-inventory', json={"page": 1,"pageSize": pageSize,"sortField": "deviceStatus","sortOrder": "DESC","matchFields": [{"field": "deviceStatus","value": ""}]}).json()
tenant_id,jw_token = apilogin(s)
Authorization_Header = {'Authorization': "Bearer {}".format(jw_token)}
r1 = s.post('https://' + rks_domain + '/api/viewmodel/tenant/' + tenant_id +'/ec-inventory', json={"page": 1,"pageSize": pageSize,"sortField": "deviceStatus","sortOrder": "DESC","matchFields": [{"field": "deviceStatus","value": ""}]}, headers=Authorization_Header).json()
countinrequest = r1['totalCount']
print("Total Devices: ",countinrequest)
if countinrequest > 1:

#### Temp data for testing. Block - START
'''y={'serialNumber': 'FJN3851P03E', 'crtTime': '2021-03-08T18:59:03.311Z', 'lastUpdTime': '2021-03-08T18:59:03.311Z', 'name': 'stack-2', 'model': 'ICX7550-24', 'venueId': '1990d21454bb4419a9685f0bf358366b', 'venueName': 'My-Venue', 'deviceStatus': 'ONLINE', 'floorplanId': '', 'xPercent': 0.0, 'yPercent': 0.0, 'tags': '', 'switchName': 'stack-2', 'tenantId': '896ff4566fda421e82ab3e744916c150', 'deviceType': 'DVCNWTYPE_SWITCH', 'switchMac': 'D4:C1:9E:4D:F7:01', 'customerName': 'Bradley Miller', 'managedAs': 'MSP'}
#### Temp data for testing Block - START
y={'serialNumber': 'FJN3851P03E', 'crtTime': '2021-03-08T18:59:03.311Z', 'lastUpdTime': '2021-03-08T18:59:03.311Z', 'name': 'stack-2', 'model': 'ICX7550-24', 'venueId': '1990d21454bb4419a9685f0bf358366b', 'venueName': 'My-Venue', 'deviceStatus': 'ONLINE', 'floorplanId': '', 'xPercent': 0.0, 'yPercent': 0.0, 'tags': '', 'switchName': 'stack-2', 'tenantId': '896ff4566fda421e82ab3e744916c150', 'deviceType': 'DVCNWTYPE_SWITCH', 'switchMac': 'D4:C1:9E:4D:F7:01', 'customerName': 'Bradley Miller', 'managedAs': 'MSP'}
r1["data"].append(y)
y={'serialNumber': 'FJN3851P03D', 'crtTime': '2021-03-08T18:59:03.311Z', 'lastUpdTime': '2021-03-08T18:59:03.311Z', 'name': 'stack-1', 'model': 'ICX7150-48ZP', 'venueId': '1990d21454bb4419a9685f0bf358366b', 'venueName': 'My-Venue', 'deviceStatus': 'OFFLINE', 'floorplanId': '', 'xPercent': 0.0, 'yPercent': 0.0, 'tags': '', 'switchName': 'stack-1', 'tenantId': '896ff4566fda421e82ab3e744916c150', 'deviceType': 'DVCNWTYPE_SWITCH', 'switchMac': 'D4:C1:9E:4D:F7:00', 'customerName': 'Bradley Miller', 'managedAs': 'MSP'}
r1["data"].append(y)
Expand All @@ -31,8 +33,8 @@ def mspinventory():
r1["data"].append(y)
y={'serialNumber': '84250327824', 'crtTime': '2021-09-04T07:07:31.548Z', 'lastUpdTime': '2021-09-06T11:08:40.700Z', 'lastSeenTime': '2021-11-29T18:38:25.080Z', 'name': 'TestAP3', 'model': 'R550', 'fwVersion': '6.0.0.1.1696', 'venueId': 'a3bcdbb2a90e44089397056a9400c1ba', 'venueName': 'My-Venue', 'configStatus': 'New Configuration', 'connectionStatus': 'Provisioned', 'deviceStatus': '3_04_DisconnectedFromCloud', 'deviceStatusSeverity': '3_RequiresAttention', 'IP': '192.168.1.111', 'extIp': '124.43.231.104', 'apMac': 'AE:58:EA:3A:09:90', 'apStatusData': {'APRadio': [{'txPower': 'max', 'channel': 13, 'band': '2.4G', 'Rssi': None, 'operativeChannelBandwidth': '20', 'radioId': 0}, {'txPower': 'max', 'channel': 36, 'band': '5G', 'Rssi': None, 'operativeChannelBandwidth': '80', 'radioId': 1}], 'APSystem': {'uptime': 709469}, 'lanPortStatus': [{'port': '0', 'phyLink': 'Up 100Mbps full'}, {'port': '1', 'phyLink': 'Down '}]}, 'meshRole': 'DISABLED', 'deviceGroupId': 'c8d5f0df5fd54a6f82d9d989894005e0', 'floorplanId': '', 'tags': 'D99069', 'deviceGroupName': '', 'deviceModelType': 'Indoor', 'tenantId': '831005cbeb1b48bc9f0b4a20281d9118', 'deviceType': 'DVCNWTYPE_WIFI', 'customerName': 'Bradley Miller', 'managedAs': 'MSP'}
r1["data"].append(y)
countinrequest=countinrequest+5'''
#### Temp data for testing. Block - END
countinrequest=countinrequest+5
#### Temp data for testing Block - END

totalcount = min(countinrequest, pageSize)
r2=r1['data']
Expand All @@ -52,4 +54,4 @@ def mspinventory():
in_influx_allap(r1, totalcount)
else:
print("No devices found")
# EOL
# EOL

0 comments on commit 550163d

Please sign in to comment.