コード例 #1
0
def test_prepare_check_command_basics():
    assert config.prepare_check_command(u"args 123 -x 1 -y 2", "bla", "blub") \
        == u"args 123 -x 1 -y 2"

    assert config.prepare_check_command(["args", "123", "-x", "1", "-y", "2"], "bla", "blub") \
        == "'args' '123' '-x' '1' '-y' '2'"

    assert config.prepare_check_command(["args", "1 2 3", "-d=2", "--hallo=eins", 9], "bla", "blub") \
        == "'args' '1 2 3' '-d=2' '--hallo=eins' 9"

    with pytest.raises(NotImplementedError):
        config.prepare_check_command((1, 2), "bla", "blub")
コード例 #2
0
ファイル: programs.py プロジェクト: m4c3/checkMK
    def _get_command_line_and_stdin(self):
        """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)

        special_agents_dir = cmk.utils.paths.agents_dir + "/special"
        local_special_agents_dir = cmk.utils.paths.local_agents_dir + "/special"

        if os.path.exists(local_special_agents_dir + "/agent_" +
                          self._special_agent_id):
            path = local_special_agents_dir + "/agent_" + self._special_agent_id
        else:
            path = special_agents_dir + "/agent_" + self._special_agent_id

        return path + " " + final_arguments, command_stdin
コード例 #3
0
ファイル: programs.py プロジェクト: st0ne-dot-at/checkmk
    def _get_command_line_and_stdin(self):
        """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.joinpath(
            "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
コード例 #4
0
def active_check_arguments(hostname, description, args):
    if not isinstance(args, (str, unicode, list)):
        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)
コード例 #5
0
ファイル: core_config.py プロジェクト: st0ne-dot-at/checkmk
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)
コード例 #6
0
def test_prepare_check_command_not_existing_password(capsys):
    assert config.prepare_check_command(["arg1", ("store", "pw-id", "--password=%s"), "arg3"], "bla", "blub") \
        == "--pwstore=2@11@pw-id 'arg1' '--password=***' 'arg3'"
    stderr = capsys.readouterr().err
    assert "The stored password \"pw-id\" used by service \"blub\" on host \"bla\"" in stderr
コード例 #7
0
def test_prepare_check_command_password_store(monkeypatch, pw):
    monkeypatch.setattr(config, "stored_passwords", {"pw-id": {"password": pw,}})
    assert config.prepare_check_command(["arg1", ("store", "pw-id", "--password=%s"), "arg3"], "bla", "blub") \
        == "--pwstore=2@11@pw-id 'arg1' '--password=%s' 'arg3'" % ("*" * len(pw))