コード例 #1
0
void CheckMKClient::send(connection_data con) {
	try {
		NSC_DEBUG_MSG_STD("Connection details: " + con.to_string());
		if (con.ssl.enabled) {
#ifndef USE_SSL
			NSC_LOG_ERROR_STD(_T("SSL not avalible (compiled without USE_SSL)"));
			return response;
#endif
		}
		socket_helpers::client::client<check_mk::client::protocol> client(con, boost::shared_ptr<client_handler>(new client_handler()));
		client.connect();
		std::string dummy;
		check_mk::packet packet = client.process_request(dummy);
		boost::optional<scripts::command_definition<lua::lua_traits> > cmd = scripts_->find_command("check_mk", "c_callback");
		if (cmd) {
			parse_data(cmd->information, cmd->function, packet);
		} else {
			NSC_LOG_ERROR_STD("No check_mk callback found!");
		}
		//lua_runtime_->on_query()
		client.shutdown();
	} catch (std::runtime_error &e) {
		NSC_LOG_ERROR_EXR("Failed to send", e);
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("Failed to send", e);
	} catch (...) {
		NSC_LOG_ERROR_EX("Failed to send");
	}
}
コード例 #2
0
ファイル: collectd_client.hpp プロジェクト: mickem/nscp
		void send(const connection_data target, const collectd::collectd_builder::packet_list &packets) {
			NSC_DEBUG_MSG("Sending " + str::xtos(packets.size()) + " packets to: " + target.to_string());
			BOOST_FOREACH(const collectd::packet &p, packets) {
				try {
					boost::asio::io_service io_service;

					boost::asio::ip::address target_address = boost::asio::ip::address::from_string(target.get_address());

					boost::asio::ip::udp::resolver resolver(io_service);
					boost::asio::ip::udp::resolver::query query(boost::asio::ip::host_name(), "");
					boost::asio::ip::udp::resolver::iterator endpoint_iterator = resolver.resolve(query);
					boost::asio::ip::udp::resolver::iterator end;
					bool is_multicast = false;
					if (target_address.is_v4()) {
						is_multicast = target_address.to_v4().is_multicast();
					}
#if BOOST_VERSION >= 105300
					else if (target_address.is_v6()) {
						is_multicast = target_address.to_v6().is_multicast();
					}
#endif

					if (is_multicast) {
						while (endpoint_iterator != end) {
							std::string ss = endpoint_iterator->endpoint().address().to_string();
							if (target_address.is_v4() && endpoint_iterator->endpoint().address().is_v4()) {
								std::cout << endpoint_iterator->endpoint().address().to_string() << std::endl;
								udp_sender s(io_service, endpoint_iterator->endpoint(), target_address, target.get_int_port());
								s.send_data(p.get_buffer());
								io_service.run();
							}
							endpoint_iterator++;
						}
					} else {
						udp_sender s(io_service, target_address, target.get_int_port());
						s.send_data(p.get_buffer());
						io_service.run();

					}


				} catch (std::exception& e) {
					NSC_LOG_ERROR_STD(utf8::utf8_from_native(e.what()));
				}
			}
		}
コード例 #3
0
ファイル: NRDPClient.cpp プロジェクト: TaylorMonacelli/nscp
boost::tuple<int,std::string> NRDPClient::clp_handler_impl::send(connection_data data, const nrdp::data &nrdp_data) {
	try {
		NSC_DEBUG_MSG_STD("Connection details: " + data.to_string());
		http::client c;
		http::client::request_type request;
		request.add_default_headers();
		http::client::request_type::post_map_type post;
		post["token"] = data.token;
		post["XMLDATA"] = nrdp_data.render_request();
		post["cmd"] = "submitcheck";
		request.add_post_payload(post);
		NSC_DEBUG_MSG_STD(nrdp_data.render_request());
		NSC_DEBUG_MSG_STD(request.payload);
		http::client::response_type response = c.execute(data.host, data.port, "/nrdp/server/", request);
		NSC_DEBUG_MSG_STD(response.payload);
		return boost::make_tuple(NSCAPI::returnUNKNOWN, "");
	} catch (const std::exception &e) {
		return boost::make_tuple(NSCAPI::returnUNKNOWN, "Error: " + utf8::utf8_from_native(e.what()));
	} catch (...) {
		return boost::make_tuple(NSCAPI::returnUNKNOWN, "Unknown error -- REPORT THIS!");
	}
}