示例#1
0
    def check(self, instance):
        try:
            directory = instance['directory']
        except KeyError:
            raise ConfigurationError(
                'DirectoryCheck: missing `directory` in config')

        abs_directory = abspath(directory)
        name = instance.get('name', directory)
        pattern = instance.get('pattern')
        exclude_dirs = instance.get('exclude_dirs', [])
        exclude_dirs_pattern = re_compile(
            '|'.join(exclude_dirs)) if exclude_dirs else None
        dirs_patterns_full = is_affirmative(
            instance.get('dirs_patterns_full', False))
        recursive = is_affirmative(instance.get('recursive', False))
        dirtagname = instance.get('dirtagname', 'name')
        filetagname = instance.get('filetagname', 'filename')
        filegauges = is_affirmative(instance.get('filegauges', False))
        countonly = is_affirmative(instance.get('countonly', False))
        ignore_missing = is_affirmative(instance.get('ignore_missing', False))
        custom_tags = instance.get('tags', [])

        if not exists(abs_directory):
            msg = "Either directory '{}' doesn't exist or the Agent doesn't "\
                  "have permissions to access it, skipping.".format(abs_directory)

            if not ignore_missing:
                raise ConfigurationError(msg)

            self.log.warning(msg)

        self._get_stats(abs_directory, name, dirtagname, filetagname,
                        filegauges, pattern, exclude_dirs_pattern,
                        dirs_patterns_full, recursive, countonly, custom_tags)
示例#2
0
def from_instance(instance, default_ca_certs=None):
    """
    Create a config object from an instance dictionary
    """
    method = instance.get('method', 'get')
    data = instance.get('data', {})
    tags = instance.get('tags', [])
    ntlm_domain = instance.get('ntlm_domain')
    username = instance.get('username')
    password = instance.get('password')
    client_cert = instance.get('client_cert')
    client_key = instance.get('client_key')
    http_response_status_code = str(
        instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
    timeout = int(instance.get('timeout', 10))
    config_headers = instance.get('headers', {})
    default_headers = _is_affirmative(
        instance.get("include_default_headers", True))
    if default_headers:
        headers = agent_headers({})
    else:
        headers = {}
    headers.update(config_headers)
    url = instance.get('url')
    content_match = instance.get('content_match')
    reverse_content_match = _is_affirmative(
        instance.get('reverse_content_match', False))
    response_time = _is_affirmative(instance.get('collect_response_time',
                                                 True))
    if not url:
        raise ConfigurationError("Bad configuration. You must specify a url")
    if not url.startswith("http"):
        raise ConfigurationError(
            "The url {} must start with the scheme http or https".format(url))
    include_content = _is_affirmative(instance.get('include_content', False))
    disable_ssl_validation = _is_affirmative(
        instance.get('disable_ssl_validation', True))
    ssl_expire = _is_affirmative(
        instance.get('check_certificate_expiration', True))
    instance_ca_certs = instance.get('ca_certs', default_ca_certs)
    weakcipher = _is_affirmative(instance.get('weakciphers', False))
    ignore_ssl_warning = _is_affirmative(
        instance.get('ignore_ssl_warning', False))
    check_hostname = _is_affirmative(instance.get('check_hostname', True))
    skip_proxy = _is_affirmative(
        instance.get('skip_proxy', instance.get('no_proxy', False)))
    allow_redirects = _is_affirmative(instance.get('allow_redirects', True))

    return Config(url, ntlm_domain, username, password, client_cert,
                  client_key, method, data, http_response_status_code, timeout,
                  include_content, headers, response_time, content_match,
                  reverse_content_match, tags, disable_ssl_validation,
                  ssl_expire, instance_ca_certs, weakcipher, check_hostname,
                  ignore_ssl_warning, skip_proxy, allow_redirects)
示例#3
0
def from_instance(instance):
    """
    Create a config object from an instance dictionary
    """
    url = instance.get('url')
    if not url:
        raise ConfigurationError("A URL must be specified in the instance")

    pshard_stats = _is_affirmative(instance.get('pshard_stats', False))
    pshard_graceful_to = _is_affirmative(
        instance.get('pshard_graceful_timeout', False))
    index_stats = _is_affirmative(instance.get('index_stats', False))
    cluster_stats = _is_affirmative(instance.get('cluster_stats', False))
    if 'is_external' in instance:
        cluster_stats = _is_affirmative(instance.get('is_external', False))
    pending_task_stats = _is_affirmative(
        instance.get('pending_task_stats', True))
    admin_forwarder = _is_affirmative(instance.get('admin_forwarder', False))

    # Support URLs that have a path in them from the config, for
    # backwards-compatibility.
    parsed = urlparse.urlparse(url)
    if parsed[2] and not admin_forwarder:
        url = '{}://{}'.format(parsed[0], parsed[1])
    port = parsed.port
    host = parsed.hostname

    custom_tags = instance.get('tags', [])
    service_check_tags = [
        'host:{}'.format(host),
        'port:{}'.format(port),
    ]
    service_check_tags.extend(custom_tags)

    # Tag by URL so we can differentiate the metrics
    # from multiple instances
    tags = ['url:{}'.format(url)]
    tags.extend(custom_tags)

    timeout = instance.get('timeout') or DEFAULT_TIMEOUT

    config = ESInstanceConfig(admin_forwarder=admin_forwarder,
                              pshard_stats=pshard_stats,
                              pshard_graceful_to=pshard_graceful_to,
                              cluster_stats=cluster_stats,
                              index_stats=index_stats,
                              password=instance.get('password'),
                              service_check_tags=service_check_tags,
                              health_tags=[],
                              ssl_cert=instance.get('ssl_cert'),
                              ssl_key=instance.get('ssl_key'),
                              ssl_verify=instance.get('ssl_verify'),
                              tags=tags,
                              timeout=timeout,
                              url=url,
                              username=instance.get('username'),
                              pending_task_stats=pending_task_stats)
    return config
示例#4
0
 def __init__(self, *args, **kwargs):
     super(YarnCheck, self).__init__(*args, **kwargs)
     application_status_mapping = self.instance.get(
         'application_status_mapping', DEFAULT_APPLICATION_STATUS_MAPPING)
     try:
         self.application_status_mapping = {
             k.upper(): getattr(AgentCheck, v.upper())
             for k, v in application_status_mapping.items()
         }
     except AttributeError as e:
         raise ConfigurationError("Invalid mapping: {}".format(e))
示例#5
0
    def check(self, instance):
        if 'url' not in instance:
            raise ConfigurationError('Mesos instance missing "url" value.')

        url = instance['url']
        tags = list(instance.get('tags', []))
        tasks = instance.get('tasks', [])
        master_port = instance.get("master_port", DEFAULT_MASTER_PORT)

        self._process_state_info(url, tasks, master_port, tags)
        self._process_stats_info(url, tags)
示例#6
0
    def get_channel_status_mapping(channel_status_mapping_raw):
        if channel_status_mapping_raw:
            custom_mapping = {}
            for ibm_mq_status_raw, service_check_status_raw in channel_status_mapping_raw.items(
            ):
                ibm_mq_status_attr = 'MQCHS_{}'.format(
                    ibm_mq_status_raw).upper()
                service_check_status_attr = service_check_status_raw.upper()

                if service_check_status_attr not in ServiceCheck._fields:
                    raise ConfigurationError(
                        "Invalid service check status: {}".format(
                            service_check_status_raw))

                try:
                    custom_mapping[getattr(pymqi.CMQCFC,
                                           ibm_mq_status_attr)] = getattr(
                                               AgentCheck,
                                               service_check_status_attr)
                except AttributeError as e:
                    raise ConfigurationError("Invalid mapping: {}".format(e))
            return custom_mapping
        else:
            return DEFAULT_CHANNEL_STATUS_MAPPING
示例#7
0
    def check(self, instance):
        if 'url' not in instance:
            raise ConfigurationError('Mesos instance missing "url" value.')

        url = instance['url']
        tags = instance.get('tags', [])
        tasks = instance.get('tasks', [])
        master_port = instance.get("master_port", DEFAULT_MASTER_PORT)

        try:
            self._process_state_info(url, tasks, master_port, tags)
            self._process_stats_info(url, tags)
        except CheckException as e:
            self.log.error("Error running check mesos_slave with exception %s",
                           e)
            raise
示例#8
0
 def check_properly_configured(self):
     if not self.channel or not self.queue_manager_name or not self.host or not self.port:
         msg = "channel, queue_manager, host and port are all required configurations"
         raise ConfigurationError(msg)
示例#9
0
    def __init__(self, instance):
        self.channel = instance.get('channel')  # type: str
        self.queue_manager_name = instance.get('queue_manager',
                                               'default')  # type: str

        if not self.channel or not self.queue_manager_name:
            msg = "channel, queue_manager are required configurations"
            raise ConfigurationError(msg)

        host = instance.get('host')  # type: str
        port = instance.get('port')  # type: str
        self.connection_name = instance.get('connection_name')  # type: str
        if (host or port) and self.connection_name:
            raise ConfigurationError(
                'Specify only one host/port or connection_name configuration, '
                '(host={}, port={}, connection_name={}).'.format(
                    host, port, self.connection_name))

        if not self.connection_name:
            host = host or 'localhost'
            port = port or '1414'
            self.connection_name = "{}({})".format(host, port)

        self.username = instance.get('username')  # type: str
        self.password = instance.get('password')  # type: str

        self.queues = instance.get('queues', [])  # type: List[str]
        self.queue_patterns = instance.get('queue_patterns',
                                           [])  # type: List[str]
        self.queue_regex = [
            re.compile(regex) for regex in instance.get('queue_regex', [])
        ]  # type: List[Pattern]

        self.auto_discover_queues = is_affirmative(
            instance.get('auto_discover_queues', False))  # type: bool

        if int(self.auto_discover_queues) + int(bool(
                self.queue_patterns)) + int(bool(self.queue_regex)) > 1:
            log.warning(
                "Configurations auto_discover_queues, queue_patterns and queue_regex are not intended to be used "
                "together.")

        self.channels = instance.get('channels', [])  # type: List[str]

        self.channel_status_mapping = self.get_channel_status_mapping(
            instance.get('channel_status_mapping'))  # type: Dict[str, str]

        custom_tags = instance.get('tags', [])  # type: List[str]
        tags = [
            "queue_manager:{}".format(self.queue_manager_name),
            "connection_name:{}".format(self.connection_name),
        ]  # type: List[str]
        tags.extend(custom_tags)
        if host or port:
            # 'host' is reserved and 'mq_host' is used instead
            tags.extend({"mq_host:{}".format(host), "port:{}".format(port)})
        self.tags_no_channel = tags
        self.tags = tags + ["channel:{}".format(self.channel)
                            ]  # type: List[str]

        self.ssl = is_affirmative(instance.get('ssl_auth',
                                               False))  # type: bool
        self.ssl_cipher_spec = instance.get(
            'ssl_cipher_spec', 'TLS_RSA_WITH_AES_256_CBC_SHA')  # type: str

        self.ssl_key_repository_location = instance.get(
            'ssl_key_repository_location',
            '/var/mqm/ssl-db/client/KeyringClient')  # type: str

        self.mq_installation_dir = instance.get('mq_installation_dir',
                                                '/opt/mqm/')

        self._queue_tag_re = instance.get('queue_tag_re',
                                          {})  # type: Dict[str, str]
        self.queue_tag_re = self._compile_tag_re()

        raw_mqcd_version = instance.get('mqcd_version', 6)
        try:
            self.mqcd_version = getattr(
                pymqi.CMQC,
                'MQCD_VERSION_{}'.format(raw_mqcd_version))  # type: int
        except (ValueError, AttributeError):
            raise ConfigurationError(
                "mqcd_version must be a number between 1 and 9. {} found.".
                format(raw_mqcd_version))