示例#1
0
    def _get_command_line_and_stdin(self):
        # type: () -> Tuple[str, Optional[str]]
        """Create command line using the special_agent_info"""
        info_func = config.special_agent_info[self._special_agent_id]
        agent_configuration = info_func(self._params, self._hostname,
                                        self._ipaddress)
        if isinstance(agent_configuration, SpecialAgentConfiguration):
            cmd_arguments = agent_configuration.args
            command_stdin = agent_configuration.stdin
        else:
            cmd_arguments = agent_configuration
            command_stdin = None

        final_arguments = config.prepare_check_command(cmd_arguments,
                                                       self._hostname,
                                                       description=None)

        agent_name = "agent_" + self._special_agent_id
        special_agent_path = Path(cmk.utils.paths.agents_dir, "special",
                                  agent_name)
        local_special_agent_path = cmk.utils.paths.local_agents_dir / "special" / agent_name

        path = local_special_agent_path if local_special_agent_path.exists(
        ) else special_agent_path
        return "%s %s" % (path, final_arguments), command_stdin
示例#2
0
def active_check_arguments(hostname, description, args):
    if not isinstance(args,
                      (six.binary_type, six.text_type,
                       list)):  # TODO: Check if six.binary_type is necessary
        raise MKGeneralException(
            "The check argument function needs to return either a list of arguments or a "
            "string of the concatenated arguments (Host: %s, Service: %s)." %
            (hostname, description))

    return config.prepare_check_command(args, hostname, description)
示例#3
0
    def _source_args(self):
        # type: () -> str
        info_func = config.special_agent_info[self._special_agent_id]
        agent_configuration = info_func(self._params, self._hostname,
                                        self._ipaddress)
        if isinstance(agent_configuration, SpecialAgentConfiguration):
            cmd_arguments = agent_configuration.args
        else:
            cmd_arguments = agent_configuration

        return config.prepare_check_command(cmd_arguments,
                                            self._hostname,
                                            description=None)
示例#4
0
def active_check_arguments(hostname, description, args):
    # type: (HostName, ServiceName, Union[str, List[str]]) -> str
    if isinstance(args, str):
        cmd_args = args  # type: Union[str, List[Union[int, float, str, Tuple[Any, Any, Any]]]]
    elif isinstance(args, list):
        cmd_args = [arg for arg in args if isinstance(arg, str)]
    else:
        raise MKGeneralException(
            "The check argument function needs to return either a list of arguments or a "
            "string of the concatenated arguments (Host: %s, Service: %s)." %
            (hostname, description))

    return config.prepare_check_command(cmd_args, hostname, description)
示例#5
0
    def _source_args(self):
        # type: () -> str
        info_func = config.special_agent_info[self._special_agent_id]
        agent_configuration = info_func(self._params, self._hostname,
                                        self._ipaddress)
        if isinstance(agent_configuration, SpecialAgentConfiguration):
            cmd_arguments = agent_configuration.args  # type: Union[str, List[Union[int, float, str, Tuple[Any, Any, Any]]]]
        elif isinstance(agent_configuration, str):
            cmd_arguments = agent_configuration
        elif isinstance(agent_configuration, list):
            cmd_arguments = [
                arg for arg in agent_configuration if isinstance(arg, str)
            ]
        else:
            raise Exception("invalid agent configuration %r" %
                            (agent_configuration, ))

        return config.prepare_check_command(cmd_arguments,
                                            self._hostname,
                                            description=None)
示例#6
0
def active_check_arguments(hostname, description, args):
    # type: (HostName, Optional[ServiceName], config.SpecialAgentInfoFunctionResult) -> str
    if isinstance(args, config.SpecialAgentConfiguration):
        # TODO: Silly dispatching because of broken types/variance.
        if isinstance(args.args, str):
            cmd_args = args.args  # type: Union[str, List[Union[int, float, str, Tuple[str, str, str]]]]
        elif isinstance(args.args, list):
            cmd_args = [arg for arg in args.args if isinstance(arg, str)]
        else:
            raise Exception("funny SpecialAgentConfiguration args %r" % (args.args,))
    elif isinstance(args, str):
        cmd_args = args
    elif isinstance(args, list):
        cmd_args = [arg for arg in args if isinstance(arg, (str, tuple))]
    else:
        raise MKGeneralException(
            "The check argument function needs to return either a list of arguments or a "
            "string of the concatenated arguments (Host: %s, Service: %s)." %
            (hostname, description))

    return config.prepare_check_command(cmd_args, hostname, description)