Skip to content

Commit

Permalink
adds InfluxDB TLS Support #7 and configparser to requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Aug 2, 2020
1 parent 6d19b7d commit 946d723
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ username = bla
password = blub
database = db
measurement_name = fritzbox
ssl = false
verify_ssl = true

[fritzbox]
host = 192.168.178.1
Expand Down
21 changes: 13 additions & 8 deletions fritzinfluxdb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
import sys
import signal
import configparser
import fritzconnection
Expand Down Expand Up @@ -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
Expand All @@ -48,6 +50,7 @@ def sanatize_fb_return_data(results):

return return_results


def query_points(fc, services):
result = {}

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fritzconnection==0.7.3
influxdb
configparser

0 comments on commit 946d723

Please sign in to comment.