Esempio n. 1
0
int DistributedClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) {
	const ::Plugin::Common_Header& request_header = request_message.header();
	int ret = NSCAPI::returnOK;
	connection_data con = parse_header(request_header, data);

	Plugin::ExecuteResponseMessage response_message;
	nscapi::functions::make_return_header(response_message.mutable_header(), request_header);

	std::list<nscp::packet> chunks;
	chunks.push_back(nscp::factory::create_envelope_request(1));
	chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request_message.SerializeAsString(), 0));
	chunks = instance->send(con, chunks);
	BOOST_FOREACH(nscp::packet &chunk, chunks) {
		if (nscp::checks::is_exec_response(chunk)) {
			nscapi::functions::append_response_payloads(response_message, chunk.payload);
		} else if (nscp::checks::is_error(chunk)) {
			std::string error = gather_and_log_errors(chunk.payload);
			nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
			ret = NSCAPI::returnUNKNOWN;
		} else {
			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
			nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
			ret = NSCAPI::returnUNKNOWN;
		}
	}
	response_message.SerializeToString(&reply);
	return ret;
}
Esempio n. 2
0
int NSCPClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, Plugin::ExecuteResponseMessage &response_message) {
	const ::Plugin::Common_Header& request_header = request_message.header();
	connection_data con = parse_header(request_header, data);

	std::string tmp;
	int ret = send(con, NSCPIPC::Common_MessageTypes_EXEC_REQUEST, request_message.SerializeAsString(), tmp);
	response_message.ParseFromString(tmp);
	return ret;
}
Esempio n. 3
0
NSCAPI::nagiosReturn SyslogClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
	std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix);

	Plugin::ExecuteRequestMessage message;
	message.ParseFromString(request);

	client::configuration config;
	setup(config, message.header());

	return commands.process_exec(cmd, config, message, result);
}
Esempio n. 4
0
int NRDPClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, Plugin::ExecuteResponseMessage &response_message) {
	const ::Plugin::Common_Header& request_header = request_message.header();
	connection_data con = parse_header(request_header, data);

	nscapi::protobuf::functions::make_return_header(response_message.mutable_header(), request_header);

	nrdp::data nrdp_data;
	for (int i=0;i < request_message.payload_size(); ++i) {
		nscapi::protobuf::functions::decoded_simple_command_data data = nscapi::protobuf::functions::parse_simple_exec_request_payload(request_message.payload(i));
		//nrdp_data.add_command(data.command, data.args);
	}
	boost::tuple<int,std::string> ret = send(con, nrdp_data);
	nscapi::protobuf::functions::append_simple_exec_response_payload(response_message.add_payload(), "TODO", ret.get<0>(), ret.get<1>());
	return NSCAPI::isSuccess;
}
Esempio n. 5
0
bool NRPEClient::commandLineExec(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response, const Plugin::ExecuteRequestMessage &request_message) {
	client::configuration config(nrpe_client::command_prefix, 
		boost::shared_ptr<nrpe_client::clp_handler_impl>(new nrpe_client::clp_handler_impl(boost::shared_ptr<socket_helpers::client::client_handler>(new client_handler()))), 
		boost::shared_ptr<nrpe_client::target_handler>(new nrpe_client::target_handler(targets)));
	nrpe_client::setup(config, request_message.header());
	return commands.parse_exec(nrpe_client::command_prefix, nrpe_client::default_command, request.command(), config, request, *response, request_message);
}
Esempio n. 6
0
bool NSCPClient::commandLineExec(const int target_mode, const Plugin::ExecuteRequestMessage &request, Plugin::ExecuteResponseMessage &response) {
	BOOST_FOREACH(const Plugin::ExecuteRequestMessage::Request &payload, request.payload()) {
		if (payload.arguments_size() == 0 || payload.arguments(0) == "help") {
			Plugin::ExecuteResponseMessage::Response *rp = response.add_payload();
			nscapi::protobuf::functions::set_response_bad(*rp, "Usage: nscp nscp --help");
			return true;
		}
	}
	if (target_mode == NSCAPI::target_module)
		return client_.do_exec(request, response, "check_nscp");
	return false;
}
Esempio n. 7
0
void lua::lua_runtime::on_exec(std::string command, script_information *information, lua::lua_traits::function_type function, bool simple, const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response, const Plugin::ExecuteRequestMessage &request_message)
{
	lua_wrapper lua(prep_function(information, function));
	int args = 2;
	if (function.object_ref != 0)
		args = 3;
	if (simple) {
		std::list<std::string> argslist;
		for (int i=0;i<request.arguments_size();i++)
			argslist.push_back(request.arguments(i));
		lua.push_string(command);
		lua.push_array(argslist);
		if (lua.pcall(args, 3, 0) != 0)
			return nscapi::protobuf::functions::set_response_bad(*response, "Failed to handle command: " + command + ": " + lua.pop_string());
		NSCAPI::nagiosReturn ret = NSCAPI::returnUNKNOWN;
		if (lua.size() < 3) {
			NSC_LOG_ERROR_STD("Invalid return: " + lua.dump_stack());
			nscapi::protobuf::functions::append_simple_exec_response_payload(response, command, NSCAPI::returnUNKNOWN, "Invalid return");
			return;
		}
		std::string msg, perf;
		msg = lua.pop_string();
		ret = lua.pop_code();
		lua.gc(LUA_GCCOLLECT, 0);
		nscapi::protobuf::functions::append_simple_exec_response_payload(response, command, ret, msg);
	} else {
		lua.push_string(command);
		lua.push_raw_string(request.SerializeAsString());
		lua.push_raw_string(request_message.SerializeAsString());
		args++;
		if (lua.pcall(args, 1, 0) != 0)
			return nscapi::protobuf::functions::set_response_bad(*response, "Failed to handle command: " + command + ": " + lua.pop_string());
		if (lua.size() < 1) {
			NSC_LOG_ERROR_STD("Invalid return: " + lua.dump_stack());
			nscapi::protobuf::functions::append_simple_exec_response_payload(response, command, NSCAPI::returnUNKNOWN, "Invalid return data");
			return;
		}
		Plugin::QueryResponseMessage local_response;
		std::string data = lua.pop_raw_string();
		response->ParseFromString(data);
		lua.gc(LUA_GCCOLLECT, 0);
	}
}
Esempio n. 8
0
bool CheckMKClient::commandLineExec(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response, const Plugin::ExecuteRequestMessage &request_message) {
	client::configuration config(command_prefix, boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this)), boost::shared_ptr<target_handler>(new target_handler(targets)));
	setup(config, request_message.header());
	return commands.parse_exec(command_prefix, default_command, request.command(), config, request, *response, request_message);
}
Esempio n. 9
0
bool SMTPClient::commandLineExec(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response, const Plugin::ExecuteRequestMessage &request_message) {
	client::configuration config(command_prefix);
	setup(config, request_message.header());
	return commands.parse_exec(command_prefix, default_command, request.command(), config, request, *response, request_message);
}