Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from myoung34/influxdb_ssl
Browse files Browse the repository at this point in the history
Add support for ssl and verify_ssl in influxdb configuration
  • Loading branch information
myoung34 authored Nov 23, 2020
2 parents 288ea0f + 39d91a0 commit 62104b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]'`
Expand Down
10 changes: 9 additions & 1 deletion tests/test_influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 14 additions & 5 deletions tilty/emitters/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" InfluxDB emitter """
import json
import logging
from distutils import util as distutil

from influxdb import InfluxDBClient
from jinja2 import Template
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 62104b4

Please sign in to comment.