def _conf(self, *args, **kwargs): result = super(Organisation, self)._conf(*args, **kwargs) result.add_unified_category( name=Organisation.CATEGORY, new_content=(Parameter(Organisation.USER_STORAGE), Parameter(Organisation.RIGHT_STORAGE), Parameter(Organisation.PROFILE_STORAGE))) return result
from signal import SIGTERM, SIGINT import importlib import sys import os config = { 'server': ( Parameter('debug', parser=Parameter.bool), Parameter('enable_crossdomain_send_events', parser=Parameter.bool), Parameter('root_directory', parser=Parameter.path) ), 'auth': ( Parameter('providers', parser=Parameter.array(), critical=True) ), 'session': ( Parameter('cookie_expires', parser=int), Parameter('secret'), Parameter('data_dir', parser=Parameter.path) ), 'webservices': ParamList(parser=Parameter.bool) } class EnsureAuthenticated(object): name = 'EnsureAuthenticated' handle_logout = False def __init__(self, ws, *args, **kwargs):
# along with Canopsis. If not, see <http://www.gnu.org/licenses/>. # --------------------------------- from canopsis.migration.manager import MigrationModule from canopsis.configuration.configurable.decorator import conf_paths from canopsis.configuration.configurable.decorator import add_category from canopsis.configuration.model import Parameter from canopsis.old.account import Account from canopsis.old.storage import Storage CONF_PATH = 'migration/purge.conf' CATEGORY = 'PURGE' CONTENT = [ Parameter('collections', parser=Parameter.array()) ] @conf_paths(CONF_PATH) @add_category(CATEGORY, content=CONTENT) class PurgeModule(MigrationModule): @property def collections(self): if not hasattr(self, '_collections'): self.collections = None return self._collections @collections.setter
from canopsis.timeserie.timewindow import get_offset_timewindow from canopsis.common.utils import ensure_iterable from canopsis.task.core import get_task from canopsis.event.manager import Event from canopsis.check import Check from canopsis.alerts.status import get_last_state, get_last_status, OFF from time import time CONF_PATH = 'alerts/manager.conf' CATEGORY = 'ALERTS' CONTENT = [ Parameter('extra_fields', Parameter.array()) ] @conf_paths(CONF_PATH) @add_category(CATEGORY, content=CONTENT) class Alerts(MiddlewareRegistry): """ Alarm cycle managment. Used to archive events related to alarms in a TimedStorage. """ CONFIG_STORAGE = 'config_storage' ALARM_STORAGE = 'alarm_storage' CONTEXT_MANAGER = 'context'
class InvalidState(Exception): """Handle CheckManager errors.""" def __init__(self, state, states): self.state = state self.states = states def __str__(self): return 'Invalid state: got value {}, expected one of {}'.format( self.state, self.states ) @add_category(CATEGORY, content=Parameter('types', parser=Parameter.array())) @conf_paths(CONF_PATH) class CheckManager(MiddlewareRegistry): """Manage entity checking state. A state is bound to an entity. Therefore, an entity id is a document state id. """ CHECK_STORAGE = 'check_storage' #: storage name. ID = '_id' #: state id field name. STATE = Check.STATE #: state field name. LAST_STATE = 'last' #: last state field name if criticity != HARD. COUNT = 'count' #: last state count if criticity != 0.
from canopsis.configuration.configurable.decorator import conf_paths from canopsis.configuration.configurable.decorator import add_category from canopsis.configuration.model import Parameter from canopsis.common.utils import lookup from logging import StreamHandler import signal import json import os CONF_PATH = 'migration/manager.conf' CATEGORY = 'MIGRATION' CONTENT = [ Parameter('modules', parser=Parameter.array()) ] @conf_paths(CONF_PATH) @add_category(CATEGORY, content=CONTENT) class MigrationTool(Configurable): @property def modules(self): if not hasattr(self, '_modules'): self.modules = None return self._modules @modules.setter
from canopsis.configuration.configurable.decorator import ( conf_paths, add_category ) from canopsis.configuration.model import Parameter from canopsis.middleware.registry import MiddlewareRegistry from canopsis.event import Event, forger from canopsis.storage.composite import CompositeStorage from urllib import unquote_plus CONF_RESOURCE = 'context/context.conf' #: last context conf resource CATEGORY = 'CONTEXT' #: context category CONTENT = [Parameter('accept_event_types', Parameter.array())] @add_category(CATEGORY, content=CONTENT) @conf_paths(CONF_RESOURCE) class Context(MiddlewareRegistry): """ Manage access to a context (connector, component, resource) elements and context data (metric, downtime, etc.) It uses a composite storage in order to modelise composite data. For example, let a resource ``R`` in the component ``C`` and connector ``K``. ``R`` is identified through the context [``K``, ``C``], the name ``R`` and the type ``resource``.
def get_configuration( self, conf_path, logger, conf=None, override=True ): """ Parse a configuration_files with input conf and returns parameters and errors by param name. :param str conf_path: conf file to parse and from get parameters :param Configuration conf: conf to fill with conf_path values and conf param names. :param Logger logger: logger to use in order to trace information/error :param bool override: if True (by default), override self configuration """ conf_resource = None result = None # ensure conf_path exists and is not empty. if self.exists(conf_path): try: # first, read conf file conf_resource = self._get_conf_resource( conf_path=conf_path, logger=logger ) except Exception as e: # if an error occured, log it logger.error( 'Impossible to parse conf_path {0} with {1}: {2}'.format( conf_path, type(self), e ) ) else: # else process conf file if conf_resource is None: return result result = Configuration() if conf is None else conf categories = self._get_categories( conf_resource=conf_resource, logger=logger ) for category_name in categories: # do something only for referenced categories if category_name in result: category = result.setdefault( category_name, Category(category_name) ) if isinstance(category, Category): parameters = self._get_parameters( conf_resource=conf_resource, category=category, logger=logger ) for name in parameters: # if param name exists in conf if name in category: # copy parameter param = category[name].copy() # else create not local parameter else: param = Parameter(name, local=False) param = category.setdefault(name, param) value = self._get_value( conf_resource=conf_resource, category=category, param=param, logger=logger ) if value not in (None, ''): if override or param.value in (None, ''): param.value = value elif isinstance(category, ParamList): paramlist = category category = Category(category_name) result.categories[category_name] = category parameters = self._get_parameters( conf_resource=conf_resource, category=category, logger=logger ) for name in parameters: param = Parameter( name, local=False, parser=paramlist.parser, asitem=category ) param = category.setdefault(name, param) value = self._get_value( conf_resource=conf_resource, category=category, param=param, logger=logger ) if value not in (None, ''): if override or param.value in (None, ''): param.value = value return result