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
This commit is contained in:
parent
a3a702b269
commit
c478f2c7d0
2 changed files with 7 additions and 1 deletions
|
@ -11,7 +11,7 @@ import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
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
|
from homeassistant.helpers import state as state_helper
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ DOMAIN = 'splunk'
|
||||||
DEFAULT_HOST = 'localhost'
|
DEFAULT_HOST = 'localhost'
|
||||||
DEFAULT_PORT = 8088
|
DEFAULT_PORT = 8088
|
||||||
DEFAULT_SSL = False
|
DEFAULT_SSL = False
|
||||||
|
DEFAULT_NAME = 'HASS'
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: 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_HOST, default=DEFAULT_HOST): cv.string,
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
vol.Optional(CONF_SSL, default=False): cv.boolean,
|
vol.Optional(CONF_SSL, default=False): cv.boolean,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
}),
|
}),
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
@ -40,6 +42,7 @@ def setup(hass, config):
|
||||||
port = conf.get(CONF_PORT)
|
port = conf.get(CONF_PORT)
|
||||||
token = conf.get(CONF_TOKEN)
|
token = conf.get(CONF_TOKEN)
|
||||||
use_ssl = conf.get(CONF_SSL)
|
use_ssl = conf.get(CONF_SSL)
|
||||||
|
name = conf.get(CONF_NAME)
|
||||||
|
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
uri_scheme = 'https://'
|
uri_scheme = 'https://'
|
||||||
|
@ -69,6 +72,7 @@ def setup(hass, config):
|
||||||
'attributes': dict(state.attributes),
|
'attributes': dict(state.attributes),
|
||||||
'time': str(event.time_fired),
|
'time': str(event.time_fired),
|
||||||
'value': _state,
|
'value': _state,
|
||||||
|
'host': name,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ class TestSplunk(unittest.TestCase):
|
||||||
'port': 123,
|
'port': 123,
|
||||||
'token': 'secret',
|
'token': 'secret',
|
||||||
'ssl': 'False',
|
'ssl': 'False',
|
||||||
|
'name': 'hostname',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ class TestSplunk(unittest.TestCase):
|
||||||
'attributes': {},
|
'attributes': {},
|
||||||
'time': '12345',
|
'time': '12345',
|
||||||
'value': out,
|
'value': out,
|
||||||
|
'host': 'HASS',
|
||||||
}]
|
}]
|
||||||
|
|
||||||
payload = {'host': 'http://host:8088/services/collector/event',
|
payload = {'host': 'http://host:8088/services/collector/event',
|
||||||
|
|
Loading…
Add table
Reference in a new issue