This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from myoung34/influxdb
Add support for InfluxDB emitter
- Loading branch information
Showing
13 changed files
with
294 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
class MockConfigParser: | ||
def __init__(self): | ||
pass | ||
def __init__(self, section): | ||
self.section = section | ||
|
||
def __getitem__(self, key): | ||
return { | ||
'url': 'http://www.google.com', | ||
'headers': {'Content-Type': 'application/json'}, | ||
'payload_template': '{"color": "{{ color }}", "gravity": {{ gravity }}, "temp": {{ temp }}, "timestamp": "{{ timestamp }}"}', | ||
'method': 'GET' | ||
} | ||
if self.section == 'webhook': | ||
return { | ||
'url': 'http://www.google.com', | ||
'headers': {'Content-Type': 'application/json'}, | ||
'payload_template': '{"color": "{{ color }}", "gravity": {{ gravity }}, "temp": {{ temp }}, "timestamp": "{{ timestamp }}"}', # noqa | ||
'method': 'GET' | ||
} | ||
if self.section == 'influxdb': | ||
return { | ||
'url': 'http://www.google.com', | ||
'database': 'foo', | ||
'gravity_payload_template': 'gravity,color={{ color }} value={{ gravity }} {{timestamp}}', # noqa | ||
'temperature_payload_template': 'temperature,scale=fahrenheit,color={{ color }} value={{ temp }} {{timestamp}}', # noqa | ||
} | ||
return None | ||
|
||
def has_section(*args, **kwargs): | ||
return True | ||
def has_section(self, *args, **kwargs): | ||
return self.section in args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
from tilty import common | ||
|
||
|
||
def test_safe_get_key_no_fallback(): | ||
assert common.safe_get_key({}, 'foo') is None | ||
|
||
|
||
def test_safe_get_key_fallback(): | ||
assert common.safe_get_key({}, 'foo', 'wut') == 'wut' | ||
|
||
|
||
def test_safe_get_key_valid(): | ||
assert common.safe_get_key({'foo': 'asdf'}, 'foo', 'wut') == 'asdf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
from unittest import mock | ||
|
||
from tilty.emitters import influxdb | ||
|
||
|
||
@mock.patch('tilty.emitters.influxdb.InfluxDBClient') | ||
def test_influxdb( | ||
mock_influx_client, | ||
): | ||
config = { | ||
'url': 'http://www.google.com', | ||
'database': 'foo', | ||
'gravity_payload': '{"measurement": "gravity", "tags": {"color": "Black"}, "fields": {"value": 1.054}}', # noqa | ||
'temperature_payload': '{"measurement": "temperature", "tags": {"color": "Black", "scale": "fahrenheight"}, "fields": {"value": 32}}', # noqa | ||
} | ||
influxdb.InfluxDB(config=config).emit() | ||
assert mock_influx_client.mock_calls == [ | ||
mock.call( | ||
'http://www.google.com', | ||
80, | ||
None, | ||
None, | ||
'foo' | ||
), | ||
mock.call().write_points([ | ||
{ | ||
'measurement': 'temperature', | ||
'tags': {'color': 'Black', 'scale': 'fahrenheight'}, | ||
'fields': {'value': 32} | ||
} | ||
]), | ||
mock.call().write_points([ | ||
{ | ||
'measurement': 'gravity', | ||
'tags': {'color': 'Black'}, | ||
'fields': {'value': 1.054} | ||
} | ||
]) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
""" Common methods """ | ||
|
||
|
||
def safe_get_key(config, key, fallback=None): | ||
""" Class to safely pull key from config or a fallback value """ | ||
try: | ||
return config[key] | ||
except KeyError: | ||
pass | ||
return fallback |
Oops, something went wrong.