def test_connection_explicit(self): amqp_conn = AmqpConnection(self.amqp_url) amqp_conn.connect() self.assertIsNotNone(amqp_conn._connection) self.assertIsNotNone(amqp_conn._channel) amqp_conn.disconnect() self.assertIsNone(amqp_conn._connection) self.assertIsNone(amqp_conn._channel)
def __init__(self, logger): self.logger = logger self.db_store = MongoStore.get_default() self.cache_store = RedisStore.get_default() self.amqp_url, self.amqp_exchange = AmqpConnection.parse_conf() self.ts_client = InfluxDBClient.from_configuration(self.logger)
def test_bad_canopsis_event_raises(self): event = {} with AmqpConnection(self.amqp_url) as ac: amqp_pub = AmqpPublisher(ac, Mock()) with self.assertRaises(KeyError): amqp_pub.canopsis_event(event, self.amqp_exname)
def setUpClass(cls): cls.amqp_url, cls.amqp_exname = AmqpConnection.parse_conf() cls.event = { 'connector': 'test_amqp', 'connector_name': 'test_amqp', 'source_type': 'resource', 'event_type': 'check', 'component': 'test', 'resource': 'test' }
def __init__(self, logger): self.logger = logger self.db_store = MongoStore.get_default() self.cache_store = RedisStore.get_default() self.amqp_url, self.amqp_exchange = AmqpConnection.parse_conf() self.ts_client = InfluxDBClient.from_configuration(self.logger) parser = Configuration.load(CONF_PATH, Ini) section = parser.get(ConfName.SECT_HC) self.check_amqp_limit_size = int( section.get(ConfName.CHECK_AMQP_LIMIT_SIZE, "")) self.check_amqp_queues = section.get(ConfName.CHECK_AMQP_QUEUES, "").split(",") self.check_collections = section.get(ConfName.CHECK_COLLECTIONS, "").split(",") self.check_engines_list = section.get(ConfName.CHECK_ENGINES, "").split(",") self.check_ts_db = section.get(ConfName.CHECK_TS_DB, "") self.check_webserver = section.get(ConfName.CHECK_WEBSERVER, "") self.systemctl_engine_prefix = section.get( ConfName.SYSTEMCTL_ENGINE_PREFIX, "")
def check_amqp(self): """ Check if amqp service is available. :rtype: ServiceState """ try: with AmqpConnection(self.amqp_url) as amqp_conn: channel = amqp_conn._channel try: channel.basic_publish(self.amqp_exchange, '', 'test') except Exception as exc: msg = 'Failed to publish: {}'.format(exc) return ServiceState(message=msg) if not amqp_conn._connection.is_open: return ServiceState(message='Connection is not opened') if not channel.is_open: return ServiceState(message='Channel is not opened') except ConnectionClosed as exc: return ServiceState(message='Failed to connect: {}'.format(exc)) return self._check_rabbitmq_state()
def _amqp_setup(self): logger = logging.getLogger("test_base") self.amqp_conn = AmqpConnection(self.AMQP_URL) self.amqp_pub = AmqpPublisher(self.amqp_conn, logger)
def _amqp_setup(self): self.amqp_conn = AmqpConnection(self.AMQP_URL) self.amqp_pub = AmqpPublisher(self.amqp_conn)
def test_json_document(self): jdoc = {'bla': 'bla'} with AmqpConnection(self.amqp_url) as ac: amqp_pub = AmqpPublisher(ac, Mock()) amqp_pub.json_document(jdoc, self.amqp_exname, '#')
def test_canopsis_event(self): with AmqpConnection(self.amqp_url) as ac: amqp_pub = AmqpPublisher(ac, Mock()) amqp_pub.canopsis_event(self.event, self.amqp_exname)
def test_connection_with_statement(self): with AmqpConnection(self.amqp_url) as amqp_conn: self.assertIsNotNone(amqp_conn.connection) self.assertIsNotNone(amqp_conn.channel)