Added parents to Hosts Live API

Change-Id: I7ea1c9b7f5bf608771e1ad82da140ef08306940e
This commit is contained in:
aviau 2015-05-07 13:49:46 -04:00
parent 0e06073b2b
commit a8b4567e4e
3 changed files with 22 additions and 7 deletions

View File

@ -28,6 +28,9 @@ class LiveHost(types.Base):
childs = wsme.wsattr([wtypes.text], mandatory=False) childs = wsme.wsattr([wtypes.text], mandatory=False)
"""The childs of the host""" """The childs of the host"""
parents = wsme.wsattr([wtypes.text], mandatory=False)
"""The parents 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"""
@ -52,6 +55,7 @@ class LiveHost(types.Base):
host_name='CoolHost', host_name='CoolHost',
address="127.0.0.1", address="127.0.0.1",
childs=['surveil.com'], childs=['surveil.com'],
parents=['parent.com'],
description='Very Nice Host', description='Very Nice Host',
state=0, state=0,
acknowledged=1, acknowledged=1,

View File

@ -44,7 +44,7 @@ class HostHandler(handler.Handler):
query = influxdb_query.build_influxdb_query( query = influxdb_query.build_influxdb_query(
live_query, live_query,
'HOST_STATE', 'HOST_STATE',
group_by=['host_name', 'address', 'childs'], group_by=['host_name', 'address', 'childs', 'parents'],
order_by=['time DESC'], order_by=['time DESC'],
limit=1 limit=1
) )
@ -81,6 +81,7 @@ class HostHandler(handler.Handler):
"address": tags['address'], "address": tags['address'],
"description": tags['host_name'], "description": tags['host_name'],
"childs": json.loads(tags['childs']), "childs": json.loads(tags['childs']),
"parents": json.loads(tags['parents']),
# Values # Values
"state": first_point['state'], "state": first_point['state'],

View File

@ -30,7 +30,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"name": "HOST_STATE", {"name": "HOST_STATE",
"tags": {"host_name": "localhost", "tags": {"host_name": "localhost",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": '[]'}, "childs": '[]',
"parents": '["parent.com"]'},
"columns": [ "columns": [
"time", "time",
"last_check", "last_check",
@ -52,7 +53,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"name": "HOST_STATE", {"name": "HOST_STATE",
"tags": {"host_name": "test_keystone", "tags": {"host_name": "test_keystone",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": '[]'}, "childs": '[]',
"parents": '["parent.com"]'},
"columns": [ "columns": [
"time", "time",
"last_check", "last_check",
@ -74,7 +76,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"name": "HOST_STATE", {"name": "HOST_STATE",
"tags": {"host_name": "ws-arbiter", "tags": {"host_name": "ws-arbiter",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": '["test_keystone"]'}, "childs": '["test_keystone"]',
"parents": '["parent.com"]'},
"columns": [ "columns": [
"time", "time",
"last_check", "last_check",
@ -110,6 +113,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"description": "localhost", {"description": "localhost",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": [], "childs": [],
"parents": ['parent.com'],
"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,
@ -119,6 +123,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"description": "test_keystone", {"description": "test_keystone",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": [], "childs": [],
"parents": ['parent.com'],
"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,
@ -128,6 +133,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"description": "ws-arbiter", {"description": "ws-arbiter",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": ['test_keystone'], "childs": ['test_keystone'],
"parents": ['parent.com'],
"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,
@ -139,7 +145,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
self.assertEqual( self.assertEqual(
httpretty.last_request().querystring['q'], httpretty.last_request().querystring['q'],
["SELECT * FROM HOST_STATE " ["SELECT * FROM HOST_STATE "
"GROUP BY host_name, address, childs ORDER BY time DESC LIMIT 1"] "GROUP BY host_name, address, childs, parents "
"ORDER BY time DESC LIMIT 1"]
) )
@httpretty.activate @httpretty.activate
@ -151,7 +158,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"name": "HOST_STATE", {"name": "HOST_STATE",
"tags": {"host_name": "ws-arbiter", "tags": {"host_name": "ws-arbiter",
"address": "127.0.0.1", "address": "127.0.0.1",
"childs": '["test_keystone"]'}, "childs": '["test_keystone"]',
"parents": '["parent.com"]'},
"columns": [ "columns": [
"time", "time",
"last_check", "last_check",
@ -198,7 +206,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
httpretty.last_request().querystring['q'], httpretty.last_request().querystring['q'],
["SELECT * FROM HOST_STATE WHERE host_name!='localhost' " ["SELECT * FROM HOST_STATE WHERE host_name!='localhost' "
"AND description!='test_keystone' " "AND description!='test_keystone' "
"GROUP BY host_name, address, childs " "GROUP BY host_name, address, childs, parents "
"ORDER BY time DESC " "ORDER BY time DESC "
"LIMIT 1"] "LIMIT 1"]
) )
@ -211,6 +219,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
{"name": "HOST_STATE", {"name": "HOST_STATE",
"tags": {"address": "localhost", "tags": {"address": "localhost",
"childs": "[\"test_keystone\"]", "childs": "[\"test_keystone\"]",
"parents": '["parent.com"]',
"host_name": "localhost"}, "host_name": "localhost"},
"columns": ["time", "columns": ["time",
"acknowledged", "acknowledged",
@ -235,6 +244,7 @@ class TestStatusHosts(functionalTest.FunctionalTest):
response = self.get("/v2/status/hosts/localhost") response = self.get("/v2/status/hosts/localhost")
expected = {"childs": ["test_keystone"], expected = {"childs": ["test_keystone"],
"parents": ['parent.com'],
"description": "localhost", "description": "localhost",
"last_state_change": 1429812192, "last_state_change": 1429812192,
"acknowledged": 0, "acknowledged": 0,