void log_args(const Plugin::QueryRequestMessage::Request &request) { std::stringstream ss; for (int i=0;i<request.arguments_size();i++) { if (i>0) ss << " "; if (request.arguments(i).find(" ") != std::string::npos) ss << '\"' << request.arguments(i) << '\"'; else ss << request.arguments(i); } NSC_DEBUG_MSG("Created command: " + ss.str()); }
void lua::lua_runtime::on_query(std::string command, script_information *information, lua::lua_traits::function_type function, bool simple, const Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response, const Plugin::QueryRequestMessage &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_query_response_payload(response, command, NSCAPI::returnUNKNOWN, "Invalid return", ""); return; } std::string msg, perf; perf = lua.pop_string(); msg = lua.pop_string(); ret = lua.pop_code(); lua.gc(LUA_GCCOLLECT, 0); nscapi::protobuf::functions::append_simple_query_response_payload(response, command, ret, msg, perf); } 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_query_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); } }
void CheckExternalScripts::query_fallback(const Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response, const Plugin::QueryRequestMessage &) { //nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); commands::optional_command_object command_def = commands_.find_object(request.command()); std::list<std::string> args; for (int i=0;i<request.arguments_size();++i) { args.push_back(request.arguments(i)); } if (command_def) { handle_command(*command_def, args, response); return; } alias::optional_command_object alias_def = aliases_.find_object(request.command()); if (alias_def) { handle_alias(*alias_def, args, response); return; } NSC_LOG_ERROR_STD("No command or alias found matching: " + request.command()); nscapi::protobuf::functions::set_response_bad(*response, "No command or alias found matching: " + request.command()); }
void CheckExternalScripts::query_fallback(const Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response, const Plugin::QueryRequestMessage &) { if (!provider_) { NSC_LOG_ERROR_STD("No provider found: " + request.command()); nscapi::protobuf::functions::set_response_bad(*response, "No command or alias found matching: " + request.command()); return; } commands::command_object_instance command_def = provider_->find_command(request.command()); std::list<std::string> args; for (int i = 0; i < request.arguments_size(); ++i) { args.push_back(request.arguments(i)); } if (command_def) { handle_command(*command_def, args, response); return; } alias::command_object_instance alias_def = aliases_.find_object(request.command()); if (alias_def) { handle_alias(*alias_def, args, response); return; } NSC_LOG_ERROR_STD("No command or alias found matching: " + request.command()); nscapi::protobuf::functions::set_response_bad(*response, "No command or alias found matching: " + request.command()); }