From b342e820b5ad6060a8d15caffdb5cf5d08976665 Mon Sep 17 00:00:00 2001 From: aviau Date: Wed, 22 Apr 2015 16:18:10 -0400 Subject: [PATCH] Fixed issue where filter_dict_list_with_live_query is called too often Change-Id: Id75ee77c928399059b27309937fc664a61389fa3 --- .../api/handlers/status/live_host_handler.py | 12 ++-- .../handlers/status/live_service_handler.py | 12 ++-- .../controllers/v2/status/test_services.py | 64 +++++++++++++++---- 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/surveil/api/handlers/status/live_host_handler.py b/surveil/api/handlers/status/live_host_handler.py index 3190daa..a6028e0 100644 --- a/surveil/api/handlers/status/live_host_handler.py +++ b/surveil/api/handlers/status/live_host_handler.py @@ -45,7 +45,7 @@ class HostHandler(handler.Handler): # Values "state": first_entry['state'], - "acknowledged": first_entry['acknowledged'], + "acknowledged": int(first_entry['acknowledged']), "last_check": int(first_entry['last_check']), "last_state_change": int(first_entry['last_state_change']), "plugin_output": first_entry['output'] @@ -53,11 +53,11 @@ class HostHandler(handler.Handler): host_dicts.append(host_dict) - if live_query: - host_dicts = query_filter.filter_dict_list_with_live_query( - host_dicts, - live_query - ) + if live_query: + host_dicts = query_filter.filter_dict_list_with_live_query( + host_dicts, + live_query + ) hosts = [] for host_dict in host_dicts: diff --git a/surveil/api/handlers/status/live_service_handler.py b/surveil/api/handlers/status/live_service_handler.py index 6c6610e..7491387 100644 --- a/surveil/api/handlers/status/live_service_handler.py +++ b/surveil/api/handlers/status/live_service_handler.py @@ -43,7 +43,7 @@ class ServiceHandler(handler.Handler): "host_name": item[0][1]['host_name'], "description": item[0][1]['service_description'], "state": first_entry['state'], - "acknowledged": first_entry['acknowledged'], + "acknowledged": int(first_entry['acknowledged']), "last_check": int(first_entry['last_check']), "last_state_change": int(first_entry['last_state_change']), "plugin_output": first_entry['output'] @@ -51,11 +51,11 @@ class ServiceHandler(handler.Handler): service_dicts.append(service_dict) - if live_query: - service_dicts = query_filter.filter_dict_list_with_live_query( - service_dicts, - live_query - ) + if live_query: + service_dicts = query_filter.filter_dict_list_with_live_query( + service_dicts, + live_query + ) services = [] for service_dict in service_dicts: diff --git a/surveil/tests/api/controllers/v2/status/test_services.py b/surveil/tests/api/controllers/v2/status/test_services.py index e1e43d5..1e9dcf7 100644 --- a/surveil/tests/api/controllers/v2/status/test_services.py +++ b/surveil/tests/api/controllers/v2/status/test_services.py @@ -23,20 +23,56 @@ class TestStatusServices(functionalTest.FunctionalTest): def setUp(self): super(TestStatusServices, self).setUp() - self.influxdb_response = ( - '{"results":[{"series":[{"name":"SERVICE_STATE","tags":{"host_nam' - 'e":"test_keystone","service_description":"Check KeyStone service' - '."},"columns":["time","last_check","last_state_change","output",' - '"state","state_type","acknowledged"],"values":[["2015-04-19T18:2' - '0:34Z",1.429467634e+09,1.429467636632134e+09,"There was no suita' - 'ble authentication url for this request",3,"SOFT",0]]},{"name":"' - 'SERVICE_STATE","tags":{"host_name":"ws-arbiter","service_descrip' - 'tion":"check-ws-arbiter"},"columns":["time","last_check","last_s' - 'tate_change","output","state","state_type","acknowledged"],"valu' - 'es":[["2015-04-19T18:20:33Z",1.429467633e+09,1.429467635629833e+' - '09,"TCP OK - 0.000 second response time on port 7760",0,"HARD",0' - ']]}]}]}' - ) + self.influxdb_response = json.dumps({ + "results": [ + {"series": [ + {"name": "SERVICE_STATE", + "tags": {"host_name": "test_keystone", + "service_description": + "Check KeyStone service."}, + "columns": [ + "time", + "last_check", + "last_state_change", + "output", + "state", + "state_type", + "acknowledged" + ], + "values":[ + ["2015-04-19T18:20:34Z", + 1.429467634e+09, + 1.429467636632134e+09, + ("There was no suitable " + "authentication url for this request"), + 3, + "SOFT", + 0] + ]}, + {"name": "SERVICE_STATE", + "tags": {"host_name": "ws-arbiter", + "service_description": "check-ws-arbiter"}, + "columns": [ + "time", + "last_check", + "last_state_change", + "output", + "state", + "state_type", + "acknowledged" + ], + "values":[ + ["2015-04-19T18:20:33Z", + 1.429467633e+09, + 1.429467635629833e+09, + "TCP OK - 0.000 second response time on port 7760", + 0, + "HARD", + 0] + ]} + ]} + ] + }) @httpretty.activate def test_get_all_services(self):