From 946d7236fc0155125327d44fb8dc03fbcd5e1eb1 Mon Sep 17 00:00:00 2001 From: Ricardo Bartels Date: Sun, 2 Aug 2020 23:48:42 +0200 Subject: [PATCH] adds InfluxDB TLS Support #7 and configparser to requirements --- default.ini | 2 ++ fritzinfluxdb.py | 21 +++++++++++++-------- requirements.txt | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/default.ini b/default.ini index 4395d43..f3aa403 100644 --- a/default.ini +++ b/default.ini @@ -5,6 +5,8 @@ username = bla password = blub database = db measurement_name = fritzbox +ssl = false +verify_ssl = true [fritzbox] host = 192.168.178.1 diff --git a/fritzinfluxdb.py b/fritzinfluxdb.py index deeda17..215b421 100755 --- a/fritzinfluxdb.py +++ b/fritzinfluxdb.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import os -import sys import signal import configparser import fritzconnection @@ -29,14 +28,17 @@ def shutdown(signal, frame): global running running = False -# sometimes integers are returned as string -# try to sanatize this a bit -def sanatize_fb_return_data(results): + +def sanitize_fb_return_data(results): + """ + sometimes integers are returned as string + try to sanitize this a bit + """ return_results = {} for instance in results: # turn None => 0 - if results[instance] == None: + if results[instance] is None: return_results.update({instance: 0}) else: # try to parse as int @@ -48,6 +50,7 @@ def sanatize_fb_return_data(results): return return_results + def query_points(fc, services): result = {} @@ -70,11 +73,11 @@ def query_points(fc, services): # only keep desired result key if instance in this_result: - result.update({ rewrite_name if rewrite_name != None else instance : this_result[instance]}) + result.update({rewrite_name if rewrite_name is not None else instance: this_result[instance]}) else: result.update(fc.call_action(service, action)) - return sanatize_fb_return_data(result) + return sanitize_fb_return_data(result) def read_config(filename): @@ -121,7 +124,7 @@ def main(): args = parse_args() # set logging - log_level = logging.DEBUG if args.debug == True else default_loglevel + log_level = logging.DEBUG if args.debug is True else default_loglevel logging.basicConfig(level=log_level, format="%(levelname)s: %(message)s") # check if config file exists @@ -141,6 +144,8 @@ def main(): config.get('influxdb', 'username'), config.get('influxdb', 'password'), config.get('influxdb', 'database'), + config.getboolean('influxdb', 'ssl'), + config.getboolean('influxdb', 'verify_ssl') ) # check influx db status diff --git a/requirements.txt b/requirements.txt index e0dfb17..dc63cf4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ fritzconnection==0.7.3 influxdb +configparser