- Timestamp:
- 08/24/11 18:37:39 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- d7e265d
- Parents:
- 0b8df3e
- Location:
- modules
- Files:
-
- 6 edited
-
CheckExternalScripts/CheckExternalScripts.cpp (modified) (3 diffs)
-
NSCPClient/NSCPClient.cpp (modified) (4 diffs)
-
NSCPClient/NSCPClient.h (modified) (1 diff)
-
NSCPServer/handler_impl.cpp (modified) (2 diffs)
-
NSCPServer/handler_impl.hpp (modified) (1 diff)
-
PythonScript/PythonScript.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
modules/CheckExternalScripts/CheckExternalScripts.cpp
r2c95d22 rb38e845 138 138 139 139 NSCAPI::nagiosReturn CheckExternalScripts::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response) { 140 nscapi::functions::decoded_simple_command_data data = nscapi::functions::p rocess_simple_command_request(char_command, request);140 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 141 141 142 142 command_list::const_iterator cit = commands.find(data.command); … … 158 158 if (first && !isAlias && !allowNasty_) { 159 159 if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 160 return nscapi::functions::process_simple_command_result(data.command, NSCAPI::returnUNKNOWN, _T("Request contained illegal characters!"), _T(""), response); 160 return nscapi::functions::create_simple_query_response_unknown(_T("Request contained illegal characters!"), _T(""), response, data.command); 161 161 162 } 162 163 } … … 190 191 int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + xargs, timeout), message, perf); 191 192 if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 192 return nscapi::functions::process_simple_command_result(data.command, NSCAPI::returnUNKNOWN, _T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result), _T(""), response); 193 } 194 return nscapi::functions::process_simple_command_result(data.command, nscapi::plugin_helper::int2nagios(result), message, perf, response); 193 nscapi::functions::create_simple_query_response(NSCAPI::returnUNKNOWN, _T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result), _T(""), response, data.command); 194 return NSCAPI::returnUNKNOWN; 195 } 196 nscapi::functions::create_simple_query_response(nscapi::plugin_helper::int2nagios(result), message, perf, response, data.command); 197 return result; 195 198 } 196 199 } -
modules/NSCPClient/NSCPClient.cpp
r4632ff7 rb38e845 240 240 NSCPClient::nscp_result_data NSCPClient::execute_nscp_command(nscp_connection_data con, std::string buffer) { 241 241 try { 242 std::list<nscp::packet ::nscp_chunk> chunks;242 std::list<nscp::packet> chunks; 243 243 chunks.push_back(nscp::packet::build_envelope_request(1)); 244 chunks.push_back(nscp::packet:: build_payload(nscp::data::command_request, buffer, 0));244 chunks.push_back(nscp::packet::create_payload(nscp::data::command_request, buffer, 0)); 245 245 if (!con.no_ssl) { 246 246 #ifdef USE_SSL … … 253 253 chunks = send_nossl(con.host, con.port, con.timeout, chunks); 254 254 } 255 BOOST_FOREACH(nscp::packet ::nscp_chunk&chunk, chunks) {255 BOOST_FOREACH(nscp::packet &chunk, chunks) { 256 256 NSC_DEBUG_MSG_STD(_T("Found chunk: ") + utf8::cvt<std::wstring>(strEx::format_buffer(chunk.payload.c_str(), chunk.payload.size()))); 257 257 } 258 258 return nscp_result_data(NSCAPI::returnUNKNOWN, _T("Hello")); 259 259 } catch (nscp::nscp_exception &e) { 260 NSC_LOG_ERROR_STD(_T("Socket error: ") + e.getMessage());261 return nscp_result_data(NSCAPI::returnUNKNOWN, _T(" NSCP Packet error: ") + e.getMessage());260 NSC_LOG_ERROR_STD(_T("Socket error: ") + utf8::cvt<std::wstring>(e.what())); 261 return nscp_result_data(NSCAPI::returnUNKNOWN, _T("Socket error: ") + utf8::cvt<std::wstring>(e.what())); 262 262 } catch (std::runtime_error &e) { 263 263 NSC_LOG_ERROR_STD(_T("Socket error: ") + utf8::cvt<std::wstring>(e.what())); … … 274 274 275 275 #ifdef USE_SSL 276 std::list<nscp::packet ::nscp_chunk> NSCPClient::send_ssl(std::wstring host, int port, int timeout, std::list<nscp::packet::nscp_chunk> &chunks) {276 std::list<nscp::packet> NSCPClient::send_ssl(std::wstring host, int port, int timeout, std::list<nscp::packet> &chunks) { 277 277 boost::asio::io_service io_service; 278 278 boost::asio::ssl::context ctx(io_service, boost::asio::ssl::context::sslv23); … … 286 286 #endif 287 287 288 std::list<nscp::packet ::nscp_chunk> NSCPClient::send_nossl(std::wstring host, int port, int timeout, std::list<nscp::packet::nscp_chunk> &chunks) {288 std::list<nscp::packet> NSCPClient::send_nossl(std::wstring host, int port, int timeout, std::list<nscp::packet> &chunks) { 289 289 boost::asio::io_service io_service; 290 290 nscp::client::socket socket(io_service, host, port); -
modules/NSCPClient/NSCPClient.h
r438998b rb38e845 105 105 private: 106 106 nscp_result_data execute_nscp_command(nscp_connection_data con, std::string buffer); 107 std::list<nscp::packet ::nscp_chunk> send_nossl(std::wstring host, int port, int timeout, std::list<nscp::packet::nscp_chunk> &chunks);108 std::list<nscp::packet ::nscp_chunk> send_ssl(std::wstring host, int port, int timeout, std::list<nscp::packet::nscp_chunk> &chunks);107 std::list<nscp::packet> send_nossl(std::wstring host, int port, int timeout, std::list<nscp::packet> &chunks); 108 std::list<nscp::packet> send_ssl(std::wstring host, int port, int timeout, std::list<nscp::packet> &chunks); 109 109 void add_options(po::options_description &desc, nscp_connection_data &command_data); 110 110 -
modules/NSCPServer/handler_impl.cpp
r438998b rb38e845 7 7 #include "handler_impl.hpp" 8 8 9 std::string handler_impl::process(std::string &buffer) { 10 std::string ret; 11 PluginCommand::RequestMessage msg; 12 msg.ParseFromString(buffer); 13 if (msg.payload_size() != 1) { 14 NSC_LOG_ERROR(_T("Multiple payloads not currently supported...")); 15 nscapi::functions::create_simple_query_result(NSCAPI::returnUNKNOWN, _T("Multiple payloads not currently supported..."), _T(""), ret); 16 return ret; 17 } 18 std::wstring command = utf8::cvt<std::wstring>(msg.payload(0).command()); 19 if (command.empty() || command == _T("_NSCP_CHECK")) { 20 nscapi::functions::create_simple_query_result(NSCAPI::returnOK, _T("I (") + nscapi::plugin_singleton->get_core()->getApplicationVersionString() + _T(") seem to be doing fine..."), _T(""), ret); 21 return ret; 22 } 9 std::list<nscp::packet> handler_impl::process(nscp::packet &packet) { 10 std::list<nscp::packet> result; 23 11 24 // @todo re-add support for nasty arguments / arguments passing 12 Plugin::Common::Header hdr; 13 14 if (packet.is_command_request()) { 15 Plugin::QueryRequestMessage msg; 16 msg.ParseFromString(packet.payload); 17 hdr.CopyFrom(msg.header()); 18 19 // @todo: Make split optional 20 21 for (int i=0;i<msg.payload_size();i++) { 22 23 // @todo re-add support for nasty arguments / arguments passing 25 24 /* 26 25 if (!allowNasty_) { … … 35 34 } 36 35 */ 37 try { 38 NSC_DEBUG_MSG_STD(_T("Running command: ") + command); 39 NSCAPI::nagiosReturn returncode = nscapi::plugin_singleton->get_core()->query(command, buffer, ret); 40 } catch (...) { 41 NSC_LOG_ERROR(_T("Internal exception processing request: ") + command); 42 nscapi::functions::create_simple_query_result(NSCAPI::returnUNKNOWN, _T("Internal exception processing request: ") + command, _T(""), ret); 43 return ret; 36 37 std::string outBuffer; 38 std::wstring command = utf8::cvt<std::wstring>(msg.payload(i).command()); 39 if (command.empty() || command == _T("_NSCP_CHECK")) { 40 nscapi::functions::create_simple_query_response(NSCAPI::returnOK, _T("I (") + nscapi::plugin_singleton->get_core()->getApplicationVersionString() + _T(") seem to be doing fine..."), _T(""), outBuffer); 41 } else { 42 std::string tmpBuffer; 43 Plugin::QueryRequestMessage tmp; 44 tmp.mutable_header()->CopyFrom(hdr); 45 tmp.add_payload()->CopyFrom(msg.payload(i)); 46 tmp.SerializeToString(&tmpBuffer); 47 NSCAPI::nagiosReturn returncode = nscapi::plugin_singleton->get_core()->query(command, tmpBuffer, outBuffer); 48 } 49 result.push_back(nscp::packet::create_query_response(outBuffer)); 50 } 51 } else { 52 NSC_LOG_ERROR(_T("Unknown packet: ") + packet.to_wstring()); 53 result.push_back(create_error(_T("Unknown packet: ") + packet.to_wstring())); 44 54 } 45 return re t;55 return result; 46 56 } 47 57 -
modules/NSCPServer/handler_impl.hpp
r438998b rb38e845 20 20 } 21 21 22 std:: string process(std::string&buffer);22 std::list<nscp::packet> process(nscp::packet &buffer); 23 23 24 24 nscp::packet create_error(std::wstring msg) { 25 return nscp::packet::create_ response(4, msg, payload_length_);25 return nscp::packet::create_error(msg); 26 26 } 27 27 -
modules/PythonScript/PythonScript.cpp
r2c95d22 rb38e845 274 274 std::wstring result; 275 275 NSCAPI::nagiosReturn ret = inst->handle_simple_exec(cmd, data.args, result); 276 return nscapi::functions::create_simple_exec_result(data.command, ret, result, response); 276 nscapi::functions::create_simple_exec_response(data.command, ret, result, response); 277 return ret; 277 278 } 278 279 return NSCAPI::returnIgnored; … … 287 288 } 288 289 if (inst->has_simple(cmd)) { 289 nscapi::functions::decoded_simple_command_data data = nscapi::functions::p rocess_simple_command_request(command, request);290 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(command, request); 290 291 std::wstring msg, perf; 291 292 NSCAPI::nagiosReturn ret = inst->exec_simple(cmd, data.args, msg, perf); 292 return nscapi::functions::process_simple_command_result(data.command, ret, msg, perf, response); 293 nscapi::functions::create_simple_query_response(ret, msg, perf, response, data.command); 294 return ret; 293 295 } 294 296 NSC_LOG_ERROR_STD(_T("Could not find python commands for: ") + command + _T(" (avalible python commands are: ") + inst->get_commands() + _T(")")); … … 311 313 if (inst->has_simple_message_handler(chnl)) { 312 314 std::wstring msg, perf; 313 nscapi::functions::parse_simple_ message(request, msg, perf);315 nscapi::functions::parse_simple_query_response(request, msg, perf); 314 316 return inst->handle_simple_message(chnl, cmd, code, msg, perf); 315 317 }
Note: See TracChangeset
for help on using the changeset viewer.








