Пример #1
0
int SyslogClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) {
	const ::Plugin::Common_Header& request_header = request_message.header();
	connection_data con = parse_header(request_header, data);

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

	//TODO: Map seveity!

	std::list<std::string> messages;
	for (int i=0;i < request_message.payload_size(); ++i) {
		const ::Plugin::QueryResponseMessage::Response& payload = request_message.payload(i);
		std::string date = "Nov 10 00:12:00"; // TODO is this actually used?
		std::string tag = con.tag_syntax;
		std::string message = con.message_syntax;
		strEx::replace(message, "%message%", payload.message());
		strEx::replace(tag, "%message%", payload.message());

		std::string severity = con.severity;
		if (payload.result() == ::Plugin::Common_ResultCode_OK)
			severity = con.ok_severity;
		if (payload.result() == ::Plugin::Common_ResultCode_WARNING)
			severity = con.warn_severity;
		if (payload.result() == ::Plugin::Common_ResultCode_CRITCAL)
			severity = con.crit_severity;
		if (payload.result() == ::Plugin::Common_ResultCode_UNKNOWN)
			severity = con.unknown_severity;

		messages.push_back(instance->parse_priority(severity, con.facility) + date + " " + tag + " " + message);
	}
	boost::tuple<int,std::wstring> ret = instance->send(con, messages);
	nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "UNKNOWN", ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()));
	response_message.SerializeToString(&reply);
	return NSCAPI::isSuccess;
}
Пример #2
0
		bool submit(client::destination_container sender, client::destination_container target, const Plugin::SubmitRequestMessage &request_message, Plugin::SubmitResponseMessage &response_message) {
			const ::Plugin::Common_Header& request_header = request_message.header();
			nscapi::protobuf::functions::make_return_header(response_message.mutable_header(), request_header);
			connection_data con(target, sender);

			std::list<collectd::packet> list;
			for (int i = 0; i < request_message.payload_size(); ++i) {
				collectd::packet packet;
				//packet.add_string(0, "Hello WOrld");
				list.push_back(packet);
			}

			send(response_message.add_payload(), con, list);
			return true;
		}
Пример #3
0
int NRDPClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, Plugin::SubmitResponseMessage &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) {
		std::string alias, msg, perf;
		NSCAPI::nagiosReturn result = nscapi::protobuf::functions::parse_simple_submit_request_payload(request_message.payload(i), alias, msg, perf);
		if (alias == "host_check")
			nrdp_data.add_host(con.sender_hostname, result, msg, perf);
		else
			nrdp_data.add_service(con.sender_hostname, alias, result, msg, perf);
	}

	boost::tuple<int,std::string> ret = send(con, nrdp_data);
	nscapi::protobuf::functions::append_simple_submit_response_payload(response_message.add_payload(), "TODO", ret.get<0>(), ret.get<1>());
	return NSCAPI::isSuccess;
}
Пример #4
0
int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, Plugin::SubmitResponseMessage &response_message) {
	const ::Plugin::Common_Header& request_header = request_message.header();
	connection_data con = parse_header(request_header, data);
	std::wstring channel = utf8::cvt<std::wstring>(request_message.channel());

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

	for (int i=0;i < request_message.payload_size(); ++i) {
		const ::Plugin::QueryResponseMessage::Response& payload = request_message.payload(i);
		boost::asio::io_service io_service;
		boost::shared_ptr<smtp::client::smtp_client> client(new smtp::client::smtp_client(io_service));
		std::list<std::string> recipients;
		std::string message = con.template_string;
		strEx::replace(message, "%message%", payload.message());
		recipients.push_back(con.recipient_str);
		client->send_mail(con.sender, recipients, "Hello world\n");
		io_service.run();
		nscapi::protobuf::functions::append_simple_submit_response_payload(response_message.add_payload(), "TODO", NSCAPI::returnOK, "Message send successfully");
	}
	return NSCAPI::isSuccess;

}