From 14f0c8990dfff08c1f045d451570d940455546ef Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 21 Jul 2020 20:26:27 -0400 Subject: [PATCH] handle packetloss --- main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a47ef6d..21b1c1a 100755 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from influxdb import InfluxDBClient # InfluxDB Settings DB_ADDRESS = os.environ.get('INFLUX_DB_ADDRESS') +print(os.environ.get('INFLUX_DB_PORT')) DB_PORT = int(os.environ.get('INFLUX_DB_PORT')) DB_USER = os.environ.get('INFLUX_DB_USER') DB_PASSWORD = os.environ.get('INFLUX_DB_PASSWORD') @@ -28,7 +29,11 @@ def init_db(): DB_DATABASE) # Create if does not exist. else: influxdb_client.switch_database(DB_DATABASE) # Switch to if does exist. - +def pkt_loss(data): + if data['packetLoss']: + return data['packetLoss'] + else: + return 0 def format_for_influx(cliout): data = json.loads(cliout) @@ -66,7 +71,7 @@ def format_for_influx(cliout): 'measurement': 'packetLoss', 'time': data['timestamp'], 'fields': { - 'packetLoss': int(data['packetLoss']) + 'packetLoss': pkt_loss(data) } } ]