diff --git a/README.md b/README.md index a4c981e..2623ac4 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,9 @@ method = POST url = influxdb.corp.com port = 80 database = tilty +password = foo # optional +ssl = True # default is False +verify_ssl = True # default is False gravity_payload_template = {"measurement": "gravity", "tags": {"color": "{{ color }}", "mac": "{{ mac }}"}, "fields": {"value": {{ gravity }}}} temperature_payload_template = {"measurement": "temperature", "tags": {"color": "{{ color }}", "mac": "{{ mac }}"}, "fields": {"value": {{ temp }}}} # `% curl -s -G 'http://influxdb.service.consul:8086/query?pretty=true' --data-urlencode "db=tilty" --data-urlencode 'q=SELECT "value", "mac", "color" FROM "autogen"."gravity"' | jq '.results[].series[].values[0]'` diff --git a/tests/test_influxdb.py b/tests/test_influxdb.py index 952add5..1910037 100644 --- a/tests/test_influxdb.py +++ b/tests/test_influxdb.py @@ -27,7 +27,15 @@ def test_influxdb( 'mac': 'foo', }) assert mock_influx_client.mock_calls == [ - mock.call('http://www.google.com', 80, None, None, 'foo'), + mock.call( + database='foo', + host='http://www.google.com', + password=None, + port=80, + ssl=False, + username=None, + verify_ssl=False, + ), mock.call().write_points([ { 'measurement': 'temperature', diff --git a/tilty/emitters/influxdb.py b/tilty/emitters/influxdb.py index a1270f6..735314f 100644 --- a/tilty/emitters/influxdb.py +++ b/tilty/emitters/influxdb.py @@ -2,6 +2,7 @@ """ InfluxDB emitter """ import json import logging +from distutils import util as distutil from influxdb import InfluxDBClient from jinja2 import Template @@ -31,12 +32,20 @@ def __init__(self, config: dict) -> None: # temperature_payload_template = {"measurement": "temperature", "tags": {"color": "{{ color }}"}, "fields": {"value": {{ temp }}}} # noqa # pylint: disable=line-too-long self.gravity_template = Template(config['gravity_payload_template']) # noqa self.temperature_template = Template(config['temperature_payload_template']) # noqa + ssl = bool(distutil.strtobool( + safe_get_key(config, 'ssl', 'False') + )) + verify_ssl = bool(distutil.strtobool( + safe_get_key(config, 'verify_ssl', 'False') + )) self.client = InfluxDBClient( - config['url'], - safe_get_key(config, 'port', 80), - safe_get_key(config, 'user'), - safe_get_key(config, 'password'), - config['database'] + host=config['url'], + port=safe_get_key(config, 'port', 80), + username=safe_get_key(config, 'user'), + password=safe_get_key(config, 'password'), + ssl=ssl, + verify_ssl=verify_ssl, + database=config['database'] ) def emit(self, tilt_data: dict) -> None: