def __init__(self, options={}): super(BasicAlarmLinkBuilder, self).__init__(options=options) self.logger = Logger.get('context-graph', LOG_PATH) conf_store = Configuration.load(MongoStore.CONF_PATH, Ini) mongo = MongoStore(config=conf_store) self.alerts_collection = mongo.get_collection(name=ALERTS_COLLECTION)
def __init__(self, options={}): super(BasicAlarmLinkBuilder, self).__init__(options=options) self.logger = Logger.get('context-graph', LOG_PATH) conf_store = Configuration.load(MongoStore.CONF_PATH, Ini) mongo = MongoStore(config=conf_store) self.alerts_collection = mongo.get_collection(name=ALERTS_COLLECTION)
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)
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)
def provide_default_basics(cls): """ provide default basics """ conf_store = Configuration.load(MongoStore.CONF_PATH, Ini) mongo = MongoStore(config=conf_store) lock_collection = mongo.get_collection(name=cls.LOCK_COLLECTION) logger = Logger.get('lock', cls.LOG_PATH) return (logger, lock_collection)
def provide_default_basics(cls): """ provide default basics """ conf_store = Configuration.load(MongoStore.CONF_PATH, Ini) mongo = MongoStore(config=conf_store) lock_collection = mongo.get_collection(name=cls.LOCK_COLLECTION) logger = Logger.get('lock', cls.LOG_PATH) return (logger, lock_collection)
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)
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)
class TestEtherealData(unittest.TestCase): def setUp(self): config = configparser.RawConfigParser() config.read(os.path.join(root_path, DEFAULT_CONF_FILE)) self.conf = { MongoStore.CONF_CAT: { "host": config["DATABASE"]["host"], "port": config["DATABASE"]["port"], 'db': config["DATABASE"]["db"], 'user': config["DATABASE"]["user"], 'pwd': config["DATABASE"]["pwd"] } } self.client = MongoStore(config=self.conf) self.collection = self.client.get_collection('any_collection') self.ed = EtherealData(collection=self.collection, filter_={}, timeout=2) def tearDown(self): """Teardown""" self.collection.drop() def test_get_set(self): self.assertIsNone(self.ed.get('mario')) self.ed.set('mario', 'bros') self.assertEqual(self.ed.get('mario'), 'bros') def test_cache(self): self.ed.set('sonic', 'hedgehog') self.assertEqual(self.ed.get('sonic'), 'hedgehog') self.collection.update({}, {'sonic': 'tails'}) self.assertEqual(self.ed.get('sonic'), 'hedgehog') sleep(3) self.assertEqual(self.ed.get('sonic'), 'tails')
class TestEtherealData(unittest.TestCase): def setUp(self): config = configparser.RawConfigParser() config.read(os.path.join(root_path, DEFAULT_CONF_FILE)) self.conf = { MongoStore.CONF_CAT: { "host": config["DATABASE"]["host"], "port": config["DATABASE"]["port"], 'db': config["DATABASE"]["db"], 'user': config["DATABASE"]["user"], 'pwd': config["DATABASE"]["pwd"] } } self.client = MongoStore(config=self.conf) self.collection = self.client.get_collection('any_collection') self.ed = EtherealData(collection=self.collection, filter_={}, timeout=2) def tearDown(self): """Teardown""" self.collection.drop() def test_get_set(self): self.assertIsNone(self.ed.get('mario')) self.ed.set('mario', 'bros') self.assertEqual(self.ed.get('mario'), 'bros') def test_cache(self): self.ed.set('sonic', 'hedgehog') self.assertEqual(self.ed.get('sonic'), 'hedgehog') self.collection.update({}, {'sonic': 'tails'}) self.assertEqual(self.ed.get('sonic'), 'hedgehog') sleep(3) self.assertEqual(self.ed.get('sonic'), 'tails')