-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-singlepull-transform-pipeline.py
More file actions
61 lines (42 loc) · 1.48 KB
/
json-singlepull-transform-pipeline.py
File metadata and controls
61 lines (42 loc) · 1.48 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
# Single PRTG sensor transform pipeline
# 1) Pull JSON records from a monitoring system
# 2) Map Sensors of Interest to new preferred format
# 3) Drop JSON records behind a web service for consuming applications to pick up
import json
import sys
# import request ... will be added to test urllib vs. request library
import urllib2
from pprint import pprint
# Retrieve and print static sensor
print('Test static single-sensor pipeline')
print('\nNative json response:\n')
macrosensor = json.load(urllib2.urlopen('https://serviceURL'))
print macrosensor
sensor = macrosensor['sensordata']
# Result contained the dictionary we wanted inside of another dictionary. This extracts the dictionary we want.
print('\nExtract sensor dictionary\n')
print(sensor)
# Modify sensor to new format
dashboard_sensor = {
'applicationIdentifier': sensor['probename'],
'applicationCodes': [
sensor['uptime'],
sensor['downtime'],
sensor['updownsince']
],
'name': sensor['parentdevicename'],
'status': 'PASS' if sensor['statustext'] == 'Up' else 'ERROR',
'messages': [
sensor['sensortype'],
]
}
# End of sensor processing
# Transformed sensor posting-Local feedback and file drop
print('\nSensor reformatted for new dashboard:\n')
pprint(dashboard_sensor)
filetag = dashboard_sensor['applicationIdentifier']
with open('%s.json' %filetag, 'wb') as json_data:
json_data.write(json.dumps(dashboard_sensor))
print('\nPosted json file:')
print(filetag)
# -30-