From c4218e35e050ebc6ab4e3e18d2d3a85c03fb171c Mon Sep 17 00:00:00 2001 From: Nis Wechselberg Date: Tue, 30 Apr 2019 18:32:31 +0200 Subject: [PATCH] Added check for spent data --- PyPass.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/PyPass.py b/PyPass.py index 7570afc..c5f51f4 100755 --- a/PyPass.py +++ b/PyPass.py @@ -34,20 +34,34 @@ response = requests.get(REQUEST_API_URL, headers=REQUEST_HEADERS) respJson = response.json() # Prepare timedata for database -measurement = [ - { - "measurement": "pass_telekom_de", - "tags": { - "host": args.hostname - }, - "fields": { - "initialVolume": respJson['initialVolume'], - "usedVolume": respJson['usedVolume'], - "remainingSeconds": respJson['remainingSeconds'], - "usedAtMillis": respJson['usedAt'] +if respJson['usedPercentage'] < 100: + measurement = [ + { + "measurement": "pass_telekom_de", + "tags": { + "host": args.hostname + }, + "fields": { + "initialVolume": respJson['initialVolume'], + "usedVolume": respJson['usedVolume'], + "remainingSeconds": respJson['remainingSeconds'], + "usedAtMillis": respJson['usedAt'] + } } - } -] + ] +else: + measurement = [ + { + "measurement": "pass_telekom_de", + "tags": { + "host": args.hostname + }, + "fields": { + "remainingSeconds": respJson['remainingSeconds'], + "usedAtMillis": respJson['usedAt'] + } + } + ] # Send data to InfluxDB influx = InfluxDBClient(host=args.influxHost, database=args.database)