Exemple #1
0
    def setUp(self):
        pbehavior_storage = Middleware.get_middleware_by_uri(
            'storage-default-testpbehavior://')
        entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://')

        logger = Logger.get('test_pb', None, output_cls=OutputNull)

        self.pbm = PBehaviorManager(logger=logger,
                                    pb_storage=pbehavior_storage)
        self.context = ContextGraph(logger)
        self.context.ent_storage = entities_storage
        self.pbm.context = self.context
Exemple #2
0
    def setUp(self):
        logger = Logger.get('', None, output_cls=OutputNull)
        self.manager = Watcher()
        self.context_graph_manager = ContextGraph(logger)
        self.alerts_storage = Middleware.get_middleware_by_uri(
            'mongodb-periodical-testalarm://')
        self.watcher_storage = Middleware.get_middleware_by_uri(
            'storage-default-testwatcher://')
        self.entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://')

        self.context_graph_manager.ent_storage = self.entities_storage
        self.manager.alert_storage = self.alerts_storage
        self.manager.context_graph = self.context_graph_manager
        self.manager.watcher_storage = self.watcher_storage
Exemple #3
0
    def __init__(self, config=None, logger=None):

        if logger is None:
            self.logger = Logger.get(self.LOG_NAME,
                                     self.LOG_PATH,
                                     output_cls=OutputFile)
        else:
            self.logger = logger

        if config is None:
            self.config = Configuration.load(CONF_PATH, Ini)
        else:
            self.config = config

        self.obj_storage = Middleware.get_middleware_by_uri(
            'storage-default://', table='schemas')

        section = self.config.get(ConfName.SECT_GCTX)
        self._event_types = section[ConfName.EVENT_TYPES]
        self._extra_fields = section[ConfName.EXTRA_FIELDS]

        section = self.config.get(ConfName.SECT_FILTER)
        self._schema_id = section[ConfName.SCHEMA_ID]

        self.reload_schema()
Exemple #4
0
    def __init__(self, storage=DEFAULT_STORAGE, *args, **kwargs):
        super(MongoOIDsModule, self).__init__(*args, **kwargs)

        self.logger = Logger.get('migrationmodule', MigrationModule.LOG_PATH)

        self.storage = Middleware.get_middleware_by_uri(storage)
        self.storage.connect()
Exemple #5
0
 def __init__(self, *args, **kwargs):
     """
     NONE of arguments are used.
     """
     super(Rights, self).__init__()
     self._storage = Middleware.get_middleware_by_uri('mongodb-default-rights://')
     self._configure()
Exemple #6
0
    def __init__(self, storage=DEFAULT_STORAGE, *args, **kwargs):
        super(MongoOIDsModule, self).__init__(*args, **kwargs)

        self.logger = Logger.get('migrationmodule', MigrationModule.LOG_PATH)

        self.storage = Middleware.get_middleware_by_uri(storage)
        self.storage.connect()
Exemple #7
0
    def __init__(self, *args, **kwargs):
        super(ViewsModule, self).__init__(*args, **kwargs)

        self.logger = Logger.get('migrationmodule', MigrationModule.LOG_PATH)
        self.storage = Middleware.get_middleware_by_uri('storage-default://',
                                                        table='object')
        self.rights = Rights()
Exemple #8
0
    def __init__(self, config=None, logger=None):

        if logger is None:
            self.logger = Logger.get(self.LOG_NAME,
                                     self.LOG_PATH,
                                     output_cls=OutputFile)
        else:
            self.logger = logger

        if config is None:
            self.config = Configuration.load(CONF_PATH, Ini)
        else:
            self.config = config

        self.obj_storage = Middleware.get_middleware_by_uri(
            'storage-default://', table='schemas')

        section = self.config.get(ConfName.SECT_GCTX)
        self._event_types = section[ConfName.EVENT_TYPES]
        self._extra_fields = section[ConfName.EXTRA_FIELDS]

        section = self.config.get(ConfName.SECT_FILTER)
        self._schema_id = section[ConfName.SCHEMA_ID]

        self.reload_schema()
Exemple #9
0
    def setUp(self):
        pbehavior_storage = Middleware.get_middleware_by_uri(
            'storage-default-testpbehavior://'
        )
        entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://'
        )

        logger = Logger.get('test_pb', None, output_cls=OutputNull)
        conf = Configuration.load(PBehaviorManager.CONF_PATH, Ini)
        self.pbm = PBehaviorManager(config=conf,
                                    logger=logger,
                                    pb_storage=pbehavior_storage)
        self.context = ContextGraph(logger)
        self.context.ent_storage = entities_storage
        self.pbm.context = self.context
Exemple #10
0
    def setUp(self):
        self.storage = Middleware.get_middleware_by_uri(
            'mongodb-default-testsession://')
        self.collection = MongoCollection(self.storage._backend)

        self.manager = Session(collection=self.collection)

        self.user = '******'
Exemple #11
0
 def __init__(self, *args, **kwargs):
     """
     NONE of arguments are used.
     """
     super(Rights, self).__init__()
     self._storage = Middleware.get_middleware_by_uri(
         'mongodb-default-rights://')
     self._configure()
Exemple #12
0
    def get_elements(protocol, data_type, data_scope, _id=None, **kwargs):
        storage = Middleware.get_middleware(
            protocol, data_type, data_scope,
            **kwargs
        )
        storage.connect()

        return storage.get_elements(ids=_id) or []
Exemple #13
0
    def setUp(self):
        self.storage = Middleware.get_middleware_by_uri(
            'mongodb-default-testsession://'
        )
        self.collection = MongoCollection(self.storage._backend)

        self.manager = Session(collection=self.collection)

        self.user = '******'
    def setUp(self):
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.DEBUG)
        self.storage = Middleware.get_middleware_by_uri(
            'storage-default-testassociativetable://'
        )

        self.assoc_manager = AssociativeTableManager(logger=self.logger,
                                                     collection=self.storage._backend)
    def setUp(self):
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.DEBUG)

        self.at_storage = Middleware.get_middleware_by_uri(
            'storage-default-testassociativetable://'
        )
        self.at_manager = AssociativeTableManager(
            collection=self.at_storage._backend,
            logger=self.logger
        )

        self.config = self.at_manager.create('test_hlm')
        self.config.set('basic_link_builder', {})
        self.at_manager.save(self.config)

        self.htl_manager = HypertextLinkManager(config=self.config.get_all(),
                                                logger=self.logger)

        self.entity = {
            '_id': 'april/oneil',
            'type': 'resource',
            'name': 'ntm',
            'depends': [],
            'impact': [],
            'measurements': {},
            'infos': {
                'location': 'technodrome'
            }
        }

        self.alarm = {
            '_id': 'krang',
            'd': 'april/oneil',
            't': 0,
            'v': {
                'connector': 'Engine',
                'connector_name': 'JENKINS',
                'component': 'oneil',
                'resource': 'april',
                'state': {
                    'a': 'Splinter',
                    '_t': 'stateinc',
                    'm': 'Possède la pensée juste, alors seulement tu pourras recevoir les dons de la force, du savoir et de la paix.',
                    't': 1,
                    'val': 0
                },
                'output': "Quatre tortues d'enfer, dans la ville",
                'display_name': 'TN-TN-TN',
            }
        }

        conf_store = Configuration.load(MongoStore.CONF_PATH, Ini)
        mongo = MongoStore(config=conf_store)
        self.alerts_collection = mongo.get_collection(name=ALERTS_COLLECTION)

        self.alerts_collection.insert(self.alarm)
Exemple #16
0
    def setUp(self):
        logger = Logger.get('', None, output_cls=OutputNull)
        self.manager = Watcher()
        self.context_graph_manager = ContextGraph(logger)
        self.alerts_storage = Middleware.get_middleware_by_uri(
            'mongodb-periodical-testalarm://'
        )
        self.watcher_storage = Middleware.get_middleware_by_uri(
            'storage-default-testwatcher://'
        )
        self.entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://'
        )

        self.context_graph_manager.ent_storage = self.entities_storage
        self.manager.alert_storage = self.alerts_storage
        self.manager.context_graph = self.context_graph_manager
        self.manager.watcher_storage = self.watcher_storage
Exemple #17
0
    def __init__(self, amqp_pub=None):
        """
        :param amqp_pub canopsis.common.amqp.AmqpPublisher:
        """
        self.logger = Logger.get('watcher', LOG_PATH)
        self.watcher_storage = Middleware.get_middleware_by_uri(
            'mongodb-default-watcher://')
        self.alert_storage = Middleware.get_middleware_by_uri(
            'mongodb-periodical-alarm://')

        self.sla_storage = Middleware.get_middleware_by_uri(
            'storage-default-sla://')

        self.context_graph = ContextGraph(self.logger)
        self.pbehavior_manager = PBehaviorManager(
            *PBehaviorManager.provide_default_basics())
        self.amqp_pub = amqp_pub
        if amqp_pub is None:
            self.amqp_pub = AmqpPublisher(get_default_amqp_conn(), self.logger)
Exemple #18
0
    def setUp(self):
        self.logger = logging.getLogger('alerts')

        self.alerts_storage = Middleware.get_middleware_by_uri(
            'storage-periodical-testalarm://')
        self.config_storage = Middleware.get_middleware_by_uri(
            'storage-default-testconfig://')
        self.config_storage.put_element(element={
            '_id': 'test_config',
            'crecord_type': 'statusmanagement',
            'bagot_time': 3600,
            'bagot_freq': 10,
            'stealthy_time': 300,
            'restore_event': True,
            'auto_snooze': False,
            'snooze_default_time': 300,
        },
                                        _id='test_config')
        self.filter_storage = Middleware.get_middleware_by_uri(
            'storage-default-testalarmfilter://')

        self.context_graph_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://')
        self.cg_manager = ContextGraph(self.logger)
        self.cg_manager.ent_storage = self.context_graph_storage
        self.watcher_manager = Watcher()

        conf = Configuration.load(Alerts.CONF_PATH, Ini)
        filter_ = {'crecord_type': 'statusmanagement'}
        self.config_data = EtherealData(collection=MongoCollection(
            self.config_storage._backend),
                                        filter_=filter_)

        self.event_publisher = Mock(spec=StatEventPublisher)

        self.manager = Alerts(config=conf,
                              logger=self.logger,
                              alerts_storage=self.alerts_storage,
                              config_data=self.config_data,
                              filter_storage=self.filter_storage,
                              context_graph=self.cg_manager,
                              watcher=self.watcher_manager,
                              event_publisher=self.event_publisher)
Exemple #19
0
    def setUp(self):
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.DEBUG)

        self.at_storage = Middleware.get_middleware_by_uri(
            'storage-default-testassociativetable://')
        self.at_manager = AssociativeTableManager(
            collection=self.at_storage._backend, logger=self.logger)

        self.config = self.at_manager.create('test_hlm')
        self.config.set('basic_link_builder', {})
        self.at_manager.save(self.config)

        self.htl_manager = HypertextLinkManager(config=self.config.get_all(),
                                                logger=self.logger)

        self.entity = {
            '_id': 'april/oneil',
            'type': 'resource',
            'name': 'ntm',
            'depends': [],
            'impact': [],
            'measurements': {},
            'infos': {
                'location': 'technodrome'
            }
        }

        self.alarm = {
            '_id': 'krang',
            'd': 'april/oneil',
            't': 0,
            'v': {
                'connector': 'Engine',
                'connector_name': 'JENKINS',
                'component': 'oneil',
                'resource': 'april',
                'state': {
                    'a': 'Splinter',
                    '_t': 'stateinc',
                    'm':
                    'Possède la pensée juste, alors seulement tu pourras recevoir les dons de la force, du savoir et de la paix.',
                    't': 1,
                    'val': 0
                },
                'output': "Quatre tortues d'enfer, dans la ville",
                'display_name': 'TN-TN-TN',
            }
        }

        conf_store = Configuration.load(MongoStore.CONF_PATH, Ini)
        mongo = MongoStore(config=conf_store)
        self.alerts_collection = mongo.get_collection(name=ALERTS_COLLECTION)

        self.alerts_collection.insert(self.alarm)
Exemple #20
0
    def __init__(self, amqp_pub=None):
        """
        :param amqp_pub canopsis.common.amqp.AmqpPublisher:
        """
        self.logger = Logger.get('watcher', LOG_PATH)
        self.watcher_storage = Middleware.get_middleware_by_uri(
            'mongodb-default-watcher://')
        self.alert_storage = Middleware.get_middleware_by_uri(
            'mongodb-periodical-alarm://')

        self.sla_storage = Middleware.get_middleware_by_uri(
            'storage-default-sla://')

        self.context_graph = ContextGraph(self.logger)
        self.pbehavior_manager = PBehaviorManager(
            *PBehaviorManager.provide_default_basics()
        )
        self.amqp_pub = amqp_pub
        if amqp_pub is None:
            self.amqp_pub = AmqpPublisher(get_default_amqp_conn(), self.logger)
    def setUp(self):
        output = StringIO()
        self.logger = Logger.get('test', output, OutputStream)

        self.storage = Middleware.get_middleware_by_uri(
            'storage-default-testmongocollection://')

        self.collection = MongoCollection(collection=self.storage._backend,
                                          logger=self.logger)

        self.id_ = 'testid'
Exemple #22
0
    def provide_default_basics(cls):
        """
        Provide logger, config, storages...

        ! Do not use in tests !

        :rtype: Union[canopsis.confng.simpleconf.Configuration
                      logging.Logger,
                      canopsis.storage.core.Storage,
                      canopsis.common.ethereal_data.EtherealData,
                      canopsis.storage.core.Storage,
                      canopsis.context_graph.manager.ContextGraph,
                      canopsis.watcher.manager.Watcher]
        """
        config = Configuration.load(Alerts.CONF_PATH, Ini)
        conf_store = Configuration.load(MongoStore.CONF_PATH, Ini)

        mongo = MongoStore(config=conf_store)
        config_collection = MongoCollection(
            mongo.get_collection(name=cls.CONFIG_COLLECTION))
        filter_ = {'crecord_type': 'statusmanagement'}
        config_data = EtherealData(collection=config_collection,
                                   filter_=filter_)

        logger = Logger.get('alerts', cls.LOG_PATH)
        alerts_storage = Middleware.get_middleware_by_uri(
            cls.ALERTS_STORAGE_URI
        )
        filter_storage = Middleware.get_middleware_by_uri(
            cls.FILTER_STORAGE_URI
        )
        context_manager = ContextGraph(logger)
        watcher_manager = Watcher()
        pbehavior_manager = PBehaviorManager(*PBehaviorManager.provide_default_basics())

        amqp_pub = AmqpPublisher(get_default_amqp_conn(), logger)
        event_publisher = StatEventPublisher(logger, amqp_pub)

        return (config, logger, alerts_storage, config_data,
                filter_storage, context_manager, watcher_manager,
                event_publisher, pbehavior_manager)
Exemple #23
0
    def provide_default_basics(cls):
        """
        Provide default event_storage.

        Do not use in tests.

        :rtype: Union[canopsis.storage.core.Storage]
        """
        event_storage = Middleware.get_middleware_by_uri(
            cls.DEFAULT_EVENT_STORAGE_URI, table='events')

        return (event_storage,)
Exemple #24
0
    def setUp(self):
        self.manager = ContextGraph(logger)
        self.entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://')
        self.organisations_storage = Middleware.get_middleware_by_uri(
            'storage-default-testorganisations://')
        self.users_storage = Middleware.get_middleware_by_uri(
            'storage-default-testusers://')

        self.manager.ent_storage = self.entities_storage

        self.template = {
            '_id': None,
            'type': 'connector',
            'name': 'conn-name1',
            'depends': [],
            'impact': [],
            'measurements': [],
            'links': {},
            'infos': {}
        }
Exemple #25
0
    def remove_elements(
        protocol, data_type, data_scope,
        _id=None, _filter=None,
        **kwargs
    ):
        storage = Middleware.get_middleware(
            protocol, data_type, data_scope,
            **kwargs
        )
        storage.connect()

        storage.remove_elements(ids=_id, _filter=_filter)
Exemple #26
0
    def provide_default_basics(cls):
        """
        Provide default event_storage.

        Do not use in tests.

        :rtype: Union[canopsis.storage.core.Storage]
        """
        event_storage = Middleware.get_middleware_by_uri(
            cls.DEFAULT_EVENT_STORAGE_URI, table='events')

        return (event_storage, )
Exemple #27
0
    def __init__(self,
                 logger,
                 *args, **kwargs):
        """__init__

        :param *args:
        :param **kwargs:
        """

        parser = Configuration.load(CONF_PATH, Ini)
        section = parser.get(ConfName.SECT_GCTX)

        self.collection_name = 'default_entities'

        self.at_storage = Middleware.get_middleware_by_uri(
            AssociativeTableManager.STORAGE_URI
        )

        self.ent_storage = Middleware.get_middleware_by_uri(
            section.get(ConfName.ENT_STORAGE)
        )

        self.logger = logger

        # For links building
        at_collection = self.at_storage._backend
        self.at_manager = AssociativeTableManager(logger=self.logger,
                                                  collection=at_collection)

        hypertextlink_conf = section.get(ConfName.CTX_HYPERLINK, "")
        self.event_types = section.get(ConfName.EVENT_TYPES, [])
        self.extra_fields = section.get(ConfName.EXTRA_FIELDS, [])

        if hypertextlink_conf != "":
            atable = self.at_manager.get(hypertextlink_conf)
            if atable is not None:
                conf = atable.get_all()
                self.hlb_manager = HypertextLinkManager(conf, self.logger)

        self.filter_ = InfosFilter(logger=self.logger)
Exemple #28
0
    def provide_default_basics(cls):
        """
        Provide logger, config, storages...

        ! Do not use in tests !

        :rtype: Union[canopsis.confng.simpleconf.Configuration
                      logging.Logger,
                      canopsis.storage.core.Storage,
                      canopsis.common.ethereal_data.EtherealData,
                      canopsis.storage.core.Storage,
                      canopsis.context_graph.manager.ContextGraph,
                      canopsis.watcher.manager.Watcher]
        """
        config = Configuration.load(Alerts.CONF_PATH, Ini)
        conf_store = Configuration.load(MongoStore.CONF_PATH, Ini)

        mongo = MongoStore(config=conf_store)
        config_collection = MongoCollection(
            mongo.get_collection(name=cls.CONFIG_COLLECTION))
        filter_ = {'crecord_type': 'statusmanagement'}
        config_data = EtherealData(collection=config_collection,
                                   filter_=filter_)

        logger = Logger.get('alerts', cls.LOG_PATH)
        alerts_storage = Middleware.get_middleware_by_uri(
            cls.ALERTS_STORAGE_URI
        )
        filter_storage = Middleware.get_middleware_by_uri(
            cls.FILTER_STORAGE_URI
        )
        context_manager = ContextGraph(logger)
        watcher_manager = Watcher()

        amqp_pub = AmqpPublisher(get_default_amqp_conn(), logger)
        event_publisher = StatEventPublisher(logger, amqp_pub)

        return (config, logger, alerts_storage, config_data,
                filter_storage, context_manager, watcher_manager,
                event_publisher)
Exemple #29
0
    def setUp(self):
        self.manager = ContextGraph(logger)
        self.entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://'
        )
        self.organisations_storage = Middleware.get_middleware_by_uri(
            'storage-default-testorganisations://'
        )
        self.users_storage = Middleware.get_middleware_by_uri(
            'storage-default-testusers://'
        )

        self.manager.ent_storage = self.entities_storage

        self.template = {'_id': None,
                         'type': 'connector',
                         'name': 'conn-name1',
                         'depends': [],
                         'impact': [],
                         'measurements': [],
                         'links': {},
                         'infos': {}}
Exemple #30
0
    def put_element(
        protocol, data_type, data_scope,
        _id=None, element=None,
        **kwargs
    ):
        storage = Middleware.get_middleware(
            protocol, data_type, data_scope,
            **kwargs
        )
        storage.connect()

        if not storage.put_element(element, _id=_id):
            return HTTPError(500, 'Impossible to put element in storage')
Exemple #31
0
    def provide_default_basics(cls):
        """
        Provide the default configuration and logger objects
        for PBehaviorManager.

        Do not use those defaults for tests.

        :return: config, logger, storage
        :rtype: Union[dict, logging.Logger, canopsis.storage.core.Storage]
        """
        logger = Logger.get(cls.LOG_NAME, cls.LOG_PATH)
        pb_storage = Middleware.get_middleware_by_uri(cls.PB_STORAGE_URI)

        return logger, pb_storage
    def setUp(self):
        """
        initialize a manager.
        """

        self.manager = CalendarManager(storage=Middleware.get_middleware_by_uri('mongodb-default-calendar://'))
        self.document_content = self.manager.get_document(
            category="2", output="true date or not",
            dtstart=1434359519, dtend=1434705119
        )
        self.vevent_content = self.manager.get_vevent(
            self.document_content
        )
        print("type and value of vevent_content", self.vevent_content)
Exemple #33
0
    def __init__(self, config=None, *args, **kwargs):
        """__init__
        :param config: a configuration
        :param *args:
        :param **kwargs:
        """
        if config is None:
            self.config = Configuration.load(self.CONF_FILE, Ini)
        else:
            self.config = config

        section = self.config.get(self.CONFIG_CAT, self.DEFAULT_CONFIG)
        self.storage = Middleware.get_middleware_by_uri(
            section[self.STORAGE_URI])
Exemple #34
0
    def __init__(self, config=None, *args, **kwargs):
        """__init__
        :param config: a configuration
        :param *args:
        :param **kwargs:
        """
        if config is None:
            self.config = Configuration.load(self.CONF_FILE, Ini)
        else:
            self.config = config

        section = self.config.get(self.CONFIG_CAT, self.DEFAULT_CONFIG)
        self.storage = Middleware.get_middleware_by_uri(
            section[self.STORAGE_URI])
Exemple #35
0
    def __init__(self, logger, *args, **kwargs):
        """__init__

        :param *args:
        :param **kwargs:
        """

        parser = Configuration.load(CONF_PATH, Ini)
        section = parser.get(ConfName.SECT_GCTX)

        self.collection_name = 'default_entities'

        self.at_storage = Middleware.get_middleware_by_uri(
            AssociativeTableManager.STORAGE_URI)

        self.ent_storage = Middleware.get_middleware_by_uri(
            section.get(ConfName.ENT_STORAGE))

        self.logger = logger

        # For links building
        at_collection = self.at_storage._backend
        self.at_manager = AssociativeTableManager(logger=self.logger,
                                                  collection=at_collection)

        hypertextlink_conf = section.get(ConfName.CTX_HYPERLINK, "")
        self.event_types = section.get(ConfName.EVENT_TYPES, [])
        self.extra_fields = section.get(ConfName.EXTRA_FIELDS, [])

        if hypertextlink_conf != "":
            atable = self.at_manager.get(hypertextlink_conf)
            if atable is not None:
                conf = atable.get_all()
                self.hlb_manager = HypertextLinkManager(conf, self.logger)

        self.filter_ = InfosFilter(logger=self.logger)
Exemple #36
0
    def setUp(self):
        mongo = MongoStore.get_default()
        collection = mongo.get_collection("default_testpbehavior")
        pb_coll = MongoCollection(collection)
        entities_storage = Middleware.get_middleware_by_uri(
            'storage-default-testentities://')

        logger = Logger.get('test_pb', None, output_cls=OutputNull)
        conf = Configuration.load(PBehaviorManager.CONF_PATH, Ini)
        self.pbm = PBehaviorManager(config=conf,
                                    logger=logger,
                                    pb_collection=pb_coll)
        self.context = ContextGraph(logger)
        self.context.ent_storage = entities_storage
        self.pbm.context = self.context
Exemple #37
0
    def provide_default_basics(cls):
        """
        Provide the default configuration and logger objects
        for PBehaviorManager.

        Do not use those defaults for tests.

        :return: config, logger, storage
        :rtype: Union[dict, logging.Logger, canopsis.storage.core.Storage]
        """
        logger = Logger.get(cls.LOG_NAME, cls.LOG_PATH)
        pb_storage = Middleware.get_middleware_by_uri(cls.PB_STORAGE_URI)
        config = Configuration.load(PBehaviorManager.CONF_PATH, Ini)

        return config, logger, pb_storage
Exemple #38
0
    def setUp(self):
        self.storage = Middleware.get_middleware_by_uri(
            'mongodb-default-testsession://')
        self.collection = MongoCollection(self.storage._backend)

        self.manager = Session(collection=self.collection)

        self.user = '******'
        self.id_beaker_session = 'cm9vdF8xNTc2MDY1MzY2'
        self.path = [
            "view/da7ac9b9-db1c-4435-a1f2-edb4d6be4db8",
            "view-tab_edd5855b-54f1-4c51-9550-d88c2da60768"
        ]
        self.path_bis = [
            "view/da7ac9b9-db1c-4435-a1f2-edb4d6be4db8",
            "view-tab_edd5855b-54f1-4c51-azerty"
        ]
Exemple #39
0
    def __init__(self, config=None, check_storage=None, *args, **kwargs):
        super(CheckManager, self).__init__(*args, **kwargs)

        if config is None:
            self.config = Configuration.load(CONF_PATH, Ini)
        else:
            self.config = config

        self.config_check = self.config.get(CONF_CATEGORY, {})
        self.types = cfg_to_array(self.config_check.get('types', DEFAULT_TYPES))

        if check_storage is None:
            self.check_storage = Middleware.get_middleware_by_uri(
                self.config_check.get('check_storage_uri', DEFAULT_CHECK_STORAGE_URI)
            )
        else:
            self.check_storage = check_storage
Exemple #40
0
    def __init__(self, config=None, check_storage=None, *args, **kwargs):
        super(CheckManager, self).__init__(*args, **kwargs)

        if config is None:
            self.config = Configuration.load(CONF_PATH, Ini)
        else:
            self.config = config

        self.config_check = self.config.get(CONF_CATEGORY, {})
        self.types = cfg_to_array(self.config_check.get(
            'types', DEFAULT_TYPES))

        if check_storage is None:
            self.check_storage = Middleware.get_middleware_by_uri(
                self.config_check.get('check_storage_uri',
                                      DEFAULT_CHECK_STORAGE_URI))
        else:
            self.check_storage = check_storage
Exemple #41
0
    def provide_default_basics(cls):
        """
        Provide logger, config, storages...

        ! Do not use in tests !

        :rtype: Union[logging.Logger,
                      canospis.confng.simpleconf.Configuration,
                      canopsis.storage.core.Storage,
                      canopsis.pbehavior.manager.PBehaviorManager]
        """
        logger = Logger.get('alertsreader', cls.LOG_PATH)
        conf = Configuration.load(Alerts.CONF_PATH, Ini)
        alerts_storage = Middleware.get_middleware_by_uri(
            Alerts.ALERTS_STORAGE_URI
        )

        pbm = PBehaviorManager(*PBehaviorManager.provide_default_basics())

        return (logger, conf, alerts_storage, pbm)
Exemple #42
0
    def provide_default_basics(cls):
        """
        Provide logger, config, storages...

        ! Do not use in tests !

        :rtype: Union[logging.Logger,
                      canospis.confng.simpleconf.Configuration,
                      canopsis.storage.core.Storage,
                      canopsis.pbehavior.manager.PBehaviorManager]
        """
        logger = Logger.get('alertsreader', cls.LOG_PATH)
        conf = Configuration.load(Alerts.CONF_PATH, Ini)
        alerts_storage = Middleware.get_middleware_by_uri(
            Alerts.ALERTS_STORAGE_URI
        )

        pbm = PBehaviorManager(*PBehaviorManager.provide_default_basics())

        return (logger, conf, alerts_storage, pbm)
Exemple #43
0
    def find_elements(
        protocol, data_type, data_scope,
        query=None, projection=None,
        limit=0, skip=0, sort=None,
        with_count=False,
        **kwargs
    ):
        storage = Middleware.get_middleware(
            protocol, data_type, data_scope,
            **kwargs
        )
        storage.connect()

        total = storage.count_elements(query=query)
        result = storage.find_elements(
            query=query, projection=projection,
            limit=limit, skip=skip, sort=sort,
            with_count=with_count
        )

        return result, total
Exemple #44
0
def event_processing(event, veventmanager=None, **params):
    """Add vevent information in VEventManager from input event.

    :param dict event: event to process.
    :param function get_info: function which takes in parameter the event and
        returns vevent info.
    """

    # initialiaze veventmanager
    if veventmanager is None:
        storage = Middleware.get_middleware_by_uri(
            VEventManager.VEVENT_COLL_URL)
        veventmanager = singleton_per_scope(VEventManager,
                                            kwargs={'vevent_storage': storage})
    context = singleton_per_scope(ContextGraph)
    # get source from the event
    source = context.get_id(event)
    # get vevent from the event
    vevent = event[VEventManager.VEVENT]
    # add event information into veventmanager
    veventmanager.put(source=source, vevents=[vevent], cache=True)
Exemple #45
0
def exports(ws):
    """
    Expose session routes.
    """

    kwargs = {
        'collection': Middleware.get_middleware_by_uri(
            Session.SESSION_STORAGE_URI
        )._backend
    }
    session_manager = singleton_per_scope(Session, kwargs=kwargs)

    @route(ws.application.get, name='account/me', adapt=False)
    def get_me():
        """
        Return the user account.
        """
        user = get_user()
        user.pop('id', None)
        user.pop('eid', None)

        return user

    @route(ws.application.get, payload=['username'])
    def keepalive(username):
        """
        Maintain the current session.
        """
        session_manager.keep_alive(username)

    @ws.application.get('/sessionstart')
    def sessionstart():
        """
        Start a new session.
        """
        username = request.get('username', None)

        session_manager.session_start(username)
        return {}
Exemple #46
0
    def setUp(self):
        super(TestReader, self).setUp()
        self.pb_storage = Middleware.get_middleware_by_uri(
            PBehaviorManager.PB_STORAGE_URI
        )

        self.logger = Logger.get('alertsreader', '/tmp/null')
        conf = Configuration.load(PBehaviorManager.CONF_PATH, Ini)
        self.pbehavior_manager = PBehaviorManager(config=conf,
                                                  logger=self.logger,
                                                  pb_storage=self.pb_storage)

        self.reader = AlertsReader(config=conf,
                                   logger=self.logger,
                                   storage=self.manager.alerts_storage,
                                   pbehavior_manager=self.pbehavior_manager)

        self.reader._alarm_fields = {
            'properties': {
                'connector': {'stored_name': 'v.ctr'},
                'component': {'stored_name': 'v.cpt'},
                'entity_id': {'stored_name': 'd'}
            }
        }
Exemple #47
0
# (at your option) any later version.
#
# Canopsis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Canopsis.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------

from canopsis.common.ws import route
from canopsis.vevent.manager import VEventManager
from canopsis.common.middleware import Middleware

vem = VEventManager(storage=Middleware.get_middleware_by_uri(VEventManager.VEVENT_COLL_URL))

DEFAULT_ROUTE = 'vevent'  #: route specifics to vevents document


def exports(ws):

    @route(ws.application.get, name=DEFAULT_ROUTE)
    def get_by_uids(
        ids, limit=0, skip=0, sort=None, projection=None, with_count=False
    ):
        """Get documents by uids.

        :param list ids: list of document ids.
        :param int limit: max number of elements to get.
        :param int skip: first element index among searched list.
Exemple #48
0
    def setUp(self):
        super(ComputeState, self).setUp()
        pbehavior_storage = Middleware.get_middleware_by_uri(
            'storage-default-testpbehavior://'
        )
        filter_storage = Middleware.get_middleware_by_uri(
            'storage-default-testalarmfilter://'
        )
        config_storage = Middleware.get_middleware_by_uri(
            'storage-default-testconfig://'
        )
        config_storage.put_element(
            element={
                '_id': 'test_config',
                'crecord_type': 'statusmanagement',
                'bagot_time': 3600,
                'bagot_freq': 10,
                'stealthy_time': 300,
                'restore_event': True,
                'auto_snooze': False,
                'snooze_default_time': 300,
            },
            _id='test_config'
        )
        logger = Logger.get('test_pb', None, output_cls=OutputNull)

        config = Configuration.load(PBehaviorManager.CONF_PATH, Ini)

        self.pbm = PBehaviorManager(config=config,
                                    logger=logger,
                                    pb_storage=pbehavior_storage)
        self.pbm.context = self.context_graph_manager
        self.manager.pbehavior_manager = self.pbm

        conf = Configuration.load(Alerts.CONF_PATH, Ini)
        filter_ = {'crecord_type': 'statusmanagement'}
        config_data = EtherealData(collection=config_storage._backend,
                                   filter_=filter_)

        event_publisher = Mock(spec=StatEventPublisher)

        self.alert_manager = Alerts(config=conf,
                                    logger=logger,
                                    alerts_storage=self.alerts_storage,
                                    config_data=config_data,
                                    filter_storage=filter_storage,
                                    context_graph=self.context_graph_manager,
                                    watcher=self.manager,
                                    event_publisher=event_publisher)

        # Creating entity
        self.type_ = 'resource'
        self.name = 'morticia'
        entity = ContextGraph.create_entity_dict(
            id=self.name,
            etype=self.type_,
            name=self.name
        )
        self.context_graph_manager.create_entity(entity)

        # Creating coresponding alarm
        event = {
            'connector': self.type_,
            'connector_name': 'connector_name',
            'component': self.name,
            'output': 'tadaTaDA tic tic',
            'timestamp': 0
        }
        alarm = self.alert_manager.make_alarm(self.name, event)
        self.state = 2
        alarm = self.alert_manager.update_state(alarm, self.state, event)
        new_value = alarm[self.alert_manager.alerts_storage.VALUE]
        self.alert_manager.update_current_alarm(alarm, new_value)
Exemple #49
0
 def setUpClass(cls):
     cls.event_storage = Middleware.get_middleware_by_uri('mongodb-default-testevent://')
Exemple #50
0
# Canopsis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Canopsis.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------

from json import dumps

from canopsis.ccalendar.manager import CalendarManager
from canopsis.common.ws import route
from canopsis.common.middleware import Middleware

cm = CalendarManager(storage=Middleware.get_middleware_by_uri(CalendarManager.CALENDAR_COLL_URI))


def exports(ws):

    @route(ws.application.get, name='calendar')
    def get_by_uids(
        uids, limit=0, skip=0, sort=None, projection=None, with_count=False
    ):
        """Get documents by uids.

        :param list uids: list of document uids.
        :param int limit: max number of elements to get.
        :param int skip: first element index among searched list.
        :param sort: contains a list of couples of field (name, ASC/DESC)
            or field name which denots an implicitelly ASC order.
Exemple #51
0
 def provide_default_basics(cls):
     """
     Provide default storage for EventsLog
     """
     return Middleware.get_middleware_by_uri(
         cls.DEFAULT_EL_STORAGE_URI, table='events_log')
 def setUpClass(cls):
     el_storage = Middleware.get_middleware_by_uri('mongodb-default-testeventslog://')
     cls.manager = EventsLog(el_storage=el_storage)