From c478f2c7d0168c92c02bfd7f82b3db1ce01e756c Mon Sep 17 00:00:00 2001 From: boojew Date: Thu, 15 Jun 2017 23:41:19 -0400 Subject: [PATCH] Added host variable to Splunk.py and updated tox tests (#8052) * Added host variable to Splunk.py and updated tox tests * Update splunk.py * Update splunk.py --- homeassistant/components/splunk.py | 6 +++++- tests/components/test_splunk.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/splunk.py b/homeassistant/components/splunk.py index e9a2ee13ae2..2b4ea862d2d 100644 --- a/homeassistant/components/splunk.py +++ b/homeassistant/components/splunk.py @@ -11,7 +11,7 @@ import requests 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 +22,7 @@ DOMAIN = 'splunk' DEFAULT_HOST = 'localhost' DEFAULT_PORT = 8088 DEFAULT_SSL = False +DEFAULT_NAME = 'HASS' CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ @@ -29,6 +30,7 @@ CONFIG_SCHEMA = vol.Schema({ 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 +42,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 +72,7 @@ def setup(hass, config): 'attributes': dict(state.attributes), 'time': str(event.time_fired), 'value': _state, + 'host': name, } ] diff --git a/tests/components/test_splunk.py b/tests/components/test_splunk.py index 4d5d4cc5d45..d0c46c5f8ea 100644 --- a/tests/components/test_splunk.py +++ b/tests/components/test_splunk.py @@ -28,6 +28,7 @@ class TestSplunk(unittest.TestCase): 'port': 123, 'token': 'secret', 'ssl': 'False', + 'name': 'hostname', } } @@ -96,6 +97,7 @@ class TestSplunk(unittest.TestCase): 'attributes': {}, 'time': '12345', 'value': out, + 'host': 'HASS', }] payload = {'host': 'http://host:8088/services/collector/event',