diff --git a/surveil/api/controllers/v2/config/businessimpactmodulations.py b/surveil/api/controllers/v2/config/businessimpactmodulations.py index 2b7bf33..1a9978a 100644 --- a/surveil/api/controllers/v2/config/businessimpactmodulations.py +++ b/surveil/api/controllers/v2/config/businessimpactmodulations.py @@ -18,6 +18,7 @@ from pecan import rest import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import businessimpactmodulation as mod +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import businessimpactmodulation_handler as bh from surveil.common import util @@ -30,11 +31,11 @@ class BusinessImpactModulationsController(rest.RestController): businessimpactmodulation_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([mod.BusinessImpactModulation]) - def get_all(self): + @wsme_pecan.wsexpose([mod.BusinessImpactModulation], body=lq.LiveQuery) + def post(self, data): """Returns all business impact modulations.""" handler = bh.BusinessImpactModulationHandler(pecan.request) - modulations = handler.get_all() + modulations = handler.get_all(data) return modulations @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/checkmodulations.py b/surveil/api/controllers/v2/config/checkmodulations.py index 1007977..ceceb06 100644 --- a/surveil/api/controllers/v2/config/checkmodulations.py +++ b/surveil/api/controllers/v2/config/checkmodulations.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import checkmodulation +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import checkmodulation_handler from surveil.common import util @@ -30,11 +31,11 @@ class CheckModulationsController(rest.RestController): return CheckModulationController(checkmodulation_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([checkmodulation.CheckModulation]) - def get_all(self): + @wsme_pecan.wsexpose([checkmodulation.CheckModulation], body=lq.LiveQuery) + def post(self, data): """Returns all check modulations.""" handler = checkmodulation_handler.CheckModulationHandler(pecan.request) - checkmodulations = handler.get_all() + checkmodulations = handler.get_all(data) return checkmodulations @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/commands.py b/surveil/api/controllers/v2/config/commands.py index b38d937..96a6932 100644 --- a/surveil/api/controllers/v2/config/commands.py +++ b/surveil/api/controllers/v2/config/commands.py @@ -17,6 +17,7 @@ from pecan import rest import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import command +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import command_handler from surveil.common import util @@ -60,11 +61,11 @@ class CommandsController(rest.RestController): return CommandController(command_id), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([command.Command]) - def get_all(self): + @wsme_pecan.wsexpose([command.Command], body=lq.LiveQuery) + def post(self, data): """Returns all commands.""" handler = command_handler.CommandHandler(pecan.request) - commands = handler.get_all() + commands = handler.get_all(data) return commands @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/contactgroups.py b/surveil/api/controllers/v2/config/contactgroups.py index 6fd1daf..7ce3800 100644 --- a/surveil/api/controllers/v2/config/contactgroups.py +++ b/surveil/api/controllers/v2/config/contactgroups.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import contactgroup +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import contactgroup_handler from surveil.common import util @@ -30,11 +31,11 @@ class ContactGroupsController(rest.RestController): return ContactGroupController(contactgroup_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([contactgroup.ContactGroup]) - def get_all(self): + @wsme_pecan.wsexpose([contactgroup.ContactGroup], body=lq.LiveQuery) + def post(self, data): """Returns all contact groups.""" handler = contactgroup_handler.ContactGroupHandler(pecan.request) - contact_groups = handler.get_all() + contact_groups = handler.get_all(data) return contact_groups @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/contacts.py b/surveil/api/controllers/v2/config/contacts.py index 78c6ff1..2e1ad8f 100644 --- a/surveil/api/controllers/v2/config/contacts.py +++ b/surveil/api/controllers/v2/config/contacts.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import contact +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import contact_handler from surveil.common import util @@ -30,11 +31,11 @@ class ContactsController(rest.RestController): return ContactController(contact_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([contact.Contact]) - def get_all(self): + @wsme_pecan.wsexpose([contact.Contact], body=lq.LiveQuery) + def post(self, data): """Returns all contacts.""" handler = contact_handler.ContactHandler(pecan.request) - hosts = handler.get_all() + hosts = handler.get_all(data) return hosts @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/hostgroups.py b/surveil/api/controllers/v2/config/hostgroups.py index fab910b..a1142ce 100644 --- a/surveil/api/controllers/v2/config/hostgroups.py +++ b/surveil/api/controllers/v2/config/hostgroups.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import hostgroup +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import hostgroup_handler from surveil.common import util @@ -30,11 +31,11 @@ class HostGroupsController(rest.RestController): return HostGroupController(hostgroup_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([hostgroup.HostGroup]) - def get_all(self): + @wsme_pecan.wsexpose([hostgroup.HostGroup], body=lq.LiveQuery) + def post(self, data): """Returns all host groups.""" handler = hostgroup_handler.HostGroupHandler(pecan.request) - host_groups = handler.get_all() + host_groups = handler.get_all(data) return host_groups @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/hosts.py b/surveil/api/controllers/v2/config/hosts.py index da195cf..61c88be 100644 --- a/surveil/api/controllers/v2/config/hosts.py +++ b/surveil/api/controllers/v2/config/hosts.py @@ -18,6 +18,7 @@ import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import host from surveil.api.datamodel.config import service +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import host_handler from surveil.api.handlers.config import service_handler from surveil.common import util @@ -66,9 +67,9 @@ class HostServicesSubController(rest.RestController): def get_all(self): """Returns all services assocaited with this host.""" handler = service_handler.ServiceHandler(pecan.request) - services = handler.get_all( - host_name=pecan.request.context['host_name'] - ) + services = handler.get_all(lq.LiveQuery( + filters='{"is":{"host_name": ["%s"]}}' + % pecan.request.context['host_name'])) return services @pecan.expose() @@ -123,13 +124,11 @@ class HostsController(rest.RestController): return HostController(host_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([host.Host], int) - def get_all(self, templates=0): + @wsme_pecan.wsexpose([host.Host], body=lq.LiveQuery) + def post(self, data): """Returns all hosts.""" handler = host_handler.HostHandler(pecan.request) - hosts = handler.get_all( - exclude_templates=(not bool(templates)) - ) + hosts = handler.get_all(data) return hosts @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/macromodulations.py b/surveil/api/controllers/v2/config/macromodulations.py index 912456e..606f0de 100644 --- a/surveil/api/controllers/v2/config/macromodulations.py +++ b/surveil/api/controllers/v2/config/macromodulations.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import macromodulation +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import macromodulation_handler from surveil.common import util @@ -30,11 +31,11 @@ class MacroModulationsController(rest.RestController): return MacroModulationController(macromodulation_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([macromodulation.MacroModulation]) - def get_all(self): + @wsme_pecan.wsexpose([macromodulation.MacroModulation], body=lq.LiveQuery) + def post(self, data): """Returns all macro modulation objects.""" handler = macromodulation_handler.MacroModulationHandler(pecan.request) - modulations = handler.get_all() + modulations = handler.get_all(data) return modulations @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/notificationways.py b/surveil/api/controllers/v2/config/notificationways.py index 9995e3b..5d32fbc 100644 --- a/surveil/api/controllers/v2/config/notificationways.py +++ b/surveil/api/controllers/v2/config/notificationways.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import notificationway +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import notificationway_handler from surveil.common import util @@ -30,11 +31,11 @@ class NotificationWaysController(rest.RestController): return NotificationWayController(notificationway_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([notificationway.NotificationWay]) - def get_all(self): + @wsme_pecan.wsexpose([notificationway.NotificationWay], body=lq.LiveQuery) + def post(self, data): """Returns all notification ways.""" handler = notificationway_handler.NotificationWayHandler(pecan.request) - notificationsway = handler.get_all() + notificationsway = handler.get_all(data) return notificationsway @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/realms.py b/surveil/api/controllers/v2/config/realms.py index ef15983..5c04c58 100644 --- a/surveil/api/controllers/v2/config/realms.py +++ b/surveil/api/controllers/v2/config/realms.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import realm +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import realm_handler from surveil.common import util @@ -30,11 +31,11 @@ class RealmsController(rest.RestController): return RealmController(realm_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([realm.Realm]) - def get_all(self): + @wsme_pecan.wsexpose([realm.Realm], body=lq.LiveQuery) + def post(self, data): """Returns all realms.""" handler = realm_handler.RealmHandler(pecan.request) - realms = handler.get_all() + realms = handler.get_all(data) return realms @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/servicegroup.py b/surveil/api/controllers/v2/config/servicegroup.py index b03653f..e5d497e 100644 --- a/surveil/api/controllers/v2/config/servicegroup.py +++ b/surveil/api/controllers/v2/config/servicegroup.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import servicegroup +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import servicegroup_handler from surveil.common import util @@ -30,11 +31,11 @@ class ServiceGroupsController(rest.RestController): return ServiceGroupController(servicegroup_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([servicegroup.ServiceGroup]) - def get_all(self): + @wsme_pecan.wsexpose([servicegroup.ServiceGroup], body=lq.LiveQuery) + def post(self, data): """Returns all service groups.""" handler = servicegroup_handler.ServiceGroupHandler(pecan.request) - service_groups = handler.get_all() + service_groups = handler.get_all(data) return service_groups @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/services.py b/surveil/api/controllers/v2/config/services.py index 3fc4bc8..33300a9 100644 --- a/surveil/api/controllers/v2/config/services.py +++ b/surveil/api/controllers/v2/config/services.py @@ -17,6 +17,7 @@ from pecan import rest import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import service +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import service_handler from surveil.common import util @@ -24,13 +25,11 @@ from surveil.common import util class ServicesController(rest.RestController): @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([service.Service], int) - def get_all(self, templates=0): + @wsme_pecan.wsexpose([service.Service], body=lq.LiveQuery) + def post(self, data): """Returns all services.""" handler = service_handler.ServiceHandler(pecan.request) - services = handler.get_all( - exclude_templates=(not bool(templates)) - ) + services = handler.get_all(data) return services @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/config/timeperiods.py b/surveil/api/controllers/v2/config/timeperiods.py index d417c22..a467d49 100644 --- a/surveil/api/controllers/v2/config/timeperiods.py +++ b/surveil/api/controllers/v2/config/timeperiods.py @@ -19,6 +19,7 @@ import wsme.types as wtypes import wsmeext.pecan as wsme_pecan from surveil.api.datamodel.config import timeperiod +from surveil.api.datamodel import live_query as lq from surveil.api.handlers.config import timeperiod_handler from surveil.common import util @@ -30,11 +31,11 @@ class TimePeriodsController(rest.RestController): return TimePeriodController(timeperiod_name), remainder @util.policy_enforce(['authenticated']) - @wsme_pecan.wsexpose([timeperiod.TimePeriod]) - def get_all(self): + @wsme_pecan.wsexpose([timeperiod.TimePeriod], body=lq.LiveQuery) + def post(self, data): """Returns all time periods.""" handler = timeperiod_handler.TimePeriodHandler(pecan.request) - time_periods = handler.get_all() + time_periods = handler.get_all(data) return time_periods @util.policy_enforce(['authenticated']) diff --git a/surveil/api/controllers/v2/status/events/events.py b/surveil/api/controllers/v2/status/events/events.py index f73ddaf..b681a9b 100644 --- a/surveil/api/controllers/v2/status/events/events.py +++ b/surveil/api/controllers/v2/status/events/events.py @@ -16,8 +16,8 @@ import pecan from pecan import rest import wsmeext.pecan as wsme_pecan +from surveil.api.datamodel import live_query from surveil.api.datamodel.status import event -from surveil.api.datamodel.status import live_query from surveil.api.handlers.status import event_handler from surveil.common import util diff --git a/surveil/api/controllers/v2/status/hosts/hosts.py b/surveil/api/controllers/v2/status/hosts/hosts.py index e588cdf..bd55420 100644 --- a/surveil/api/controllers/v2/status/hosts/hosts.py +++ b/surveil/api/controllers/v2/status/hosts/hosts.py @@ -20,8 +20,8 @@ from surveil.api.controllers.v2.status.hosts import metrics as host_metrics from surveil.api.controllers.v2.status.hosts import results as host_results from surveil.api.controllers.v2.status.hosts.services import ( services as host_services) +from surveil.api.datamodel import live_query from surveil.api.datamodel.status import live_host -from surveil.api.datamodel.status import live_query from surveil.api.handlers.status import live_host_handler from surveil.common import util diff --git a/surveil/api/controllers/v2/status/hosts/metrics.py b/surveil/api/controllers/v2/status/hosts/metrics.py index dfdfdfb..ffe37aa 100644 --- a/surveil/api/controllers/v2/status/hosts/metrics.py +++ b/surveil/api/controllers/v2/status/hosts/metrics.py @@ -16,7 +16,7 @@ import pecan from pecan import rest import wsmeext.pecan as wsme_pecan -from surveil.api.datamodel.status import live_query +from surveil.api.datamodel import live_query from surveil.api.datamodel.status.metrics import metric as m from surveil.api.handlers.status.metrics import metric_handler from surveil.api.handlers.status.metrics import metric_name_handler diff --git a/surveil/api/controllers/v2/status/hosts/services/metrics.py b/surveil/api/controllers/v2/status/hosts/services/metrics.py index 6bc32fa..55db83a 100644 --- a/surveil/api/controllers/v2/status/hosts/services/metrics.py +++ b/surveil/api/controllers/v2/status/hosts/services/metrics.py @@ -16,7 +16,7 @@ import pecan from pecan import rest import wsmeext.pecan as wsme_pecan -from surveil.api.datamodel.status import live_query +from surveil.api.datamodel import live_query from surveil.api.datamodel.status.metrics import metric as m from surveil.api.handlers.status.metrics import metric_handler from surveil.api.handlers.status.metrics import metric_name_handler diff --git a/surveil/api/controllers/v2/status/services/services.py b/surveil/api/controllers/v2/status/services/services.py index 5413247..6c5e80c 100644 --- a/surveil/api/controllers/v2/status/services/services.py +++ b/surveil/api/controllers/v2/status/services/services.py @@ -16,7 +16,7 @@ import pecan from pecan import rest import wsmeext.pecan as wsme_pecan -from surveil.api.datamodel.status import live_query +from surveil.api.datamodel import live_query from surveil.api.datamodel.status import live_service from surveil.api.handlers.status import live_service_handler from surveil.common import util diff --git a/surveil/api/datamodel/status/live_query.py b/surveil/api/datamodel/live_query.py similarity index 100% rename from surveil/api/datamodel/status/live_query.py rename to surveil/api/datamodel/live_query.py diff --git a/surveil/api/handlers/config/mongoengine_query.py b/surveil/api/handlers/config/mongoengine_query.py new file mode 100644 index 0000000..406de9b --- /dev/null +++ b/surveil/api/handlers/config/mongoengine_query.py @@ -0,0 +1,52 @@ +# Copyright 2015 - Savoir-Faire Linux inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import json + + +def build_mongoengine_query(live_query): + + # Build the filters + query = {} + kwargs = None + fields = [] + + if live_query.fields: + for field in live_query.fields: + fields.append(field) + + if live_query.filters and json.loads(live_query.filters).items(): + for filter_name, filter_data in json.loads(live_query.filters).items(): + for field, value in filter_data.items(): + query.update(_get_mongoengine_filter(field, + filter_name, + value)) + + live_query.paging + if live_query.paging: + paging = live_query.paging + skip = paging.size * paging.page + limit = skip + paging.size + kwargs = slice(skip, limit) + else: + kwargs = slice(None, None) + return fields, query, kwargs + + +def _get_mongoengine_filter(field_name, filter_name, value): + filters = { + "is": field_name + "__in", + "isnot": field_name + "__nin" + } + return {filters[filter_name]: value} \ No newline at end of file diff --git a/surveil/api/handlers/mongodb_mongoengine_object_handler.py b/surveil/api/handlers/mongodb_mongoengine_object_handler.py index d445b19..656f29c 100644 --- a/surveil/api/handlers/mongodb_mongoengine_object_handler.py +++ b/surveil/api/handlers/mongodb_mongoengine_object_handler.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from surveil.api.handlers.config import mongoengine_query from surveil.api.handlers import handler @@ -60,16 +61,27 @@ class MongoObjectHandler(handler.Handler): r = self.resource_storage(**resource.as_dict()) r.save() - def get_all(self, identifier=None, exclude_templates=False, **kwargs): + def get_all(self, lq={}): """Return all resources.""" - identifier = identifier or {} - if exclude_templates is True: - identifier.update( - {"register__ne": "0"} - ) - return [ + fields, query, kwargs = mongoengine_query.build_mongoengine_query(lq) + + resp = [ self.resource_datamodel(**self._get_dict(r)) for r - in self.resource_storage.objects(**identifier) - ] + in self.resource_storage.objects(**query) + ][kwargs] + + resp_field = [] + + if fields: + for obj in resp: + obj_with_field = {} + for field in fields: + obj_with_field[field] = obj[field] + resp_field.append(obj_with_field) + + else: + resp_field = resp + + return resp_field diff --git a/surveil/api/handlers/status/metrics/metric_handler.py b/surveil/api/handlers/status/metrics/metric_handler.py index f4ca567..fd0ddad 100644 --- a/surveil/api/handlers/status/metrics/metric_handler.py +++ b/surveil/api/handlers/status/metrics/metric_handler.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from surveil.api.datamodel.status import live_query as q +from surveil.api.datamodel import live_query as q from surveil.api.datamodel.status.metrics import metric as m from surveil.api.handlers import handler from surveil.api.handlers.status import influxdb_query diff --git a/surveil/tests/api/config/__init__.py b/surveil/tests/api/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/surveil/tests/api/config/test_mongolive_query.py b/surveil/tests/api/config/test_mongolive_query.py new file mode 100644 index 0000000..9ed0291 --- /dev/null +++ b/surveil/tests/api/config/test_mongolive_query.py @@ -0,0 +1,62 @@ +# Copyright 2015 - Savoir-Faire Linux inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import json + +from surveil.api.datamodel import live_query +from surveil.api.datamodel.status import paging +from surveil.api.handlers.config import mongoengine_query +from surveil.tests import base + + +class MongoliveQueryTest(base.BaseTestCase): + + def test_build_mongo_query(self): + query = live_query.LiveQuery( + fields=['host_name', 'last_check'], + filters=json.dumps({ + "isnot": { + "state": ["0", "1"], + "host_state": ["2"] + }, + "is": { + "event_type": ["ALERT"] + } + }), + paging=paging.Paging( + page=3, + size=100 + ) + + ) + + fields, query, kwargs = mongoengine_query.build_mongoengine_query( + query) + + self.assertEqual( + fields, + ['host_name', 'last_check'] + ) + + self.assertEqual( + query, + {"state__nin": ["0", "1"], + "host_state__nin": ["2"], + "event_type__in": ["ALERT"]}, + ) + + self.assertEqual( + kwargs, + slice(300, 400) + ) \ No newline at end of file diff --git a/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py b/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py index 66d56d7..840db20 100644 --- a/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py +++ b/surveil/tests/api/controllers/v2/config/test_businessimpactmodulations.py @@ -40,7 +40,8 @@ class TestBusinessImpactModulationController(functionalTest.FunctionalTest): ) def test_get_all_modulations(self): - response = self.get('/v2/config/businessimpactmodulations') + response = self.post_json('/v2/config/businessimpactmodulations', + params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_checkmodulation.py b/surveil/tests/api/controllers/v2/config/test_checkmodulation.py index 42ddcdf..d840885 100644 --- a/surveil/tests/api/controllers/v2/config/test_checkmodulation.py +++ b/surveil/tests/api/controllers/v2/config/test_checkmodulation.py @@ -40,7 +40,7 @@ class TestCheckModulationsController(functionalTest.FunctionalTest): ) def test_get_all_checkmodulations(self): - response = self.get('/v2/config/checkmodulations') + response = self.post_json('/v2/config/checkmodulations', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_commands.py b/surveil/tests/api/controllers/v2/config/test_commands.py index ec5c06f..e97c71e 100644 --- a/surveil/tests/api/controllers/v2/config/test_commands.py +++ b/surveil/tests/api/controllers/v2/config/test_commands.py @@ -34,7 +34,7 @@ class TestCommandController(functionalTest.FunctionalTest): ) def test_get_all_commands(self): - response = self.get('/v2/config/commands') + response = self.post_json('/v2/config/commands', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_contactgroup.py b/surveil/tests/api/controllers/v2/config/test_contactgroup.py index 076b31e..87fd5cd 100644 --- a/surveil/tests/api/controllers/v2/config/test_contactgroup.py +++ b/surveil/tests/api/controllers/v2/config/test_contactgroup.py @@ -49,7 +49,7 @@ class TestContactGroupsController(functionalTest.FunctionalTest): ) def test_get_all_contactgroups(self): - response = self.get('/v2/config/contactgroups') + response = self.post_json('/v2/config/contactgroups', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_contacts.py b/surveil/tests/api/controllers/v2/config/test_contacts.py index a8b4c85..7ae2942 100644 --- a/surveil/tests/api/controllers/v2/config/test_contacts.py +++ b/surveil/tests/api/controllers/v2/config/test_contacts.py @@ -47,7 +47,7 @@ class TestContactsController(functionalTest.FunctionalTest): ) def test_get_all_contacts(self): - response = self.get('/v2/config/contacts') + response = self.post_json('/v2/config/contacts', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_hostgroup.py b/surveil/tests/api/controllers/v2/config/test_hostgroup.py index d948bf7..1fac290 100644 --- a/surveil/tests/api/controllers/v2/config/test_hostgroup.py +++ b/surveil/tests/api/controllers/v2/config/test_hostgroup.py @@ -49,7 +49,7 @@ class TestHostGroupsController(functionalTest.FunctionalTest): ) def test_get_all_hostgroups(self): - response = self.get('/v2/config/hostgroups') + response = self.post_json('/v2/config/hostgroups', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_hosts.py b/surveil/tests/api/controllers/v2/config/test_hosts.py index 5d5bdbf..88e3a28 100644 --- a/surveil/tests/api/controllers/v2/config/test_hosts.py +++ b/surveil/tests/api/controllers/v2/config/test_hosts.py @@ -88,7 +88,7 @@ class TestHostController(functionalTest.FunctionalTest): ) def test_get_all_hosts(self): - response = self.get('/v2/config/hosts') + response = self.post_json('/v2/config/hosts', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), @@ -112,17 +112,28 @@ class TestHostController(functionalTest.FunctionalTest): "use": []} ) ) - response = self.get('/v2/config/hosts') + post_lq = {"filters": '{"is":{"register": "0"}}'} + response = self.post_json('/v2/config/hosts', params=post_lq) self.assert_count_equal_backport( json.loads(response.body.decode()), - self.hosts + [{"host_name": "bogus-router345345", + "address": "192.168.1.254", + "max_check_attempts": 5, + "check_period": "24x7", + "contacts": ["admin", "carl"], + "contact_groups": ["router-admins"], + "notification_interval": 30, + "notification_period": "24x7", + "register": "0", + "custom_fields": {}, + "use": []}] ) - response = self.get('/v2/config/hosts', params={'templates': 1}) + response = self.post_json('/v2/config/hosts', params=post_lq) self.assertEqual( len(json.loads(response.body.decode())), - len(self.hosts) + 1 + 1 ) self.assertEqual(response.status_int, 200) diff --git a/surveil/tests/api/controllers/v2/config/test_macromodulations.py b/surveil/tests/api/controllers/v2/config/test_macromodulations.py index e27d040..1ce0797 100644 --- a/surveil/tests/api/controllers/v2/config/test_macromodulations.py +++ b/surveil/tests/api/controllers/v2/config/test_macromodulations.py @@ -46,7 +46,7 @@ class TestMacroModulationController(functionalTest.FunctionalTest): ) def test_get_all_macromodulations(self): - response = self.get('/v2/config/macromodulations') + response = self.post_json('/v2/config/macromodulations', params={}) self.assert_count_equal_backport( [ diff --git a/surveil/tests/api/controllers/v2/config/test_notificationways.py b/surveil/tests/api/controllers/v2/config/test_notificationways.py index 196fb35..36893e4 100644 --- a/surveil/tests/api/controllers/v2/config/test_notificationways.py +++ b/surveil/tests/api/controllers/v2/config/test_notificationways.py @@ -49,7 +49,7 @@ class TestNotificationWayController(functionalTest.FunctionalTest): ) def test_get_all_notificationways(self): - response = self.get('/v2/config/notificationways') + response = self.post_json('/v2/config/notificationways', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_realms.py b/surveil/tests/api/controllers/v2/config/test_realms.py index 65f6910..97a26a5 100644 --- a/surveil/tests/api/controllers/v2/config/test_realms.py +++ b/surveil/tests/api/controllers/v2/config/test_realms.py @@ -41,7 +41,7 @@ class TestRealmsController(functionalTest.FunctionalTest): ) def test_get_all_realms(self): - response = self.get('/v2/config/realms') + response = self.post_json('/v2/config/realms', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_servicegroup.py b/surveil/tests/api/controllers/v2/config/test_servicegroup.py index cd8cf5e..799f2f4 100644 --- a/surveil/tests/api/controllers/v2/config/test_servicegroup.py +++ b/surveil/tests/api/controllers/v2/config/test_servicegroup.py @@ -50,7 +50,7 @@ class TestServiceGroupsController(functionalTest.FunctionalTest): ) def test_get_all_servicegroups(self): - response = self.get('/v2/config/servicegroups') + response = self.post_json('/v2/config/servicegroups', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/controllers/v2/config/test_services.py b/surveil/tests/api/controllers/v2/config/test_services.py index 857c5de..73be915 100644 --- a/surveil/tests/api/controllers/v2/config/test_services.py +++ b/surveil/tests/api/controllers/v2/config/test_services.py @@ -79,7 +79,7 @@ class TestServiceController(functionalTest.FunctionalTest): ) def test_get_all_services(self): - response = self.get('/v2/config/services') + response = self.post_json('/v2/config/services', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), @@ -101,21 +101,36 @@ class TestServiceController(functionalTest.FunctionalTest): "notification_period": "24x7", "contacts": ["surveil-ptl", "surveil-bob"], "register": "0", - "contact_groups": ["linux-admins"]} + "contact_groups": ["linux-admins"], + "use": []} ) ) - response = self.get('/v2/config/services') + + post_lq = {"filters": '{"is":{"register": "0"}}'} + response = self.post_json('/v2/config/services', params=post_lq) self.assert_count_equal_backport( json.loads(response.body.decode()), - self.services + [{"host_name": ["sample-server444"], + "service_description": "check-disk-sdb2", + "check_command": "check-disk!/dev/sdb1", + "max_check_attempts": 5, + "check_interval": 5, + "retry_interval": 3, + "check_period": "24x7", + "notification_interval": 30, + "notification_period": "24x7", + "contacts": ["surveil-ptl", "surveil-bob"], + "register": "0", + "contact_groups": ["linux-admins"], + "use":[]}] ) - response = self.get('/v2/config/services', params={"templates": 1}) + response = self.post_json('/v2/config/services', params=post_lq) self.assertEqual( len(json.loads(response.body.decode())), - len(self.services) + 1 + 1 ) self.assertEqual(response.status_int, 200) diff --git a/surveil/tests/api/controllers/v2/config/test_timeperiods.py b/surveil/tests/api/controllers/v2/config/test_timeperiods.py index 91862f4..902f3e3 100644 --- a/surveil/tests/api/controllers/v2/config/test_timeperiods.py +++ b/surveil/tests/api/controllers/v2/config/test_timeperiods.py @@ -44,7 +44,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest): ) def test_get_all_timeperiods(self): - response = self.get('/v2/config/timeperiods') + response = self.post_json('/v2/config/timeperiods', params={}) self.assert_count_equal_backport( json.loads(response.body.decode()), diff --git a/surveil/tests/api/handlers/live/test_fields_filter.py b/surveil/tests/api/handlers/live/test_fields_filter.py index 0eb1ba5..5373c97 100644 --- a/surveil/tests/api/handlers/live/test_fields_filter.py +++ b/surveil/tests/api/handlers/live/test_fields_filter.py @@ -14,7 +14,7 @@ import json -from surveil.api.datamodel.status import live_query +from surveil.api.datamodel import live_query from surveil.api.handlers.status import fields_filter from surveil.tests import base diff --git a/surveil/tests/api/handlers/live/test_influxdb_query.py b/surveil/tests/api/handlers/live/test_influxdb_query.py index 3b956f8..9b676d2 100644 --- a/surveil/tests/api/handlers/live/test_influxdb_query.py +++ b/surveil/tests/api/handlers/live/test_influxdb_query.py @@ -14,7 +14,7 @@ import json -from surveil.api.datamodel.status import live_query +from surveil.api.datamodel import live_query from surveil.api.datamodel.status.metrics import time_interval from surveil.api.handlers.status import influxdb_query from surveil.tests import base diff --git a/surveil/tests/api/handlers/live/test_mongodb_query.py b/surveil/tests/api/handlers/live/test_mongodb_query.py index a5f4a90..e695062 100644 --- a/surveil/tests/api/handlers/live/test_mongodb_query.py +++ b/surveil/tests/api/handlers/live/test_mongodb_query.py @@ -14,7 +14,7 @@ import json -from surveil.api.datamodel.status import live_query +from surveil.api.datamodel import live_query from surveil.api.datamodel.status import paging from surveil.api.handlers.status import mongodb_query from surveil.tests import base