Added childs attribute to LiveHost
Change-Id: I462dc319d0701b07e11707f0731b02e761638a06
This commit is contained in:
parent
cb1734c65c
commit
4d96462469
@ -25,6 +25,9 @@ class LiveHost(types.Base):
|
|||||||
address = wsme.wsattr(wtypes.text, mandatory=False)
|
address = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
"""The address of the host"""
|
"""The address of the host"""
|
||||||
|
|
||||||
|
childs = wsme.wsattr([wtypes.text], mandatory=False)
|
||||||
|
"""The childs of the host"""
|
||||||
|
|
||||||
description = wsme.wsattr(wtypes.text, mandatory=False)
|
description = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
"""The description of the host"""
|
"""The description of the host"""
|
||||||
|
|
||||||
@ -48,6 +51,7 @@ class LiveHost(types.Base):
|
|||||||
return cls(
|
return cls(
|
||||||
host_name='CoolHost',
|
host_name='CoolHost',
|
||||||
address="127.0.0.1",
|
address="127.0.0.1",
|
||||||
|
childs=['surveil.com'],
|
||||||
description='Very Nice Host',
|
description='Very Nice Host',
|
||||||
state=0,
|
state=0,
|
||||||
acknowledged=1,
|
acknowledged=1,
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import json
|
||||||
|
|
||||||
from surveil.api.datamodel.status import live_host
|
from surveil.api.datamodel.status import live_host
|
||||||
from surveil.api.handlers import handler
|
from surveil.api.handlers import handler
|
||||||
@ -25,7 +26,9 @@ class HostHandler(handler.Handler):
|
|||||||
def get_all(self, live_query=None):
|
def get_all(self, live_query=None):
|
||||||
"""Return all live hosts."""
|
"""Return all live hosts."""
|
||||||
cli = self.request.influxdb_client
|
cli = self.request.influxdb_client
|
||||||
query = "SELECT * from HOST_STATE GROUP BY host_name, address LIMIT 1"
|
query = ("SELECT * from HOST_STATE "
|
||||||
|
"GROUP BY host_name, address, childs "
|
||||||
|
"LIMIT 1")
|
||||||
response = cli.query(query)
|
response = cli.query(query)
|
||||||
|
|
||||||
host_dicts = []
|
host_dicts = []
|
||||||
@ -34,9 +37,13 @@ class HostHandler(handler.Handler):
|
|||||||
first_entry = next(item[1])
|
first_entry = next(item[1])
|
||||||
|
|
||||||
host_dict = {
|
host_dict = {
|
||||||
|
# TAGS
|
||||||
"host_name": item[0][1]['host_name'],
|
"host_name": item[0][1]['host_name'],
|
||||||
"address": item[0][1]['address'],
|
"address": item[0][1]['address'],
|
||||||
"description": item[0][1]['host_name'],
|
"description": item[0][1]['host_name'],
|
||||||
|
"childs": json.loads(item[0][1]['childs']),
|
||||||
|
|
||||||
|
# Values
|
||||||
"state": first_entry['state'],
|
"state": first_entry['state'],
|
||||||
"acknowledged": first_entry['acknowledged'],
|
"acknowledged": first_entry['acknowledged'],
|
||||||
"last_check": int(first_entry['last_check']),
|
"last_check": int(first_entry['last_check']),
|
||||||
|
@ -85,6 +85,7 @@ def main():
|
|||||||
"_OS_PASSWORD": "blo",
|
"_OS_PASSWORD": "blo",
|
||||||
"_OS_TENANT": "blu",
|
"_OS_TENANT": "blu",
|
||||||
"_KS_SERVICES": "bly",
|
"_KS_SERVICES": "bly",
|
||||||
|
"parents": "localhost"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,23 +23,80 @@ class TestStatusHosts(functionalTest.FunctionalTest):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestStatusHosts, self).setUp()
|
super(TestStatusHosts, self).setUp()
|
||||||
self.influxdb_response = (
|
self.influxdb_response = json.dumps({
|
||||||
'{"results":[{"series":[{"name":"HOST_STATE","tags":{"host_name":'
|
"results": [
|
||||||
'"localhost","address":"127.0.0.1"},"columns":["time","last_check'
|
{
|
||||||
'","last_state_change","output","state","state_type", "acknowledg'
|
"series": [
|
||||||
'ed"],"values":[["2015-04-19T01:09:24Z",1.429405764e+09,1.4294057'
|
{"name": "HOST_STATE",
|
||||||
'65316929e+09,"OK - localhost: rta 0.033ms, lost 0%",0,"HARD",0]]'
|
"tags": {"host_name": "localhost",
|
||||||
'},{"name":"HOST_STATE","tags":{"host_name":"test_keystone","addr'
|
"address": "127.0.0.1",
|
||||||
'ess":"127.0.0.1"},"columns":["time","last_check","last_state_cha'
|
"childs": '[]'},
|
||||||
'nge","output","state","state_type", "acknowledged"],"values":[["'
|
"columns": [
|
||||||
'2015-04-19T01:09:23Z",1.429405763e+09,1.429405765317144e+09,"OK '
|
"time",
|
||||||
'- 127.0.0.1: rta 0.032ms, lost 0%",0,"HARD",0]]},{"name":"HOST_S'
|
"last_check",
|
||||||
'TATE","tags":{"host_name":"ws-arbiter","address":"127.0.0.1"},"c'
|
"last_state_change",
|
||||||
'olumns":["time","last_check","last_state_change","output","state'
|
"output",
|
||||||
'","state_type","acknowledged"],"values":[["2015-04-19T01:09:24Z"'
|
"state",
|
||||||
',1.429405764e+09,1.429405765317063e+09,"OK - localhost: rta 0.03'
|
"state_type",
|
||||||
'0ms, lost 0%",0,"HARD",0]]}]}]}'
|
"acknowledged"
|
||||||
)
|
],
|
||||||
|
"values":[
|
||||||
|
["2015-04-19T01:09:24Z",
|
||||||
|
1.429405764e+09,
|
||||||
|
1.429405765316929e+09,
|
||||||
|
"OK - localhost: rta 0.033ms, lost 0%",
|
||||||
|
0,
|
||||||
|
"HARD",
|
||||||
|
0]
|
||||||
|
]},
|
||||||
|
{"name": "HOST_STATE",
|
||||||
|
"tags": {"host_name": "test_keystone",
|
||||||
|
"address": "127.0.0.1",
|
||||||
|
"childs": '[]'},
|
||||||
|
"columns": [
|
||||||
|
"time",
|
||||||
|
"last_check",
|
||||||
|
"last_state_change",
|
||||||
|
"output",
|
||||||
|
"state",
|
||||||
|
"state_type",
|
||||||
|
"acknowledged"
|
||||||
|
],
|
||||||
|
"values":[
|
||||||
|
["2015-04-19T01:09:23Z",
|
||||||
|
1.429405763e+09,
|
||||||
|
1.429405765317144e+09,
|
||||||
|
"OK - 127.0.0.1: rta 0.032ms, lost 0%",
|
||||||
|
0,
|
||||||
|
"HARD",
|
||||||
|
0]
|
||||||
|
]},
|
||||||
|
{"name": "HOST_STATE",
|
||||||
|
"tags": {"host_name": "ws-arbiter",
|
||||||
|
"address": "127.0.0.1",
|
||||||
|
"childs": '["test_keystone"]'},
|
||||||
|
"columns": [
|
||||||
|
"time",
|
||||||
|
"last_check",
|
||||||
|
"last_state_change",
|
||||||
|
"output",
|
||||||
|
"state",
|
||||||
|
"state_type",
|
||||||
|
"acknowledged"
|
||||||
|
],
|
||||||
|
"values":[
|
||||||
|
["2015-04-19T01:09:24Z",
|
||||||
|
1.429405764e+09,
|
||||||
|
1.429405765317063e+09,
|
||||||
|
"OK - localhost: rta 0.030ms, lost 0%",
|
||||||
|
0,
|
||||||
|
"HARD",
|
||||||
|
0]
|
||||||
|
]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_get_all_hosts(self):
|
def test_get_all_hosts(self):
|
||||||
@ -52,6 +109,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
|
|||||||
expected = [
|
expected = [
|
||||||
{"description": "localhost",
|
{"description": "localhost",
|
||||||
"address": "127.0.0.1",
|
"address": "127.0.0.1",
|
||||||
|
"childs": [],
|
||||||
"last_state_change": 1429405765,
|
"last_state_change": 1429405765,
|
||||||
"plugin_output": "OK - localhost: rta 0.033ms, lost 0%",
|
"plugin_output": "OK - localhost: rta 0.033ms, lost 0%",
|
||||||
"last_check": 1429405764,
|
"last_check": 1429405764,
|
||||||
@ -60,6 +118,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
|
|||||||
"host_name": "localhost"},
|
"host_name": "localhost"},
|
||||||
{"description": "test_keystone",
|
{"description": "test_keystone",
|
||||||
"address": "127.0.0.1",
|
"address": "127.0.0.1",
|
||||||
|
"childs": [],
|
||||||
"last_state_change": 1429405765,
|
"last_state_change": 1429405765,
|
||||||
"plugin_output": "OK - 127.0.0.1: rta 0.032ms, lost 0%",
|
"plugin_output": "OK - 127.0.0.1: rta 0.032ms, lost 0%",
|
||||||
"last_check": 1429405763,
|
"last_check": 1429405763,
|
||||||
@ -68,6 +127,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
|
|||||||
"host_name": "test_keystone"},
|
"host_name": "test_keystone"},
|
||||||
{"description": "ws-arbiter",
|
{"description": "ws-arbiter",
|
||||||
"address": "127.0.0.1",
|
"address": "127.0.0.1",
|
||||||
|
"childs": ['test_keystone'],
|
||||||
"last_state_change": 1429405765,
|
"last_state_change": 1429405765,
|
||||||
"plugin_output": "OK - localhost: rta 0.030ms, lost 0%",
|
"plugin_output": "OK - localhost: rta 0.030ms, lost 0%",
|
||||||
"last_check": 1429405764,
|
"last_check": 1429405764,
|
||||||
@ -75,7 +135,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
|
|||||||
"acknowledged": 0,
|
"acknowledged": 0,
|
||||||
"host_name": "ws-arbiter"}]
|
"host_name": "ws-arbiter"}]
|
||||||
|
|
||||||
self.assertEqual(json.loads(response.body), expected)
|
self.assertItemsEqual(json.loads(response.body), expected)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_query_hosts(self):
|
def test_query_hosts(self):
|
||||||
@ -97,4 +157,4 @@ class TestStatusHosts(functionalTest.FunctionalTest):
|
|||||||
|
|
||||||
expected = [{"host_name": "ws-arbiter", "last_check": 1429405764}]
|
expected = [{"host_name": "ws-arbiter", "last_check": 1429405764}]
|
||||||
|
|
||||||
self.assertEqual(json.loads(response.body), expected)
|
self.assertItemsEqual(json.loads(response.body), expected)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user