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")
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
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
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)
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)
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
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))