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