Ejemplo n.º 1
0
def get_port(port_or_port_re, process_name):
    """Given the regular expression, extract port from the process name.

    :param str port_or_port_re: whether integer port or port regular expression.
    :param str process_name: process name.

    :rtype: int|None
    """

    if isinstance(port_or_port_re, int):
        return port_or_port_re

    try:
        return int(port_or_port_re)
    except ValueError:
        pass

    match = re.match(port_or_port_re, process_name)

    if match:
        try:
            groups = match.groups()
            if len(groups) == 1:
                return int(groups[0])
        except (ValueError, TypeError) as err:
            raise errors.InvalidCheckConfig(err)

    raise errors.InvalidCheckConfig(
        'Could not extract port number for process name %s using regular '
        'expression %s' % (process_name, port_or_port_re))
Ejemplo n.º 2
0
    def _validate_config(self):

        if 'max_cpu' not in self._config:
            raise errors.InvalidCheckConfig(
                'Required `max_cpu` parameter is missing in %s check config.'
                % (self.NAME,))

        if not isinstance(self._config['max_cpu'], (int, float)):
            raise errors.InvalidCheckConfig(
                '`max_cpu` parameter must be numeric type in %s check config.'
                % (self.NAME,))
Ejemplo n.º 3
0
    def _validate_config(self):

        if 'url' not in self._config:
            raise errors.InvalidCheckConfig(
                'Required `url` parameter is missing in %s check config.' % (
                    self.NAME,))

        if not isinstance(self._config['url'], str):
            raise errors.InvalidCheckConfig(
                '`url` parameter must be string type in %s check config.' % (
                    self.NAME,))

        if 'port' not in self._config:
            raise errors.InvalidCheckConfig(
                'Required `port` parameter is missing in %s check config.' % (
                    self.NAME,))
Ejemplo n.º 4
0
    def _validate_config(self):

        one_of_required = {'url', 'sock_path', 'sock_dir'}

        param_intersection = one_of_required.intersection(self._config)
        if not param_intersection:
            raise errors.InvalidCheckConfig(
                'One of required parameters: `url`, `sock_path` or `sock_dir` '
                'is missing in %s check config.' % (self.NAME, ))

        if len(param_intersection) > 1:
            raise errors.InvalidCheckConfig(
                '`url`, `sock_path` and `sock_dir` must be mutually exclusive'
                'in %s check config.' % (self.NAME, ))

        if 'url' in self._config and 'port' not in self._config:
            raise errors.InvalidCheckConfig(
                'When `url` parameter is specified, `port` parameter is '
                'required in %s check config.' % (self.NAME, ))
Ejemplo n.º 5
0
    def _validate_config(self):

        if 'port' not in self._config:
            raise errors.InvalidCheckConfig(
                'Required `port` parameter is missing in %s check config.' %
                (self.NAME, ))