def test_config_ignored(self):
     """
     Asserts that ignored_data is properly ignored.
     """
     ignored_data = dict(exchange=['a.*', 'b.*'])
     conf = utils.Config(self.auth, self.conn, ignored_data)
     self.assertTrue(conf.is_ignored('exchange', 'abc'))
 def test_config_url(self):
     """
     Assert that host and port are set from URL.
     """
     conf = utils.Config(None, self.conn)
     self.assertEquals(conf.connection.host, "example.com")
     self.assertEquals(conf.connection.scheme, "http")
     self.assertEquals(conf.connection.port, 15672)
def configure(config_values):
    """
    Converts a collectd configuration into rabbitmq configuration.
    """

    collectd.debug('Configuring RabbitMQ Plugin')
    data_to_ignore = dict()
    scheme = 'http'
    validate_certs = True
    vhost_prefix = None
    local_queues_only = False

    for config_value in config_values.children:
        collectd.debug("%s = %s" % (config_value.key, config_value.values))
        if len(config_value.values) > 0:
            if config_value.key == 'Username':
                username = config_value.values[0]
            elif config_value.key == 'Password':
                password = config_value.values[0]
            elif config_value.key == 'Host':
                host = config_value.values[0]
            elif config_value.key == 'Port':
                port = config_value.values[0]
            elif config_value.key == 'Realm':
                realm = config_value.values[0]
            elif config_value.key == 'Scheme':
                scheme = config_value.values[0]
            elif config_value.key == 'VHostPrefix':
                vhost_prefix = config_value.values[0]
            elif config_value.key == 'ValidateCerts':
                validate_certs = config_value.values[0]
            elif config_value.key == 'LocalQueuesOnly':
                local_queues_only = config_value.values[0]
            elif config_value.key == 'Ignore':
                type_rmq = config_value.values[0]
                data_to_ignore[type_rmq] = list()
                for regex in config_value.children:
                    data_to_ignore[type_rmq].append(regex.values[0])

    global CONFIGS  # pylint: disable=W0603

    auth = utils.Auth(username, password, realm)
    conn = utils.ConnectionInfo(host, port, scheme,
                                validate_certs=validate_certs)
    config = utils.Config(auth, conn, data_to_ignore, vhost_prefix,
                          local_queues_only)
    CONFIGS.append(config)
Exemple #4
0
def configure(config_values):
    """
    Converts a collectd configuration into rabbitmq configuration.
    """

    collectd.debug('Configuring RabbitMQ Plugin')
    data_to_ignore = dict()
    scheme = 'http'
    vhost_prefix = None

    for config_value in config_values.children:
        collectd.debug("%s = %s" % (config_value.key, config_value.values))
        if len(config_value.values) > 0:
            if config_value.key == 'Username':
                username = config_value.values[0]
            elif config_value.key == 'Password':
                password = config_value.values[0]
            elif config_value.key == 'Host':
                host = config_value.values[0]
            elif config_value.key == 'Port':
                port = config_value.values[0]
            elif config_value.key == 'Realm':
                realm = config_value.values[0]
            elif config_value.key == 'Scheme':
                scheme = config_value.values[0]
            elif config_value.key == 'VHostPrefix':
                vhost_prefix = config_value.values[0]
            elif config_value.key == 'Ignore':
                type_rmq = config_value.values[0]
                data_to_ignore[type_rmq] = list()
                for regex in config_value.children:
                    data_to_ignore[type_rmq].append(regex.values[0])

    global AUTH  # pylint: disable=W0603
    global CONN  # pylint: disable=W0603
    global CONFIG  # pylint: disable=W0603

    AUTH = utils.Auth(username, password, realm)
    CONN = utils.ConnectionInfo(host, port, scheme)
    CONFIG = utils.Config(AUTH, CONN, data_to_ignore, vhost_prefix)