Introduce MongoEngine

Change-Id: Iaad35fa5e1e4134d07c5fb92c60f874a8b77a7f5
This commit is contained in:
aviau 2015-07-07 18:10:58 -04:00
parent cd907a7622
commit fad7ef331f
54 changed files with 649 additions and 332 deletions

View File

@ -13,3 +13,4 @@ pika
python-surveilclient==0.10.0 python-surveilclient==0.10.0
six six
docker-py docker-py
mongoengine

View File

@ -38,7 +38,9 @@ class BusinessImpactModulationsController(rest.RestController):
def get_one(self, modulation_name): def get_one(self, modulation_name):
"""Returns a specific business impact modulation.""" """Returns a specific business impact modulation."""
handler = bh.BusinessImpactModulationHandler(pecan.request) handler = bh.BusinessImpactModulationHandler(pecan.request)
modulation = handler.get(modulation_name) modulation = handler.get(
{"business_impact_modulation_name": modulation_name}
)
return modulation return modulation
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -58,7 +60,9 @@ class BusinessImpactModulationsController(rest.RestController):
def delete(self, modulation_name): def delete(self, modulation_name):
"""Returns a specific business impact modulation.""" """Returns a specific business impact modulation."""
handler = bh.BusinessImpactModulationHandler(pecan.request) handler = bh.BusinessImpactModulationHandler(pecan.request)
handler.delete(modulation_name) handler.delete(
{"business_impact_modulation_name": modulation_name}
)
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation, @wsme_pecan.wsexpose(mod.BusinessImpactModulation,
@ -68,4 +72,7 @@ class BusinessImpactModulationsController(rest.RestController):
def put(self, modulaion_name, modulation): def put(self, modulaion_name, modulation):
"""Update a specific business impact modulation.""" """Update a specific business impact modulation."""
handler = bh.BusinessImpactModulationHandler(pecan.request) handler = bh.BusinessImpactModulationHandler(pecan.request)
handler.update(modulaion_name, modulation) handler.update(
{"business_impact_modulation_name": modulaion_name},
modulation
)

View File

@ -38,7 +38,9 @@ class CheckModulationsController(rest.RestController):
def get_one(self, checkmodulation_name): def get_one(self, checkmodulation_name):
"""Returns a specific check modulation.""" """Returns a specific check modulation."""
handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
checkmodulation = handler.get(checkmodulation_name) checkmodulation = handler.get(
{"checkmodulation_name": checkmodulation_name}
)
return checkmodulation return checkmodulation
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -57,7 +59,7 @@ class CheckModulationsController(rest.RestController):
def delete(self, checkmodulation_name): def delete(self, checkmodulation_name):
"""Returns a specific check modulation.""" """Returns a specific check modulation."""
handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
handler.delete(checkmodulation_name) handler.delete({"checkmodulation_name": checkmodulation_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(checkmodulation.CheckModulation, @wsme_pecan.wsexpose(checkmodulation.CheckModulation,
@ -67,4 +69,7 @@ class CheckModulationsController(rest.RestController):
def put(self, checkmodulation_name, checkmodulation): def put(self, checkmodulation_name, checkmodulation):
"""Update a specific check modulation.""" """Update a specific check modulation."""
handler = checkmodulation_handler.CheckModulationHandler(pecan.request) handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
handler.update(checkmodulation_name, checkmodulation) handler.update(
{"checkmodulation_name": checkmodulation_name},
checkmodulation
)

View File

@ -32,7 +32,7 @@ class CommandController(rest.RestController):
def get(self): def get(self):
"""Returns a specific command.""" """Returns a specific command."""
handler = command_handler.CommandHandler(pecan.request) handler = command_handler.CommandHandler(pecan.request)
c = handler.get(self._id) c = handler.get({"command_name": self._id})
return c return c
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -43,14 +43,14 @@ class CommandController(rest.RestController):
:param data: a command within the request body. :param data: a command within the request body.
""" """
handler = command_handler.CommandHandler(pecan.request) handler = command_handler.CommandHandler(pecan.request)
handler.update(self._id, data) handler.update({"command_name": self._id}, data)
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(None, status_code=204) @wsme_pecan.wsexpose(None, status_code=204)
def delete(self): def delete(self):
"""Delete this command.""" """Delete this command."""
handler = command_handler.CommandHandler(pecan.request) handler = command_handler.CommandHandler(pecan.request)
handler.delete(self._id) handler.delete({"command_name": self._id})
class CommandsController(rest.RestController): class CommandsController(rest.RestController):

View File

@ -38,7 +38,7 @@ class ContactGroupsController(rest.RestController):
def get_one(self, group_name): def get_one(self, group_name):
"""Returns a contact group.""" """Returns a contact group."""
handler = contactgroup_handler.ContactGroupHandler(pecan.request) handler = contactgroup_handler.ContactGroupHandler(pecan.request)
contactgroup = handler.get(group_name) contactgroup = handler.get({"contactgroup_name": group_name})
return contactgroup return contactgroup
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -57,7 +57,7 @@ class ContactGroupsController(rest.RestController):
def delete(self, group_name): def delete(self, group_name):
"""Delete a specific contact group.""" """Delete a specific contact group."""
handler = contactgroup_handler.ContactGroupHandler(pecan.request) handler = contactgroup_handler.ContactGroupHandler(pecan.request)
handler.delete(group_name) handler.delete({"contactgroup_name": group_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contactgroup.ContactGroup, @wsme_pecan.wsexpose(contactgroup.ContactGroup,
@ -67,4 +67,4 @@ class ContactGroupsController(rest.RestController):
def put(self, group_name, contactgroup): def put(self, group_name, contactgroup):
"""Update a specific contact group.""" """Update a specific contact group."""
handler = contactgroup_handler.ContactGroupHandler(pecan.request) handler = contactgroup_handler.ContactGroupHandler(pecan.request)
handler.update(group_name, contactgroup) handler.update({"contactgroup_name": group_name}, contactgroup)

View File

@ -38,7 +38,7 @@ class ContactsController(rest.RestController):
def get_one(self, contact_name): def get_one(self, contact_name):
"""Returns a specific contact.""" """Returns a specific contact."""
handler = contact_handler.ContactHandler(pecan.request) handler = contact_handler.ContactHandler(pecan.request)
contact = handler.get(contact_name) contact = handler.get({"contact_name": contact_name})
return contact return contact
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -56,7 +56,7 @@ class ContactsController(rest.RestController):
def delete(self, contact_name): def delete(self, contact_name):
"""Returns a specific contact.""" """Returns a specific contact."""
handler = contact_handler.ContactHandler(pecan.request) handler = contact_handler.ContactHandler(pecan.request)
handler.delete(contact_name) handler.delete({"contact_name": contact_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contact.Contact, @wsme_pecan.wsexpose(contact.Contact,
@ -66,4 +66,4 @@ class ContactsController(rest.RestController):
def put(self, contact_name, contact): def put(self, contact_name, contact):
"""Returns a specific contact.""" """Returns a specific contact."""
handler = contact_handler.ContactHandler(pecan.request) handler = contact_handler.ContactHandler(pecan.request)
handler.update(contact_name, contact) handler.update({"contact_name": contact_name}, contact)

View File

@ -38,7 +38,7 @@ class HostGroupsController(rest.RestController):
def get_one(self, group_name): def get_one(self, group_name):
"""Returns a host group.""" """Returns a host group."""
handler = hostgroup_handler.HostGroupHandler(pecan.request) handler = hostgroup_handler.HostGroupHandler(pecan.request)
hostgroup = handler.get(group_name) hostgroup = handler.get({"hostgroup_name": group_name})
return hostgroup return hostgroup
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -56,7 +56,7 @@ class HostGroupsController(rest.RestController):
def delete(self, group_name): def delete(self, group_name):
"""Returns a specific host group.""" """Returns a specific host group."""
handler = hostgroup_handler.HostGroupHandler(pecan.request) handler = hostgroup_handler.HostGroupHandler(pecan.request)
handler.delete(group_name) handler.delete({"hostgroup_name": group_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(hostgroup.HostGroup, @wsme_pecan.wsexpose(hostgroup.HostGroup,
@ -66,4 +66,4 @@ class HostGroupsController(rest.RestController):
def put(self, group_name, hostgroup): def put(self, group_name, hostgroup):
"""Update a specific host group.""" """Update a specific host group."""
handler = hostgroup_handler.HostGroupHandler(pecan.request) handler = hostgroup_handler.HostGroupHandler(pecan.request)
handler.update(group_name, hostgroup) handler.update({"hostgroup_name": group_name}, hostgroup)

View File

@ -35,8 +35,12 @@ class HostServiceSubController(rest.RestController):
"""Returns a specific service.""" """Returns a specific service."""
handler = service_handler.ServiceHandler(pecan.request) handler = service_handler.ServiceHandler(pecan.request)
s = handler.get( s = handler.get(
pecan.request.context['host_name'], {
pecan.request.context['service_description'] "host_name": pecan.request.context['host_name'],
"service_description": pecan.request.context[
'service_description'
]
}
) )
return s return s
@ -46,8 +50,12 @@ class HostServiceSubController(rest.RestController):
"""Delete a specific service.""" """Delete a specific service."""
handler = service_handler.ServiceHandler(pecan.request) handler = service_handler.ServiceHandler(pecan.request)
handler.delete( handler.delete(
pecan.request.context['host_name'], {
pecan.request.context['service_description'] "host_name": pecan.request.context['host_name'],
"service_description": pecan.request.context[
'service_description'
]
}
) )
@ -83,7 +91,7 @@ class HostController(rest.RestController):
def get(self): def get(self):
"""Returns a specific host.""" """Returns a specific host."""
handler = host_handler.HostHandler(pecan.request) handler = host_handler.HostHandler(pecan.request)
h = handler.get(self._id) h = handler.get({"host_name": self._id})
return h return h
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -94,14 +102,14 @@ class HostController(rest.RestController):
:param data: a host within the request body. :param data: a host within the request body.
""" """
handler = host_handler.HostHandler(pecan.request) handler = host_handler.HostHandler(pecan.request)
handler.update(self._id, data) handler.update({"host_name": self._id}, data)
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(None, status_code=204) @wsme_pecan.wsexpose(None, status_code=204)
def delete(self): def delete(self):
"""Delete this host.""" """Delete this host."""
handler = host_handler.HostHandler(pecan.request) handler = host_handler.HostHandler(pecan.request)
handler.delete(self._id) handler.delete({"host_name": self._id})
@pecan.expose() @pecan.expose()
def _lookup(self, *remainder): def _lookup(self, *remainder):
@ -120,7 +128,7 @@ class HostsController(rest.RestController):
"""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(
templates=bool(templates) exclude_templates=(not bool(templates))
) )
return hosts return hosts

View File

@ -35,10 +35,12 @@ class MacroModulationController(rest.RestController):
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation, wtypes.text) @wsme_pecan.wsexpose(macromodulation.MacroModulation, wtypes.text)
def get_one(self, timeperiod_name): def get_one(self, macromodulation_name):
"""Returns a specific macro modulation.""" """Returns a specific macro modulation."""
handler = macromodulation_handler.MacroModulationHandler(pecan.request) handler = macromodulation_handler.MacroModulationHandler(pecan.request)
modulation = handler.get(timeperiod_name) modulation = handler.get(
{"macromodulation_name": macromodulation_name}
)
return modulation return modulation
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -58,7 +60,7 @@ class MacroModulationController(rest.RestController):
def delete(self, modulation_name): def delete(self, modulation_name):
"""Returns a specific macro modulation.""" """Returns a specific macro modulation."""
handler = macromodulation_handler.MacroModulationHandler(pecan.request) handler = macromodulation_handler.MacroModulationHandler(pecan.request)
handler.delete(modulation_name) handler.delete({"macromodulation_name": modulation_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation, @wsme_pecan.wsexpose(macromodulation.MacroModulation,
@ -68,4 +70,4 @@ class MacroModulationController(rest.RestController):
def put(self, modulation_name, modulation): def put(self, modulation_name, modulation):
"""Update a specific macro modulation.""" """Update a specific macro modulation."""
handler = macromodulation_handler.MacroModulationHandler(pecan.request) handler = macromodulation_handler.MacroModulationHandler(pecan.request)
handler.update(modulation_name, modulation) handler.update({"macromodulation_name": modulation_name}, modulation)

View File

@ -38,7 +38,9 @@ class NotificationWaysController(rest.RestController):
def get_one(self, notificationway_name): def get_one(self, notificationway_name):
"""Returns a specific notification way.""" """Returns a specific notification way."""
handler = notificationway_handler.NotificationWayHandler(pecan.request) handler = notificationway_handler.NotificationWayHandler(pecan.request)
notificationway = handler.get(notificationway_name) notificationway = handler.get(
{"notificationway_name": notificationway_name}
)
return notificationway return notificationway
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -60,7 +62,7 @@ class NotificationWaysController(rest.RestController):
def delete(self, notificationway_name): def delete(self, notificationway_name):
"""Returns a specific notification way.""" """Returns a specific notification way."""
handler = notificationway_handler.NotificationWayHandler(pecan.request) handler = notificationway_handler.NotificationWayHandler(pecan.request)
handler.delete(notificationway_name) handler.delete({"notificationway_name": notificationway_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(notificationway.NotificationWay, @wsme_pecan.wsexpose(notificationway.NotificationWay,
@ -70,4 +72,7 @@ class NotificationWaysController(rest.RestController):
def put(self, notificationway_name, notificationway): def put(self, notificationway_name, notificationway):
"""Update a specific notification way.""" """Update a specific notification way."""
handler = notificationway_handler.NotificationWayHandler(pecan.request) handler = notificationway_handler.NotificationWayHandler(pecan.request)
handler.update(notificationway_name, notificationway) handler.update(
{"notificationway_name": notificationway_name},
notificationway
)

View File

@ -38,7 +38,7 @@ class RealmsController(rest.RestController):
def get_one(self, realm_name): def get_one(self, realm_name):
"""Returns a specific realm.""" """Returns a specific realm."""
handler = realm_handler.RealmHandler(pecan.request) handler = realm_handler.RealmHandler(pecan.request)
realm = handler.get(realm_name) realm = handler.get({"realm_name": realm_name})
return realm return realm
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -56,7 +56,7 @@ class RealmsController(rest.RestController):
def delete(self, realm_name): def delete(self, realm_name):
"""Deletes a specific realm.""" """Deletes a specific realm."""
handler = realm_handler.RealmHandler(pecan.request) handler = realm_handler.RealmHandler(pecan.request)
handler.delete(realm_name) handler.delete({"realm_name": realm_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(realm.Realm, @wsme_pecan.wsexpose(realm.Realm,
@ -66,4 +66,7 @@ class RealmsController(rest.RestController):
def put(self, realm_name, realm): def put(self, realm_name, realm):
"""Updates a specific realm.""" """Updates a specific realm."""
handler = realm_handler.RealmHandler(pecan.request) handler = realm_handler.RealmHandler(pecan.request)
handler.update(realm_name, realm) handler.update(
{"realm_name": realm_name},
realm
)

View File

@ -38,7 +38,7 @@ class ServiceGroupsController(rest.RestController):
def get_one(self, group_name): def get_one(self, group_name):
"""Returns a service group.""" """Returns a service group."""
handler = servicegroup_handler.ServiceGroupHandler(pecan.request) handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
servicegroup = handler.get(group_name) servicegroup = handler.get({"servicegroup_name": group_name})
return servicegroup return servicegroup
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -57,7 +57,7 @@ class ServiceGroupsController(rest.RestController):
def delete(self, group_name): def delete(self, group_name):
"""Returns a specific service group.""" """Returns a specific service group."""
handler = servicegroup_handler.ServiceGroupHandler(pecan.request) handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
handler.delete(group_name) handler.delete({"servicegroup_name": group_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, @wsme_pecan.wsexpose(servicegroup.ServiceGroup,
@ -67,4 +67,4 @@ class ServiceGroupsController(rest.RestController):
def put(self, group_name, servicegroup): def put(self, group_name, servicegroup):
"""Update a specific service group.""" """Update a specific service group."""
handler = servicegroup_handler.ServiceGroupHandler(pecan.request) handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
handler.update(group_name, servicegroup) handler.update({"servicegroup_name": group_name}, servicegroup)

View File

@ -29,7 +29,7 @@ class ServicesController(rest.RestController):
"""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(
templates=bool(templates) exclude_templates=(not bool(templates))
) )
return services return services

View File

@ -38,7 +38,7 @@ class TimePeriodsController(rest.RestController):
def get_one(self, timeperiod_name): def get_one(self, timeperiod_name):
"""Returns a specific time period.""" """Returns a specific time period."""
handler = timeperiod_handler.TimePeriodHandler(pecan.request) handler = timeperiod_handler.TimePeriodHandler(pecan.request)
timeperiod = handler.get(timeperiod_name) timeperiod = handler.get({"timeperiod_name": timeperiod_name})
return timeperiod return timeperiod
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@ -56,7 +56,7 @@ class TimePeriodsController(rest.RestController):
def delete(self, timeperiod_name): def delete(self, timeperiod_name):
"""Returns a specific time period.""" """Returns a specific time period."""
handler = timeperiod_handler.TimePeriodHandler(pecan.request) handler = timeperiod_handler.TimePeriodHandler(pecan.request)
handler.delete(timeperiod_name) handler.delete({"timeperiod_name": timeperiod_name})
@util.policy_enforce(['authenticated']) @util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(timeperiod.TimePeriod, @wsme_pecan.wsexpose(timeperiod.TimePeriod,
@ -66,4 +66,4 @@ class TimePeriodsController(rest.RestController):
def put(self, timeperiod_name, timeperiod): def put(self, timeperiod_name, timeperiod):
"""Update a specific time period.""" """Update a specific time period."""
handler = timeperiod_handler.TimePeriodHandler(pecan.request) handler = timeperiod_handler.TimePeriodHandler(pecan.request)
handler.update(timeperiod_name, timeperiod) handler.update({"timeperiod_name": timeperiod_name}, timeperiod)

View File

@ -21,33 +21,12 @@ from surveil.api.datamodel import types
class MacroModulation(types.Base): class MacroModulation(types.Base):
macromodulation_name = wsme.wsattr(wtypes.text, mandatory=True) macromodulation_name = wsme.wsattr(wtypes.text, mandatory=True)
modulation_period = wsme.wsattr(wtypes.text, mandatory=True) modulation_period = wsme.wsattr(wtypes.text, mandatory=True)
# _CRITICAL = wsme.wsattr(int, mandatory=True)
# _WARNING = wsme.wsattr(int, mandatory=True)
macros = wsme.wsattr( macros = wsme.wsattr(
wtypes.DictType(wtypes.text, int), wtypes.DictType(wtypes.text, int),
mandatory=False mandatory=False
) )
def __init__(self, **kwargs):
super(MacroModulation, self).__init__(**kwargs)
# Custom fields start with '_'. Detect them and assign them.
macros = [i for i in kwargs.items()
if isinstance(i[0], str) and i[0].startswith('_')]
if len(macros) > 0:
self.macros = {}
for item in macros:
self.macros[item[0]] = item[1]
def as_dict(self):
mod_dict = super(MacroModulation, self).as_dict()
macros = mod_dict.pop("macros", None)
if macros:
for item in macros.items():
mod_dict[item[0]] = item[1]
return mod_dict
@classmethod @classmethod
def sample(cls): def sample(cls):
return cls( return cls(

View File

@ -27,24 +27,6 @@ class TimePeriod(types.Base):
mandatory=False mandatory=False
) )
def __init__(self, **kwargs):
super(TimePeriod, self).__init__(**kwargs)
periods = [i for i in kwargs.items() if isinstance(i[0], str)
and i[0] not in ['timeperiod_name', 'exclude', 'periods']]
if len(periods) > 0:
self.periods = {}
for item in periods:
self.periods[item[0]] = item[1]
def as_dict(self):
timeperiod_dict = super(TimePeriod, self).as_dict()
periods = timeperiod_dict.pop("periods", None)
if periods:
for item in periods.items():
timeperiod_dict[item[0]] = item[1]
return timeperiod_dict
@classmethod @classmethod
def sample(cls): def sample(cls):
return cls( return cls(

View File

@ -12,18 +12,21 @@
# 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.config import businessimpactmodulation from surveil.api.datamodel.config import businessimpactmodulation as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import (businessimpactmodulation
as storage)
class BusinessImpactModulationHandler(mongo_object_handler.MongoObjectHandler): class BusinessImpactModulationHandler(
mongodb_mongoengine_object_handler.MongoObjectHandler
):
"""Fulfills a request on the Business Impact Modulation resource.""" """Fulfills a request on the Business Impact Modulation resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(BusinessImpactModulationHandler, self).__init__( super(BusinessImpactModulationHandler, self).__init__(
'businessimpactmodulations', datamodel.BusinessImpactModulation,
'business_impact_modulation_name', storage.BusinessImpactModulation,
businessimpactmodulation.BusinessImpactModulation,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,20 @@
# 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.config import checkmodulation from surveil.api.datamodel.config import checkmodulation as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import checkmodulation as storage
class CheckModulationHandler(mongo_object_handler.MongoObjectHandler): class CheckModulationHandler(
mongodb_mongoengine_object_handler.MongoObjectHandler
):
"""Fulfills a request on the Check Modulation resource.""" """Fulfills a request on the Check Modulation resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(CheckModulationHandler, self).__init__( super(CheckModulationHandler, self).__init__(
'checkmodulations', datamodel.CheckModulation,
'checkmodulation_name', storage.CheckModulation,
checkmodulation.CheckModulation,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,18 @@
# 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.config import command from surveil.api.datamodel.config import command as command_datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import command as command_storage
class CommandHandler(mongo_object_handler.MongoObjectHandler): class CommandHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the Command resource.""" """Fulfills a request on the Command resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(CommandHandler, self).__init__( super(CommandHandler, self).__init__(
'commands', command_datamodel.Command,
'command_name', command_storage.Command,
command.Command,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,18 @@
# 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.config import contact from surveil.api.datamodel.config import contact as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import contact as storage
class ContactHandler(mongo_object_handler.MongoObjectHandler): class ContactHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the Contact resource.""" """Fulfills a request on the Contact resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ContactHandler, self).__init__( super(ContactHandler, self).__init__(
'contacts', datamodel.Contact,
'contact_name', storage.Contact,
contact.Contact,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,20 @@
# 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.config import contactgroup from surveil.api.datamodel.config import contactgroup as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import contactgroup as storage
class ContactGroupHandler(mongo_object_handler.MongoObjectHandler): class ContactGroupHandler(
mongodb_mongoengine_object_handler.MongoObjectHandler
):
"""Fulfills a request on the Contact Group resource.""" """Fulfills a request on the Contact Group resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ContactGroupHandler, self).__init__( super(ContactGroupHandler, self).__init__(
'contactgroups', datamodel.ContactGroup,
'contactgroup_name', storage.ContactGroup,
contactgroup.ContactGroup,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,18 @@
# 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.config import host from surveil.api.datamodel.config import host as host_datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import host as host_storage
class HostHandler(mongo_object_handler.MongoObjectHandler): class HostHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the Host resource.""" """Fulfills a request on the Host resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(HostHandler, self).__init__( super(HostHandler, self).__init__(
'hosts', host_datamodel.Host,
'host_name', host_storage.Host,
host.Host,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,18 @@
# 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.config import hostgroup from surveil.api.datamodel.config import hostgroup as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import hostgroup as storage
class HostGroupHandler(mongo_object_handler.MongoObjectHandler): class HostGroupHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the host group resource.""" """Fulfills a request on the host group resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(HostGroupHandler, self).__init__( super(HostGroupHandler, self).__init__(
'hostgroups', datamodel.HostGroup,
'hostgroup_name', storage.HostGroup,
hostgroup.HostGroup,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,20 @@
# 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.config import macromodulation from surveil.api.datamodel.config import macromodulation as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import macromodulation as storage
class MacroModulationHandler(mongo_object_handler.MongoObjectHandler): class MacroModulationHandler(
mongodb_mongoengine_object_handler.MongoObjectHandler
):
"""Fulfills a request on the Macro Modulation resource.""" """Fulfills a request on the Macro Modulation resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(MacroModulationHandler, self).__init__( super(MacroModulationHandler, self).__init__(
'macromodulations', datamodel.MacroModulation,
'macromodulation_name', storage.MacroModulation,
macromodulation.MacroModulation,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,20 @@
# 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.config import notificationway from surveil.api.datamodel.config import notificationway as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import notificationway as storage
class NotificationWayHandler(mongo_object_handler.MongoObjectHandler): class NotificationWayHandler(
mongodb_mongoengine_object_handler.MongoObjectHandler
):
"""Fulfills a request on the Notification Way resource.""" """Fulfills a request on the Notification Way resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(NotificationWayHandler, self).__init__( super(NotificationWayHandler, self).__init__(
'notificationways', datamodel.NotificationWay,
'notificationway_name', storage.NotificationWays,
notificationway.NotificationWay,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,18 @@
# 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.config import realm from surveil.api.datamodel.config import realm as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import realm as storage
class RealmHandler(mongo_object_handler.MongoObjectHandler): class RealmHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the Realm resource.""" """Fulfills a request on the Realm resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(RealmHandler, self).__init__( super(RealmHandler, self).__init__(
'realms', datamodel.Realm,
'realm_name', storage.Realm,
realm.Realm,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,60 +12,18 @@
# 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.config import service from surveil.api.datamodel.config import service as service_datamodel
from surveil.api.handlers import handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import service as service_storage
class ServiceHandler(handler.Handler): class ServiceHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the service resource.""" """Fulfills a request on the service resource."""
def get(self, host_name, service_description): def __init__(self, *args, **kwargs):
"""Return a service.""" super(ServiceHandler, self).__init__(
mongo_s = self.request.mongo_connection.shinken.services.find_one( service_datamodel.Service,
{"host_name": host_name, service_storage.Service,
"service_description": service_description} *args,
**kwargs
) )
return service.Service(**mongo_s)
def update(self, id, data):
"""Modify existing host."""
host_dict = data.as_dict()
if "host_name" not in host_dict.keys():
host_dict['host_name'] = id
self.request.mongo_connection.shinken.hosts.update(
{"host_name": id},
{"$set": host_dict},
upsert=True
)
def delete(self, host_name, service_description):
"""Delete existing service."""
self.request.mongo_connection.shinken.services.remove(
{"host_name": host_name,
"service_description": service_description}
)
def create(self, data):
"""Create a new service."""
self.request.mongo_connection.shinken.services.insert(
data.as_dict()
)
def get_all(self, host_name=None, templates=False):
"""Return all services."""
if templates is True:
filters = {}
else:
filters = {"register": {"$ne": "0"}}
if host_name is not None:
filters['host_name'] = host_name
services = [
s for s
in self.request.mongo_connection.
# Don't return templates
shinken.services.find(filters)
]
return [service.Service(**s) for s in services]

View File

@ -12,18 +12,20 @@
# 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.config import servicegroup from surveil.api.datamodel.config import servicegroup as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import servicegroup as storage
class ServiceGroupHandler(mongo_object_handler.MongoObjectHandler): class ServiceGroupHandler(
mongodb_mongoengine_object_handler.MongoObjectHandler
):
"""Fulfills a request on the Service Group resource.""" """Fulfills a request on the Service Group resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ServiceGroupHandler, self).__init__( super(ServiceGroupHandler, self).__init__(
'servicegroups', datamodel.ServiceGroup,
'servicegroup_name', storage.ServiceGroup,
servicegroup.ServiceGroup,
*args, *args,
**kwargs **kwargs
) )

View File

@ -12,18 +12,18 @@
# 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.config import timeperiod from surveil.api.datamodel.config import timeperiod as datamodel
from surveil.api.handlers import mongo_object_handler from surveil.api.handlers import mongodb_mongoengine_object_handler
from surveil.api.storage.mongodb.config import timeperiod as storage
class TimePeriodHandler(mongo_object_handler.MongoObjectHandler): class TimePeriodHandler(mongodb_mongoengine_object_handler.MongoObjectHandler):
"""Fulfills a request on the Time Period resource.""" """Fulfills a request on the Time Period resource."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TimePeriodHandler, self).__init__( super(TimePeriodHandler, self).__init__(
'timeperiods', datamodel.TimePeriod,
'timeperiod_name', storage.TimePeriod,
timeperiod.TimePeriod,
*args, *args,
**kwargs **kwargs
) )

View File

@ -1,80 +0,0 @@
# Copyright 2014 - 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.
from surveil.api.handlers import handler
class MongoObjectHandler(handler.Handler):
"""Fulfills a request on a MongoDB resource."""
def __init__(self,
resource_colleciton,
resource_key,
resource_datamodel,
*args,
**kwargs):
super(MongoObjectHandler, self).__init__(*args, **kwargs)
self.resource_collection = resource_colleciton
self.resource_key = resource_key
self.resource_datamodel = resource_datamodel
def _get_resource_collection(self):
shinken_db = self.request.mongo_connection.shinken
resource_colleciton = getattr(shinken_db, self.resource_collection)
return resource_colleciton
def get(self, resource_key_value):
"""Return the resource."""
r = self._get_resource_collection().find_one(
{self.resource_key: resource_key_value},
{'_id': 0}
)
return self.resource_datamodel(**r)
def update(self, resource_key_value, resource):
"""Modify an existing resource."""
resource_dict = resource.as_dict()
if self.resource_key not in resource_dict.keys():
resource_dict[self.resource_key] = resource_key_value
self._get_resource_collection().update(
{self.resource_key: resource_key_value},
{"$set": resource_dict},
upsert=True
)
def delete(self, resource_key_value):
"""Delete existing resource."""
self._get_resource_collection().remove(
{self.resource_key: resource_key_value}
)
def create(self, resource):
"""Create a new resource."""
self._get_resource_collection().insert(
resource.as_dict()
)
def get_all(self, templates=False):
"""Return all resources."""
if templates is True:
filters = {}
else:
filters = {"register": {"$ne": "0"}}
resources = [r for r
in self._get_resource_collection()
.find(filters, {'_id': 0})]
resources = [self.resource_datamodel(**r) for r in resources]
return resources

View File

@ -0,0 +1,75 @@
# Copyright 2014 - 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.
from surveil.api.handlers import handler
class MongoObjectHandler(handler.Handler):
"""Fulfills a request on a MongoDB resource."""
def __init__(self,
resource_datamodel,
resource_storage,
*args,
**kwargs):
super(MongoObjectHandler, self).__init__(*args, **kwargs)
self.resource_datamodel = resource_datamodel
self.resource_storage = resource_storage
def _get_mongoengine_object(self, identifier):
return self.resource_storage.objects.get(**identifier)
def _get_dict(self, mongoengine_object):
json_object = mongoengine_object.to_mongo().to_dict()
json_object.pop('_id', None)
return json_object
def get(self, identifier):
"""Return the resource."""
mongoengine_object = self._get_mongoengine_object(identifier)
resource_dict = self._get_dict(mongoengine_object)
return self.resource_datamodel(**resource_dict)
def update(self, identifier, resource):
"""Modify an existing resource."""
r = self._get_mongoengine_object(identifier)
resource_dict = resource.as_dict()
for key, value in resource_dict.items():
setattr(r, key, value)
r.save()
def delete(self, identifier):
"""Delete existing resource."""
r = self._get_mongoengine_object(identifier)
r.delete()
r.save()
def create(self, resource):
"""Create a new resource."""
r = self.resource_storage(**resource.as_dict())
r.save()
def get_all(self, identifier=None, exclude_templates=False, **kwargs):
"""Return all resources."""
identifier = identifier or {}
if exclude_templates is True:
identifier.update(
{"register__ne": "0"}
)
return [
self.resource_datamodel(**self._get_dict(r))
for r
in self.resource_storage.objects(**identifier)
]

View File

View File

View File

@ -0,0 +1,22 @@
# Copyright 2014 - 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 mongoengine
class BusinessImpactModulation(mongoengine.Document):
meta = {'collection': 'businessimpactmodulations'}
business_impact_modulation_name = mongoengine.StringField(unique=True)
business_impact = mongoengine.IntField()
modulation_period = mongoengine.StringField()

View File

@ -0,0 +1,22 @@
# Copyright 2014 - 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 mongoengine
class CheckModulation(mongoengine.Document):
meta = {'collection': 'checkmodulations'}
checkmodulation_name = mongoengine.StringField(unique=True)
check_command = mongoengine.StringField()
check_period = mongoengine.StringField()

View File

@ -0,0 +1,22 @@
# Copyright 2014 - 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 mongoengine
class Command(mongoengine.Document):
meta = {'collection': 'commands'}
command_name = mongoengine.StringField(unique=True)
command_line = mongoengine.StringField()
module_type = mongoengine.StringField()

View File

@ -0,0 +1,35 @@
# Copyright 2014 - 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 mongoengine
class Contact(mongoengine.Document):
meta = {'collection': 'contacts'}
contact_name = mongoengine.StringField(unique=True)
host_notifications_enabled = mongoengine.StringField()
service_notifications_enabled = mongoengine.StringField()
host_notification_period = mongoengine.StringField()
service_notification_period = mongoengine.StringField()
host_notification_options = mongoengine.StringField()
service_notification_options = mongoengine.StringField()
host_notification_commands = mongoengine.StringField()
service_notification_commands = mongoengine.StringField()
email = mongoengine.StringField()
pager = mongoengine.StringField()
can_submit_commands = mongoengine.StringField()
is_admin = mongoengine.StringField()
retain_status_information = mongoengine.StringField()
retain_nonstatus_information = mongoengine.StringField()
min_business_impact = mongoengine.StringField()

View File

@ -0,0 +1,23 @@
# Copyright 2014 - 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 mongoengine
class ContactGroup(mongoengine.Document):
meta = {'collection': 'contactgroups'}
contactgroup_name = mongoengine.StringField(unique=True)
members = mongoengine.StringField()
alias = mongoengine.StringField()
contactgroup_members = mongoengine.StringField()

View File

@ -0,0 +1,33 @@
# Copyright 2014 - 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 mongoengine
class Host(mongoengine.Document):
meta = {'collection': 'hosts'}
host_name = mongoengine.StringField(unique=True)
address = mongoengine.StringField()
max_check_attempts = mongoengine.IntField()
check_period = mongoengine.StringField()
contacts = mongoengine.StringField()
contact_groups = mongoengine.StringField()
notification_interval = mongoengine.IntField()
notification_period = mongoengine.StringField()
use = mongoengine.StringField()
name = mongoengine.StringField()
register = mongoengine.StringField()
check_interval = mongoengine.IntField()
retry_interval = mongoengine.IntField()
custom_fields = mongoengine.DictField()

View File

@ -0,0 +1,26 @@
# Copyright 2014 - 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 mongoengine
class HostGroup(mongoengine.Document):
meta = {'collection': 'hostgroups'}
hostgroup_name = mongoengine.StringField(unique=True)
members = mongoengine.StringField()
alias = mongoengine.StringField()
hostgroup_members = mongoengine.StringField()
notes = mongoengine.StringField()
notes_url = mongoengine.StringField()
action_url = mongoengine.StringField()

View File

@ -0,0 +1,22 @@
# Copyright 2014 - 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 mongoengine
class MacroModulation(mongoengine.Document):
meta = {'collection': 'macromodulations'}
macromodulation_name = mongoengine.StringField(unique=True)
modulation_period = mongoengine.StringField()
macros = mongoengine.DictField()

View File

@ -0,0 +1,27 @@
# Copyright 2014 - 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 mongoengine
class NotificationWays(mongoengine.Document):
meta = {'collection': 'notificationways'}
notificationway_name = mongoengine.StringField(unique=True)
host_notification_period = mongoengine.StringField()
service_notification_period = mongoengine.StringField()
host_notification_options = mongoengine.StringField()
service_notification_options = mongoengine.StringField()
host_notification_commands = mongoengine.StringField()
service_notification_commands = mongoengine.StringField()
min_business_impact = mongoengine.IntField()

View File

@ -0,0 +1,22 @@
# Copyright 2014 - 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 mongoengine
class Realm(mongoengine.Document):
meta = {'collection': 'realms'}
realm_name = mongoengine.StringField(unique=True)
realm_members = mongoengine.StringField()
default = mongoengine.IntField()

View File

@ -0,0 +1,34 @@
# Copyright 2014 - 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 mongoengine
class Service(mongoengine.Document):
meta = {'collection': 'services'}
host_name = mongoengine.StringField(unique=True)
service_description = mongoengine.StringField()
contacts = mongoengine.StringField()
check_command = mongoengine.StringField()
max_check_attempts = mongoengine.IntField()
check_interval = mongoengine.IntField()
retry_interval = mongoengine.IntField()
check_period = mongoengine.StringField()
notification_interval = mongoengine.IntField()
notification_period = mongoengine.StringField()
contact_groups = mongoengine.StringField()
passive_checks_enabled = mongoengine.StringField()
use = mongoengine.StringField()
name = mongoengine.StringField()
register = mongoengine.StringField()

View File

@ -0,0 +1,26 @@
# Copyright 2014 - 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 mongoengine
class ServiceGroup(mongoengine.Document):
meta = {'collection': 'servicegroups'}
servicegroup_name = mongoengine.StringField(unique=True)
members = mongoengine.StringField()
alias = mongoengine.StringField()
servicegroup_members = mongoengine.StringField()
notes = mongoengine.StringField()
notes_url = mongoengine.StringField()
action_url = mongoengine.StringField()

View File

@ -0,0 +1,22 @@
# Copyright 2014 - 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 mongoengine
class TimePeriod(mongoengine.Document):
meta = {'collection': 'timeperiods'}
timeperiod_name = mongoengine.StringField(unique=True)
exclude = mongoengine.StringField()
periods = mongoengine.DictField()

View File

@ -30,19 +30,21 @@ class TestHostController(functionalTest.FunctionalTest):
"max_check_attempts": 5, "check_period": "24x7", "max_check_attempts": 5, "check_period": "24x7",
"contacts": "admin,carl", "contact_groups": "router-admins", "contacts": "admin,carl", "contact_groups": "router-admins",
"notification_interval": 30, "notification_period": "24x7", "notification_interval": 30, "notification_period": "24x7",
"custom_fields": {}
}, },
{ {
"host_name": "bogus-router2", "address": "192.168.1.254", "host_name": "bogus-router2", "address": "192.168.1.254",
"max_check_attempts": 5, "check_period": "24x7", "max_check_attempts": 5, "check_period": "24x7",
"contacts": "admin,carl", "contact_groups": "router-admins", "contacts": "admin,carl", "contact_groups": "router-admins",
"notification_interval": 30, "notification_period": "24x7" "notification_interval": 30, "notification_period": "24x7",
"custom_fields": {}
}, },
{ {
"host_name": "bogus-router333", "address": "192.168.1.254", "host_name": "bogus-router333", "address": "192.168.1.254",
"max_check_attempts": 5, "check_period": "24x7", "max_check_attempts": 5, "check_period": "24x7",
"contacts": "admin,carl", "contact_groups": "router-admins", "contacts": "admin,carl", "contact_groups": "router-admins",
"notification_interval": 30, "notification_period": "24x7", "notification_interval": 30, "notification_period": "24x7",
'use': 'test' 'use': 'test', "custom_fields": {}
}, },
] ]
self.mongoconnection.shinken.hosts.insert( self.mongoconnection.shinken.hosts.insert(
@ -80,23 +82,15 @@ class TestHostController(functionalTest.FunctionalTest):
def test_get_all_hosts_templates(self): def test_get_all_hosts_templates(self):
self.mongoconnection.shinken.hosts.insert( self.mongoconnection.shinken.hosts.insert(
copy.deepcopy( copy.deepcopy(
{"host_name": "bogus-router", "address": "192.168.1.254", {"host_name": "bogus-router345345", "address": "192.168.1.254",
"max_check_attempts": 5, "check_period": "24x7", "max_check_attempts": 5, "check_period": "24x7",
"contacts": "admin,carl", "contact_groups": "router-admins", "contacts": "admin,carl", "contact_groups": "router-admins",
"notification_interval": 30, "notification_period": "24x7", "notification_interval": 30, "notification_period": "24x7",
"register": "0"} "register": "0", "custom_fields": {}}
) )
) )
response = self.get('/v2/config/hosts') response = self.get('/v2/config/hosts')
# Adjust self.host content to reflect custom_fields sub-dict
c_fields = {}
for h in self.hosts:
if '_CRITICAL' in h.keys():
c_fields['_CRITICAL'] = h['_CRITICAL']
h.pop('_CRITICAL')
h['custom_fields'] = c_fields
self.assert_count_equal_backport( self.assert_count_equal_backport(
json.loads(response.body.decode()), json.loads(response.body.decode()),
self.hosts self.hosts
@ -143,7 +137,8 @@ class TestHostController(functionalTest.FunctionalTest):
'contact_groups': u'router-admins', 'contact_groups': u'router-admins',
'host_name': u'bogus-router333', 'host_name': u'bogus-router333',
'max_check_attempts': 5, 'max_check_attempts': 5,
'use': u'test' 'use': u'test',
'custom_fields': {},
} }
self.assertEqual(expected, mongo_host.as_dict()) self.assertEqual(expected, mongo_host.as_dict())
@ -167,7 +162,8 @@ class TestHostController(functionalTest.FunctionalTest):
"contacts": "admin,carl", "contacts": "admin,carl",
"contact_groups": "router-admins", "contact_groups": "router-admins",
"notification_interval": 3, "notification_interval": 3,
"notification_period": "24x7" "notification_period": "24x7",
"custom_fields": {}
} }
response = self.post_json("/v2/config/hosts", params=new_host) response = self.post_json("/v2/config/hosts", params=new_host)

View File

@ -27,14 +27,18 @@ class TestMacroModulationController(functionalTest.FunctionalTest):
{ {
'macromodulation_name': 'HighDuringNight', 'macromodulation_name': 'HighDuringNight',
'modulation_period': 'night', 'modulation_period': 'night',
'_CRITICAL': 20, 'macros': {
'_WARNING': 10, '_CRITICAL': 10,
'_WARNING': 20
}
}, },
{ {
'macromodulation_name': 'LowDuringNight', 'macromodulation_name': 'LowDuringNight',
'modulation_period': 'night', 'modulation_period': 'night',
'_CRITICAL': 10, 'macros': {
'_WARNING': 20, '_CRITICAL': 20,
'_WARNING': 10
}
} }
] ]
self.mongoconnection.shinken.macromodulations.insert( self.mongoconnection.shinken.macromodulations.insert(
@ -50,14 +54,18 @@ class TestMacroModulationController(functionalTest.FunctionalTest):
'macromodulation_name': 'HighDuringNight', 'macromodulation_name': 'HighDuringNight',
'modulation_period': 'night', 'modulation_period': 'night',
'macros': { 'macros': {
'_CRITICAL': 20, '_CRITICAL': 10,
'_WARNING': 10}}, '_WARNING': 20
}
},
{ {
'macromodulation_name': 'LowDuringNight', 'macromodulation_name': 'LowDuringNight',
'modulation_period': 'night', 'modulation_period': 'night',
'macros': { 'macros': {
'_CRITICAL': 10, '_CRITICAL': 20,
'_WARNING': 20}} '_WARNING': 10
}
}
], ],
json.loads(response.body.decode()) json.loads(response.body.decode())
@ -69,11 +77,14 @@ class TestMacroModulationController(functionalTest.FunctionalTest):
self.assertEqual( self.assertEqual(
json.loads(response.body.decode()), json.loads(response.body.decode()),
{'macromodulation_name': 'HighDuringNight', {
'modulation_period': 'night', 'macromodulation_name': 'HighDuringNight',
'macros': { 'modulation_period': 'night',
'_CRITICAL': 20, 'macros': {
'_WARNING': 10}} '_CRITICAL': 10,
'_WARNING': 20
}
}
) )
def test_create_macromodulation(self): def test_create_macromodulation(self):
@ -90,11 +101,7 @@ class TestMacroModulationController(functionalTest.FunctionalTest):
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.macromodulations.find_one( self.mongoconnection.shinken.macromodulations.find_one(
{ m
'macromodulation_name': 'TEST_CREATE_MODULATION',
'_CRITICAL': 10,
'_WARNING': 20
}
) )
) )

View File

@ -80,7 +80,7 @@ class TestServiceController(functionalTest.FunctionalTest):
def test_get_all_services_templates(self): def test_get_all_services_templates(self):
self.mongoconnection.shinken.services.insert( self.mongoconnection.shinken.services.insert(
copy.deepcopy( copy.deepcopy(
{"host_name": "sample-server3", {"host_name": "sample-server444",
"service_description": "check-disk-sdb", "service_description": "check-disk-sdb",
"check_command": "check-disk!/dev/sdb1", "check_command": "check-disk!/dev/sdb1",
"max_check_attempts": 5, "max_check_attempts": 5,

View File

@ -26,13 +26,17 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
self.timeperiods = [ self.timeperiods = [
{ {
'timeperiod_name': 'nonworkhours', 'timeperiod_name': 'nonworkhours',
'sunday': '00:00-24:00', "periods": {
'monday': '00:00-09:00,17:00-24:00' 'sunday': '00:00-24:00',
'monday': '00:00-09:00,17:00-24:00'
}
}, },
{ {
'timeperiod_name': 'misc-single-days', 'timeperiod_name': 'misc-single-days',
'1999-01-28': '00:00-24:00', "periods": {
'day 2': '00:00-24:00', '1999-01-28': '00:00-24:00',
'day 2': '00:00-24:00',
}
}, },
] ]
self.mongoconnection.shinken.timeperiods.insert( self.mongoconnection.shinken.timeperiods.insert(
@ -75,10 +79,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
self.post_json('/v2/config/timeperiods', t) self.post_json('/v2/config/timeperiods', t)
self.assertIsNotNone( self.assertIsNotNone(
self.mongoconnection.shinken.timeperiods.find_one( self.mongoconnection.shinken.timeperiods.find_one(t)
{"timeperiod_name": 'someperiod',
"monday": "fun day",
"tuesday": "pizza day"})
) )
def test_delete_timeperiod(self): def test_delete_timeperiod(self):
@ -100,7 +101,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
self.assertEqual( self.assertEqual(
self.mongoconnection.shinken.timeperiods.find_one( self.mongoconnection.shinken.timeperiods.find_one(
{'timeperiod_name': 'nonworkhours'} {'timeperiod_name': 'nonworkhours'}
)['sunday'], )['periods']['sunday'],
'00:00-24:00' '00:00-24:00'
) )
@ -113,6 +114,6 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
self.assertEqual( self.assertEqual(
self.mongoconnection.shinken.timeperiods.find_one( self.mongoconnection.shinken.timeperiods.find_one(
{'timeperiod_name': 'nonworkhours'} {'timeperiod_name': 'nonworkhours'}
)['sunday'], )['periods']['sunday'],
'updated' 'updated'
) )

View File

@ -15,11 +15,13 @@
import os import os
import influxdb import influxdb
import mongoengine
import mongomock import mongomock
from oslo_config import cfg from oslo_config import cfg
import pecan import pecan
from pecan import hooks from pecan import hooks
import pecan.testing import pecan.testing
import pymongo
from surveil.tests import base from surveil.tests import base
@ -36,7 +38,14 @@ class FunctionalTest(base.BaseTestCase):
def setUp(self): def setUp(self):
self.mongoconnection = mongomock.Connection() if os.environ.get('SURVEIL_FUNCTIONAL_MONGOMOCK', None) == 'True':
self.mongoconnection = mongomock.Connection()
else:
self.mongoconnection = pymongo.MongoClient()
self.mongoconnection.drop_database('shinken')
self.mongoconnection.drop_database('alignak_live')
self.mongoconnection.drop_database('surveil')
self.ws_arbiter_url = "http://localhost:7760" self.ws_arbiter_url = "http://localhost:7760"
self.influxdb_client = influxdb.InfluxDBClient.from_DSN( self.influxdb_client = influxdb.InfluxDBClient.from_DSN(
'influxdb://root:root@influxdb:8086/db' 'influxdb://root:root@influxdb:8086/db'
@ -53,6 +62,12 @@ class FunctionalTest(base.BaseTestCase):
state.request.ws_arbiter_url = self.ws_arbiter_url state.request.ws_arbiter_url = self.ws_arbiter_url
state.request.influxdb_client = self.influxdb_client state.request.influxdb_client = self.influxdb_client
def get_connection(alias):
return self.mongoclient
mongoengine.connection.get_connection = get_connection
mongoengine.connect('shinken')
app_hooks = [ app_hooks = [
TestHook( TestHook(
self.mongoconnection, self.mongoconnection,
@ -103,4 +118,6 @@ class FunctionalTest(base.BaseTestCase):
setattr(self, action, make_action(action)) setattr(self, action, make_action(action))
def tearDown(self): def tearDown(self):
if os.environ.get('SURVEIL_FUNCTIONAL_MONGOMOCK', None) != 'True':
self.mongoconnection.close()
pecan.set_config({}, overwrite=True) pecan.set_config({}, overwrite=True)

View File

@ -5,7 +5,8 @@ sphinxcontrib-pecanwsme>=0.8
sphinxcontrib-httpdomain>=1.3.0 sphinxcontrib-httpdomain>=1.3.0
oslosphinx>=2.5.0 oslosphinx>=2.5.0
testrepository>=0.0.18 testrepository>=0.0.18
mongomock #mongomock
https://github.com/aviau/mongomock/archive/create_index.zip#egg=mongomock
requests_mock requests_mock
sphinx_rtd_theme sphinx_rtd_theme
docker-compose docker-compose

View File

@ -7,12 +7,13 @@ skipsdist = True
setenv = LANGUAGE=en_US setenv = LANGUAGE=en_US
LC_ALL=en_US.utf-8 LC_ALL=en_US.utf-8
SURVEIL_INTEGRATION_TESTS=False SURVEIL_INTEGRATION_TESTS=False
SURVEIL_FUNCTIONAL_MONGOMOCK=False
usedevelop = True usedevelop = True
install_command = pip install -U --force-reinstall {opts} {packages} install_command = pip install -U --force-reinstall {opts} {packages}
deps = -r{toxinidir}/requirements.txt deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}' commands = python setup.py testr --slowest --testr-args='--parallel --concurrency=1'
[testenv:integration] [testenv:integration]
setenv = SURVEIL_INTEGRATION_TESTS=True setenv = SURVEIL_INTEGRATION_TESTS=True