-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson2.py
More file actions
68 lines (57 loc) · 1.6 KB
/
json2.py
File metadata and controls
68 lines (57 loc) · 1.6 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Simple JSON transform routine
# Pull JSON records from a monitoring system
# Map Sensors of Interest to and transform
# Output new JSON objects
# Special thanks to Brian R for assistance at Boston Python Project Night
import json
import sys
# import requests
import logging
from pprint import pprint
# import file with all JSON objects
with open('data/format2.json') as json_data:
ping = json.load(json_data)
app_a_sensors = [
1, 3, 5
]
app_b_sensors = [
1, 2, 4
]
all_sensors = set(app_a_sensors) | set(app_b_sensors)
for sensor_name in all_sensors:
# GET sensor
# Transform sensor
# POST to interested apps
pass
total = 0
for sensor in ping['sensors']:
sys.stderr.write('Processing sensor {}\n'.format(sensor['sensor']))
dashboard_sensor = {
'applicationIdentifier': sensor['group'],
'applicationCodes': [
sensor['device'],
],
'name': sensor['sensor'],
'status': 'OK' if sensor['status'] == 'Up' else 'ERROR',
'messages': [
sensor['lastvalue'],
]
}
total += 1
# print(sensor)
pprint(dashboard_sensor)
jsontotal = len(sensor)
sensortotal = total
print('\nTotal dictionary items at top level', jsontotal)
print('Total sensors processed...500 may be the limit??', sensortotal)
# Ping is now a dictionary with my
# with open('refactored-sensors.json') as json_data:
# postform = json.load(json_data)
# json_data.close()
# print('inboundjson')
# print(ping)
# print('\nMaps to new json')
# print(postform)
# x=type(ping)
# print('Type of loaded JSON objects is',x)
# -30-