diff --git a/surveil/api/datamodel/live_query.py b/surveil/api/datamodel/live_query.py index 24b3206..e7af0b6 100644 --- a/surveil/api/datamodel/live_query.py +++ b/surveil/api/datamodel/live_query.py @@ -56,6 +56,9 @@ class LiveQuery(types.Base): }, "is": { "event_type": ["ALERT"] + }, + "defined": { + "name": True } }) ) diff --git a/surveil/api/handlers/config/mongoengine_query.py b/surveil/api/handlers/config/mongoengine_query.py index 406de9b..a8349cb 100644 --- a/surveil/api/handlers/config/mongoengine_query.py +++ b/surveil/api/handlers/config/mongoengine_query.py @@ -47,6 +47,7 @@ def build_mongoengine_query(live_query): def _get_mongoengine_filter(field_name, filter_name, value): filters = { "is": field_name + "__in", - "isnot": field_name + "__nin" + "isnot": field_name + "__nin", + "defined": field_name + "__exists" } return {filters[filter_name]: value} \ No newline at end of file diff --git a/surveil/tests/api/config/test_mongolive_query.py b/surveil/tests/api/config/test_mongolive_query.py index 9ed0291..33db13e 100644 --- a/surveil/tests/api/config/test_mongolive_query.py +++ b/surveil/tests/api/config/test_mongolive_query.py @@ -32,6 +32,9 @@ class MongoliveQueryTest(base.BaseTestCase): }, "is": { "event_type": ["ALERT"] + }, + "defined": { + "name": True } }), paging=paging.Paging( @@ -53,7 +56,8 @@ class MongoliveQueryTest(base.BaseTestCase): query, {"state__nin": ["0", "1"], "host_state__nin": ["2"], - "event_type__in": ["ALERT"]}, + "event_type__in": ["ALERT"], + "name__exists": True, } ) self.assertEqual( diff --git a/surveil/tests/api/controllers/v2/config/test_hosts.py b/surveil/tests/api/controllers/v2/config/test_hosts.py index 88e3a28..910a8a4 100644 --- a/surveil/tests/api/controllers/v2/config/test_hosts.py +++ b/surveil/tests/api/controllers/v2/config/test_hosts.py @@ -107,12 +107,14 @@ class TestHostController(functionalTest.FunctionalTest): "contact_groups": ["router-admins"], "notification_interval": 30, "notification_period": "24x7", + "name": "Template", "register": "0", "custom_fields": {}, "use": []} ) ) - post_lq = {"filters": '{"is":{"register": "0"}}'} + post_lq = {"filters": '{"is":{"register": "0"},' + '"defined":{"name": "True"}}'} response = self.post_json('/v2/config/hosts', params=post_lq) self.assert_count_equal_backport( @@ -125,6 +127,7 @@ class TestHostController(functionalTest.FunctionalTest): "contact_groups": ["router-admins"], "notification_interval": 30, "notification_period": "24x7", + "name": "Template", "register": "0", "custom_fields": {}, "use": []}] diff --git a/surveil/tests/api/controllers/v2/config/test_services.py b/surveil/tests/api/controllers/v2/config/test_services.py index 73be915..8ac091e 100644 --- a/surveil/tests/api/controllers/v2/config/test_services.py +++ b/surveil/tests/api/controllers/v2/config/test_services.py @@ -100,13 +100,15 @@ class TestServiceController(functionalTest.FunctionalTest): "notification_interval": 30, "notification_period": "24x7", "contacts": ["surveil-ptl", "surveil-bob"], + "name": "Template", "register": "0", "contact_groups": ["linux-admins"], "use": []} ) ) - post_lq = {"filters": '{"is":{"register": "0"}}'} + post_lq = {"filters": '{"is":{"register": "0"},' + '"defined":{"name": "True"}}'} response = self.post_json('/v2/config/services', params=post_lq) self.assert_count_equal_backport( @@ -121,6 +123,7 @@ class TestServiceController(functionalTest.FunctionalTest): "notification_interval": 30, "notification_period": "24x7", "contacts": ["surveil-ptl", "surveil-bob"], + "name": "Template", "register": "0", "contact_groups": ["linux-admins"], "use":[]}]