Update main.py

Migrate namespace to tag.
This commit is contained in:
Leigh Phillips 2021-01-16 20:15:40 -08:00 committed by GitHub
parent b8ddba245b
commit adc0a4a1dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

18
main.py
View file

@ -45,11 +45,12 @@ def pkt_loss(data):
def tag_selection(data): def tag_selection(data):
tags = DB_TAGS tags = DB_TAGS
if tags is None: options = {}
return None
# tag_switch takes in _data and attaches CLIoutput to more readable ids # tag_switch takes in _data and attaches CLIoutput to more readable ids
tag_switch = { tag_switch = {
'isp': data['isp'], 'namespace': NAMESPACE,
'isp': data['isp'],
'interface': data['interface']['name'], 'interface': data['interface']['name'],
'internal_ip': data['interface']['internalIp'], 'internal_ip': data['interface']['internalIp'],
'interface_mac': data['interface']['macAddr'], 'interface_mac': data['interface']['macAddr'],
@ -66,10 +67,13 @@ def tag_selection(data):
'speedtest_url': data['result']['url'] 'speedtest_url': data['result']['url']
} }
if tags == '*': if tags is None:
tags = 'namespace'
elif '*' in tags:
return tag_switch return tag_switch
else:
tags = 'namespace, ' + tags
options = {}
tags = tags.split(',') tags = tags.split(',')
for tag in tags: for tag in tags:
# split the tag string, strip and add selected tags to {options} with corresponding tag_switch data # split the tag string, strip and add selected tags to {options} with corresponding tag_switch data
@ -87,7 +91,6 @@ def format_for_influx(data):
'measurement': 'ping', 'measurement': 'ping',
'time': data['timestamp'], 'time': data['timestamp'],
'fields': { 'fields': {
'namespace': NAMESPACE,
'jitter': data['ping']['jitter'], 'jitter': data['ping']['jitter'],
'latency': data['ping']['latency'] 'latency': data['ping']['latency']
} }
@ -96,7 +99,6 @@ def format_for_influx(data):
'measurement': 'download', 'measurement': 'download',
'time': data['timestamp'], 'time': data['timestamp'],
'fields': { 'fields': {
'namespace': NAMESPACE,
# Byte to Megabit # Byte to Megabit
'bandwidth': data['download']['bandwidth'] / 125000, 'bandwidth': data['download']['bandwidth'] / 125000,
'bytes': data['download']['bytes'], 'bytes': data['download']['bytes'],
@ -107,7 +109,6 @@ def format_for_influx(data):
'measurement': 'upload', 'measurement': 'upload',
'time': data['timestamp'], 'time': data['timestamp'],
'fields': { 'fields': {
'namespace': NAMESPACE,
# Byte to Megabit # Byte to Megabit
'bandwidth': data['upload']['bandwidth'] / 125000, 'bandwidth': data['upload']['bandwidth'] / 125000,
'bytes': data['upload']['bytes'], 'bytes': data['upload']['bytes'],
@ -118,7 +119,6 @@ def format_for_influx(data):
'measurement': 'packetLoss', 'measurement': 'packetLoss',
'time': data['timestamp'], 'time': data['timestamp'],
'fields': { 'fields': {
'namespace': NAMESPACE,
'packetLoss': pkt_loss(data) 'packetLoss': pkt_loss(data)
} }
} }