Change get_all endpoint for config object from GET to POST
Change-Id: I7cfdecf47661b7f063cac51c6fa61eabcf10bfd0
This commit is contained in:
parent
4b2538b37e
commit
d90a7553a7
@ -18,6 +18,7 @@ from pecan import rest
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import businessimpactmodulation as mod
|
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.api.handlers.config import businessimpactmodulation_handler as bh
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class BusinessImpactModulationsController(rest.RestController):
|
|||||||
businessimpactmodulation_name), remainder
|
businessimpactmodulation_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([mod.BusinessImpactModulation])
|
@wsme_pecan.wsexpose([mod.BusinessImpactModulation], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all business impact modulations."""
|
"""Returns all business impact modulations."""
|
||||||
handler = bh.BusinessImpactModulationHandler(pecan.request)
|
handler = bh.BusinessImpactModulationHandler(pecan.request)
|
||||||
modulations = handler.get_all()
|
modulations = handler.get_all(data)
|
||||||
return modulations
|
return modulations
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import checkmodulation
|
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.api.handlers.config import checkmodulation_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class CheckModulationsController(rest.RestController):
|
|||||||
return CheckModulationController(checkmodulation_name), remainder
|
return CheckModulationController(checkmodulation_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([checkmodulation.CheckModulation])
|
@wsme_pecan.wsexpose([checkmodulation.CheckModulation], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all check modulations."""
|
"""Returns all check modulations."""
|
||||||
handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
|
handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
|
||||||
checkmodulations = handler.get_all()
|
checkmodulations = handler.get_all(data)
|
||||||
return checkmodulations
|
return checkmodulations
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -17,6 +17,7 @@ from pecan import rest
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import command
|
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.api.handlers.config import command_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -60,11 +61,11 @@ class CommandsController(rest.RestController):
|
|||||||
return CommandController(command_id), remainder
|
return CommandController(command_id), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([command.Command])
|
@wsme_pecan.wsexpose([command.Command], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all commands."""
|
"""Returns all commands."""
|
||||||
handler = command_handler.CommandHandler(pecan.request)
|
handler = command_handler.CommandHandler(pecan.request)
|
||||||
commands = handler.get_all()
|
commands = handler.get_all(data)
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import contactgroup
|
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.api.handlers.config import contactgroup_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class ContactGroupsController(rest.RestController):
|
|||||||
return ContactGroupController(contactgroup_name), remainder
|
return ContactGroupController(contactgroup_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([contactgroup.ContactGroup])
|
@wsme_pecan.wsexpose([contactgroup.ContactGroup], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all contact groups."""
|
"""Returns all contact groups."""
|
||||||
handler = contactgroup_handler.ContactGroupHandler(pecan.request)
|
handler = contactgroup_handler.ContactGroupHandler(pecan.request)
|
||||||
contact_groups = handler.get_all()
|
contact_groups = handler.get_all(data)
|
||||||
return contact_groups
|
return contact_groups
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import contact
|
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.api.handlers.config import contact_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class ContactsController(rest.RestController):
|
|||||||
return ContactController(contact_name), remainder
|
return ContactController(contact_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([contact.Contact])
|
@wsme_pecan.wsexpose([contact.Contact], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all contacts."""
|
"""Returns all contacts."""
|
||||||
handler = contact_handler.ContactHandler(pecan.request)
|
handler = contact_handler.ContactHandler(pecan.request)
|
||||||
hosts = handler.get_all()
|
hosts = handler.get_all(data)
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import hostgroup
|
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.api.handlers.config import hostgroup_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class HostGroupsController(rest.RestController):
|
|||||||
return HostGroupController(hostgroup_name), remainder
|
return HostGroupController(hostgroup_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([hostgroup.HostGroup])
|
@wsme_pecan.wsexpose([hostgroup.HostGroup], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all host groups."""
|
"""Returns all host groups."""
|
||||||
handler = hostgroup_handler.HostGroupHandler(pecan.request)
|
handler = hostgroup_handler.HostGroupHandler(pecan.request)
|
||||||
host_groups = handler.get_all()
|
host_groups = handler.get_all(data)
|
||||||
return host_groups
|
return host_groups
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -18,6 +18,7 @@ import wsmeext.pecan as wsme_pecan
|
|||||||
|
|
||||||
from surveil.api.datamodel.config import host
|
from surveil.api.datamodel.config import host
|
||||||
from surveil.api.datamodel.config import service
|
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 host_handler
|
||||||
from surveil.api.handlers.config import service_handler
|
from surveil.api.handlers.config import service_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
@ -66,9 +67,9 @@ class HostServicesSubController(rest.RestController):
|
|||||||
def get_all(self):
|
def get_all(self):
|
||||||
"""Returns all services assocaited with this host."""
|
"""Returns all services assocaited with this host."""
|
||||||
handler = service_handler.ServiceHandler(pecan.request)
|
handler = service_handler.ServiceHandler(pecan.request)
|
||||||
services = handler.get_all(
|
services = handler.get_all(lq.LiveQuery(
|
||||||
host_name=pecan.request.context['host_name']
|
filters='{"is":{"host_name": ["%s"]}}'
|
||||||
)
|
% pecan.request.context['host_name']))
|
||||||
return services
|
return services
|
||||||
|
|
||||||
@pecan.expose()
|
@pecan.expose()
|
||||||
@ -123,13 +124,11 @@ class HostsController(rest.RestController):
|
|||||||
return HostController(host_name), remainder
|
return HostController(host_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([host.Host], int)
|
@wsme_pecan.wsexpose([host.Host], body=lq.LiveQuery)
|
||||||
def get_all(self, templates=0):
|
def post(self, data):
|
||||||
"""Returns all hosts."""
|
"""Returns all hosts."""
|
||||||
handler = host_handler.HostHandler(pecan.request)
|
handler = host_handler.HostHandler(pecan.request)
|
||||||
hosts = handler.get_all(
|
hosts = handler.get_all(data)
|
||||||
exclude_templates=(not bool(templates))
|
|
||||||
)
|
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import macromodulation
|
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.api.handlers.config import macromodulation_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class MacroModulationsController(rest.RestController):
|
|||||||
return MacroModulationController(macromodulation_name), remainder
|
return MacroModulationController(macromodulation_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([macromodulation.MacroModulation])
|
@wsme_pecan.wsexpose([macromodulation.MacroModulation], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all macro modulation objects."""
|
"""Returns all macro modulation objects."""
|
||||||
handler = macromodulation_handler.MacroModulationHandler(pecan.request)
|
handler = macromodulation_handler.MacroModulationHandler(pecan.request)
|
||||||
modulations = handler.get_all()
|
modulations = handler.get_all(data)
|
||||||
return modulations
|
return modulations
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import notificationway
|
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.api.handlers.config import notificationway_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class NotificationWaysController(rest.RestController):
|
|||||||
return NotificationWayController(notificationway_name), remainder
|
return NotificationWayController(notificationway_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([notificationway.NotificationWay])
|
@wsme_pecan.wsexpose([notificationway.NotificationWay], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all notification ways."""
|
"""Returns all notification ways."""
|
||||||
handler = notificationway_handler.NotificationWayHandler(pecan.request)
|
handler = notificationway_handler.NotificationWayHandler(pecan.request)
|
||||||
notificationsway = handler.get_all()
|
notificationsway = handler.get_all(data)
|
||||||
return notificationsway
|
return notificationsway
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import realm
|
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.api.handlers.config import realm_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class RealmsController(rest.RestController):
|
|||||||
return RealmController(realm_name), remainder
|
return RealmController(realm_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([realm.Realm])
|
@wsme_pecan.wsexpose([realm.Realm], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all realms."""
|
"""Returns all realms."""
|
||||||
handler = realm_handler.RealmHandler(pecan.request)
|
handler = realm_handler.RealmHandler(pecan.request)
|
||||||
realms = handler.get_all()
|
realms = handler.get_all(data)
|
||||||
return realms
|
return realms
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import servicegroup
|
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.api.handlers.config import servicegroup_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class ServiceGroupsController(rest.RestController):
|
|||||||
return ServiceGroupController(servicegroup_name), remainder
|
return ServiceGroupController(servicegroup_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([servicegroup.ServiceGroup])
|
@wsme_pecan.wsexpose([servicegroup.ServiceGroup], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all service groups."""
|
"""Returns all service groups."""
|
||||||
handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
|
handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
|
||||||
service_groups = handler.get_all()
|
service_groups = handler.get_all(data)
|
||||||
return service_groups
|
return service_groups
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -17,6 +17,7 @@ from pecan import rest
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import service
|
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.api.handlers.config import service_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -24,13 +25,11 @@ from surveil.common import util
|
|||||||
class ServicesController(rest.RestController):
|
class ServicesController(rest.RestController):
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([service.Service], int)
|
@wsme_pecan.wsexpose([service.Service], body=lq.LiveQuery)
|
||||||
def get_all(self, templates=0):
|
def post(self, data):
|
||||||
"""Returns all services."""
|
"""Returns all services."""
|
||||||
handler = service_handler.ServiceHandler(pecan.request)
|
handler = service_handler.ServiceHandler(pecan.request)
|
||||||
services = handler.get_all(
|
services = handler.get_all(data)
|
||||||
exclude_templates=(not bool(templates))
|
|
||||||
)
|
|
||||||
return services
|
return services
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -19,6 +19,7 @@ import wsme.types as wtypes
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.config import timeperiod
|
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.api.handlers.config import timeperiod_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@ -30,11 +31,11 @@ class TimePeriodsController(rest.RestController):
|
|||||||
return TimePeriodController(timeperiod_name), remainder
|
return TimePeriodController(timeperiod_name), remainder
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([timeperiod.TimePeriod])
|
@wsme_pecan.wsexpose([timeperiod.TimePeriod], body=lq.LiveQuery)
|
||||||
def get_all(self):
|
def post(self, data):
|
||||||
"""Returns all time periods."""
|
"""Returns all time periods."""
|
||||||
handler = timeperiod_handler.TimePeriodHandler(pecan.request)
|
handler = timeperiod_handler.TimePeriodHandler(pecan.request)
|
||||||
time_periods = handler.get_all()
|
time_periods = handler.get_all(data)
|
||||||
return time_periods
|
return time_periods
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
|
@ -16,8 +16,8 @@ import pecan
|
|||||||
from pecan import rest
|
from pecan import rest
|
||||||
import wsmeext.pecan as wsme_pecan
|
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 event
|
||||||
from surveil.api.datamodel.status import live_query
|
|
||||||
from surveil.api.handlers.status import event_handler
|
from surveil.api.handlers.status import event_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
|
@ -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 import results as host_results
|
||||||
from surveil.api.controllers.v2.status.hosts.services import (
|
from surveil.api.controllers.v2.status.hosts.services import (
|
||||||
services as host_services)
|
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_host
|
||||||
from surveil.api.datamodel.status import live_query
|
|
||||||
from surveil.api.handlers.status import live_host_handler
|
from surveil.api.handlers.status import live_host_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import pecan
|
|||||||
from pecan import rest
|
from pecan import rest
|
||||||
import wsmeext.pecan as wsme_pecan
|
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.datamodel.status.metrics import metric as m
|
||||||
from surveil.api.handlers.status.metrics import metric_handler
|
from surveil.api.handlers.status.metrics import metric_handler
|
||||||
from surveil.api.handlers.status.metrics import metric_name_handler
|
from surveil.api.handlers.status.metrics import metric_name_handler
|
||||||
|
@ -16,7 +16,7 @@ import pecan
|
|||||||
from pecan import rest
|
from pecan import rest
|
||||||
import wsmeext.pecan as wsme_pecan
|
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.datamodel.status.metrics import metric as m
|
||||||
from surveil.api.handlers.status.metrics import metric_handler
|
from surveil.api.handlers.status.metrics import metric_handler
|
||||||
from surveil.api.handlers.status.metrics import metric_name_handler
|
from surveil.api.handlers.status.metrics import metric_name_handler
|
||||||
|
@ -16,7 +16,7 @@ import pecan
|
|||||||
from pecan import rest
|
from pecan import rest
|
||||||
import wsmeext.pecan as wsme_pecan
|
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.datamodel.status import live_service
|
||||||
from surveil.api.handlers.status import live_service_handler
|
from surveil.api.handlers.status import live_service_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
52
surveil/api/handlers/config/mongoengine_query.py
Normal file
52
surveil/api/handlers/config/mongoengine_query.py
Normal file
@ -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}
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from surveil.api.handlers.config import mongoengine_query
|
||||||
from surveil.api.handlers import handler
|
from surveil.api.handlers import handler
|
||||||
|
|
||||||
|
|
||||||
@ -60,16 +61,27 @@ class MongoObjectHandler(handler.Handler):
|
|||||||
r = self.resource_storage(**resource.as_dict())
|
r = self.resource_storage(**resource.as_dict())
|
||||||
r.save()
|
r.save()
|
||||||
|
|
||||||
def get_all(self, identifier=None, exclude_templates=False, **kwargs):
|
def get_all(self, lq={}):
|
||||||
"""Return all resources."""
|
"""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))
|
self.resource_datamodel(**self._get_dict(r))
|
||||||
for 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
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# 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.datamodel.status.metrics import metric as m
|
||||||
from surveil.api.handlers import handler
|
from surveil.api.handlers import handler
|
||||||
from surveil.api.handlers.status import influxdb_query
|
from surveil.api.handlers.status import influxdb_query
|
||||||
|
0
surveil/tests/api/config/__init__.py
Normal file
0
surveil/tests/api/config/__init__.py
Normal file
62
surveil/tests/api/config/test_mongolive_query.py
Normal file
62
surveil/tests/api/config/test_mongolive_query.py
Normal file
@ -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)
|
||||||
|
)
|
@ -40,7 +40,8 @@ class TestBusinessImpactModulationController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_modulations(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -40,7 +40,7 @@ class TestCheckModulationsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_checkmodulations(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -34,7 +34,7 @@ class TestCommandController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_commands(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -49,7 +49,7 @@ class TestContactGroupsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_contactgroups(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -47,7 +47,7 @@ class TestContactsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_contacts(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -49,7 +49,7 @@ class TestHostGroupsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_hostgroups(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -88,7 +88,7 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_hosts(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
@ -112,17 +112,28 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
"use": []}
|
"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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
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(
|
self.assertEqual(
|
||||||
len(json.loads(response.body.decode())),
|
len(json.loads(response.body.decode())),
|
||||||
len(self.hosts) + 1
|
1
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(response.status_int, 200)
|
self.assertEqual(response.status_int, 200)
|
||||||
|
@ -46,7 +46,7 @@ class TestMacroModulationController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_macromodulations(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
[
|
[
|
||||||
|
@ -49,7 +49,7 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_notificationways(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -41,7 +41,7 @@ class TestRealmsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_realms(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -50,7 +50,7 @@ class TestServiceGroupsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_servicegroups(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -79,7 +79,7 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_services(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
@ -101,21 +101,36 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": ["surveil-ptl", "surveil-bob"],
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"register": "0",
|
"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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
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(
|
self.assertEqual(
|
||||||
len(json.loads(response.body.decode())),
|
len(json.loads(response.body.decode())),
|
||||||
len(self.services) + 1
|
1
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(response.status_int, 200)
|
self.assertEqual(response.status_int, 200)
|
||||||
|
@ -44,7 +44,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_all_timeperiods(self):
|
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(
|
self.assert_count_equal_backport(
|
||||||
json.loads(response.body.decode()),
|
json.loads(response.body.decode()),
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import json
|
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.api.handlers.status import fields_filter
|
||||||
from surveil.tests import base
|
from surveil.tests import base
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import json
|
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.datamodel.status.metrics import time_interval
|
||||||
from surveil.api.handlers.status import influxdb_query
|
from surveil.api.handlers.status import influxdb_query
|
||||||
from surveil.tests import base
|
from surveil.tests import base
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import json
|
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.datamodel.status import paging
|
||||||
from surveil.api.handlers.status import mongodb_query
|
from surveil.api.handlers.status import mongodb_query
|
||||||
from surveil.tests import base
|
from surveil.tests import base
|
||||||
|
Loading…
Reference in New Issue
Block a user