From 044e84ea942402a2feda9c0bd47ff0ce602aaba6 Mon Sep 17 00:00:00 2001 From: Ben Abecassis Date: Thu, 15 Jun 2017 22:14:43 -0400 Subject: [PATCH 1/3] Added host variable to Splunk.py and updated tox tests --- homeassistant/components/splunk.py | 8 ++++++-- tests/components/test_splunk.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/splunk.py b/homeassistant/components/splunk.py index e9a2ee13ae2eab..1d0e28994ca941 100644 --- a/homeassistant/components/splunk.py +++ b/homeassistant/components/splunk.py @@ -1,6 +1,5 @@ """ Support to send data to an Splunk instance. - For more details about this component, please refer to the documentation at https://home-assistant.io/components/splunk/ """ @@ -11,7 +10,7 @@ import voluptuous as vol from homeassistant.const import ( - CONF_HOST, CONF_PORT, CONF_SSL, CONF_TOKEN, EVENT_STATE_CHANGED) + CONF_NAME, CONF_HOST, CONF_PORT, CONF_SSL, CONF_TOKEN, EVENT_STATE_CHANGED) from homeassistant.helpers import state as state_helper import homeassistant.helpers.config_validation as cv @@ -22,6 +21,7 @@ DEFAULT_HOST = 'localhost' DEFAULT_PORT = 8088 DEFAULT_SSL = False +DEFAULT_NAME = 'HASS' CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ @@ -29,6 +29,7 @@ vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_SSL, default=False): cv.boolean, + vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }), }, extra=vol.ALLOW_EXTRA) @@ -40,6 +41,7 @@ def setup(hass, config): port = conf.get(CONF_PORT) token = conf.get(CONF_TOKEN) use_ssl = conf.get(CONF_SSL) + name = conf.get(CONF_NAME) if use_ssl: uri_scheme = 'https://' @@ -69,6 +71,7 @@ def splunk_event_listener(event): 'attributes': dict(state.attributes), 'time': str(event.time_fired), 'value': _state, + 'host': name, } ] @@ -85,3 +88,4 @@ def splunk_event_listener(event): hass.bus.listen(EVENT_STATE_CHANGED, splunk_event_listener) return True + diff --git a/tests/components/test_splunk.py b/tests/components/test_splunk.py index 4d5d4cc5d4599a..d0c46c5f8ea887 100644 --- a/tests/components/test_splunk.py +++ b/tests/components/test_splunk.py @@ -28,6 +28,7 @@ def test_setup_config_full(self): 'port': 123, 'token': 'secret', 'ssl': 'False', + 'name': 'hostname', } } @@ -96,6 +97,7 @@ def test_event_listener(self, mock_dump, mock_requests): 'attributes': {}, 'time': '12345', 'value': out, + 'host': 'HASS', }] payload = {'host': 'http://host:8088/services/collector/event', From 72cf90b7e2b4874bc721df2d8eccc689e9d7344c Mon Sep 17 00:00:00 2001 From: boojew Date: Thu, 15 Jun 2017 22:38:57 -0400 Subject: [PATCH 2/3] Update splunk.py --- homeassistant/components/splunk.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/splunk.py b/homeassistant/components/splunk.py index 1d0e28994ca941..e6d745d4152319 100644 --- a/homeassistant/components/splunk.py +++ b/homeassistant/components/splunk.py @@ -88,4 +88,3 @@ def splunk_event_listener(event): hass.bus.listen(EVENT_STATE_CHANGED, splunk_event_listener) return True - From b8891061aa8d898f837131d978597831935441f5 Mon Sep 17 00:00:00 2001 From: boojew Date: Thu, 15 Jun 2017 23:11:12 -0400 Subject: [PATCH 3/3] Update splunk.py --- homeassistant/components/splunk.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/splunk.py b/homeassistant/components/splunk.py index e6d745d4152319..2b4ea862d2db2e 100644 --- a/homeassistant/components/splunk.py +++ b/homeassistant/components/splunk.py @@ -1,5 +1,6 @@ """ Support to send data to an Splunk instance. + For more details about this component, please refer to the documentation at https://home-assistant.io/components/splunk/ """