- Timestamp:
- 08/10/11 07:37:24 (22 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 54ac968
- Parents:
- e11d494
- Location:
- modules
- Files:
-
- 7 edited
-
CheckNSCP/CheckNSCP.cpp (modified) (4 diffs)
-
LUAScript/LUAScript.cpp (modified) (6 diffs)
-
LUAScript/LUAScript.h (modified) (3 diffs)
-
LUAScript/script_wrapper.hpp (modified) (6 diffs)
-
NRPEClient/CMakeLists.txt (modified) (1 diff)
-
NRPEServer/CMakeLists.txt (modified) (1 diff)
-
NSCAAgent/CMakeLists.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
modules/CheckNSCP/CheckNSCP.cpp
re11d494 r04ef932 22 22 23 23 #include <file_helpers.hpp> 24 #include <unicode_char.hpp> 24 25 25 26 #include <settings/client/settings_client.hpp> … … 85 86 86 87 int CheckNSCP::get_crashes(std::wstring &last_crash) { 88 #ifdef WIN32 87 89 if (!file_helpers::checks::is_directory(crashFolder)) { 88 90 return 0; … … 109 111 last_crash = last_file; 110 112 return count; 113 #else 114 return 0; 115 #endif 111 116 } 112 117 … … 125 130 std::wstring last_crash; 126 131 int crash_count = get_crashes(last_crash); 127 if (crash_count > 0) 128 strEx::append_list(msg, strEx::itos(crash_count) + _T(" crash(es), last crash: ") + last_crash, _T(", ")); 132 if (crash_count > 0){ 133 std::wstring tmp = strEx::itos(crash_count) + _T(" crash(es), last crash: ") + last_crash; 134 strEx::append_list(msg, tmp, _T(", ")); 135 } 129 136 130 137 std::wstring last_error; 131 138 int err_count = get_errors(last_error); 132 if (err_count > 0) 133 strEx::append_list(msg, strEx::itos(err_count) + _T(" error(s), last error: ") + last_error, _T(", ")); 139 if (err_count > 0) { 140 std::wstring tmp = strEx::itos(err_count) + _T(" error(s), last error: ") + last_error; 141 strEx::append_list(msg, tmp, _T(", ")); 142 } 134 143 135 144 if (msg.empty()) -
modules/LUAScript/LUAScript.cpp
rd66ccee r04ef932 46 46 try { 47 47 48 root_ = get_core()->getBasePath(); 49 48 50 sh::settings_registry settings(get_settings_proxy()); 49 51 settings.set_alias(alias, _T("lua")); … … 52 54 (_T("LUA SCRIPT SECTION"), _T("Section for the LUAScripts module.")) 53 55 54 (_T("scripts"), sh::fun_values_path(boost::bind(&LUAScript::loadScript, this, _1 )),56 (_T("scripts"), sh::fun_values_path(boost::bind(&LUAScript::loadScript, this, _1, _2)), 55 57 _T("LUA SCRIPTS SECTION"), _T("A list of scripts available to run from the LuaSCript module.")) 56 58 ; … … 62 64 // addAllScriptsFrom(scriptDirectory_); 63 65 // } 64 root_ = get_core()->getBasePath(); 66 67 68 69 70 BOOST_FOREACH(script_container &script, scripts_) { 71 try { 72 boost::shared_ptr<script_wrapper::lua_script> instance = boost::shared_ptr<script_wrapper::lua_script>(new script_wrapper::lua_script(script)); 73 instance->pre_load(this); 74 instances_.push_back(instance); 75 } catch (script_wrapper::LUAException e) { 76 NSC_LOG_ERROR_STD(_T("Could not load script ") + script.to_wstring() + _T(": ") + e.getMessage()); 77 } 78 } 65 79 66 80 // } catch (nrpe::server::nrpe_exception &e) { … … 81 95 82 96 void LUAScript::register_command(script_wrapper::lua_script* script, std::wstring command, std::wstring function) { 83 NSC_LOG_MESSAGE(_T("Script loading: ") + script->get_ script() + _T(": ") + command);97 NSC_LOG_MESSAGE(_T("Script loading: ") + script->get_wscript() + _T(": ") + command); 84 98 commands_[command] = lua_func(script, function); 85 99 } 86 100 87 bool LUAScript::loadScript(const std::wstring file) { 101 boost::optional<boost::filesystem::wpath> LUAScript::find_file(std::wstring file) { 102 std::list<boost::filesystem::wpath> checks; 103 checks.push_back(file); 104 checks.push_back(root_ / _T("scripts") / _T("lua") / file); 105 checks.push_back(root_ / _T("scripts") / file); 106 checks.push_back(root_ / _T("lua") / file); 107 checks.push_back(root_ / file); 108 BOOST_FOREACH(boost::filesystem::wpath c, checks) { 109 NSC_DEBUG_MSG_STD(_T("Looking for: ") + c.string()); 110 if (boost::filesystem::exists(c)) 111 return boost::optional<boost::filesystem::wpath>(c); 112 } 113 NSC_LOG_ERROR(_T("Script not found: ") + file); 114 return boost::optional<boost::filesystem::wpath>(); 115 } 116 117 bool LUAScript::loadScript(std::wstring alias, std::wstring file) { 88 118 try { 89 std::wstring file_ = file; 119 if (file.empty()) { 120 file = alias; 121 alias = _T(""); 122 } 90 123 91 if (!file_helpers::checks::exists(file_)) { 92 file_ = root_ + file; 93 if (!file_helpers::checks::exists(file_)) { 94 NSC_LOG_ERROR(_T("Script not found: ") + file + _T(" (") + file_ + _T(")")); 95 return false; 96 } 97 } 98 NSC_DEBUG_MSG_STD(_T("Loading script: ") + file + _T(" (") + file_ + _T(")")); 99 script_wrapper::lua_script *script = new script_wrapper::lua_script(file_); 100 script->pre_load(this); 101 scripts_.push_back(script); 124 boost::optional<boost::filesystem::wpath> ofile = find_file(file); 125 if (!ofile) 126 return false; 127 script_container::push(scripts_, alias, *ofile); 128 NSC_DEBUG_MSG_STD(_T("Adding script: ") + ofile->string() + _T(" as ") + alias + _T(")")); 102 129 return true; 103 } catch (script_wrapper::LUAException e) {104 NSC_LOG_ERROR_STD(_T("Could not load script: ") + file + _T(", ") + e.getMessage());105 130 } catch (...) { 106 131 NSC_LOG_ERROR_STD(_T("Could not load script: (Unknown exception) ") + file); … … 111 136 112 137 bool LUAScript::unloadModule() { 113 for (script_list::const_iterator cit = scripts_.begin(); cit != scripts_.end() ; ++cit) { 114 delete (*cit); 115 } 116 scripts_.clear(); 138 instances_.clear(); 117 139 return true; 118 140 } … … 129 151 bool error = false; 130 152 commands_.clear(); 131 for (script_list::const_iterator cit = scripts_.begin(); cit != scripts_.end() ; ++cit) {153 for (script_list::const_iterator cit = instances_.begin(); cit != instances_.end() ; ++cit) { 132 154 try { 133 155 (*cit)->reload(this); 134 156 } catch (script_wrapper::LUAException e) { 135 157 error = true; 136 message += _T("Exception when reloading script: ") + (*cit)->get_ script() + _T(": ") + e.getMessage();137 NSC_LOG_ERROR_STD(_T("Exception when reloading script: ") + (*cit)->get_ script() + _T(": ") + e.getMessage());158 message += _T("Exception when reloading script: ") + (*cit)->get_wscript() + _T(": ") + e.getMessage(); 159 NSC_LOG_ERROR_STD(_T("Exception when reloading script: ") + (*cit)->get_wscript() + _T(": ") + e.getMessage()); 138 160 } catch (...) { 139 161 error = true; 140 message += _T("Unhandeled Exception when reloading script: ") + (*cit)->get_ script();141 NSC_LOG_ERROR_STD(_T("Unhandeled Exception when reloading script: ") + (*cit)->get_ script());162 message += _T("Unhandeled Exception when reloading script: ") + (*cit)->get_wscript(); 163 NSC_LOG_ERROR_STD(_T("Unhandeled Exception when reloading script: ") + (*cit)->get_wscript()); 142 164 } 143 165 } -
modules/LUAScript/LUAScript.h
r3bdaf18 r04ef932 26 26 #include "script_wrapper.hpp" 27 27 28 #include <boost/optional.hpp> 29 30 #include <scripts/functions.hpp> 31 32 28 33 class LUAScript : public nscapi::impl::SimpleCommand, public script_wrapper::lua_handler, public nscapi::impl::simple_plugin { 29 34 private: … … 41 46 }; 42 47 48 script_container::list_type scripts_; 49 43 50 typedef std::map<std::wstring,lua_func> cmd_list; 44 typedef std::list< script_wrapper::lua_script*> script_list;51 typedef std::list<boost::shared_ptr<script_wrapper::lua_script> > script_list; 45 52 46 53 cmd_list commands_; 47 script_list scripts_;48 std::wstringroot_;54 script_list instances_; 55 boost::filesystem::wpath root_; 49 56 50 57 public: … … 71 78 bool hasCommandHandler(); 72 79 bool hasMessageHandler(); 73 bool loadScript(const std::wstring script); 80 boost::optional<boost::filesystem::wpath> find_file(std::wstring file); 81 bool loadScript(std::wstring alias, std::wstring file); 74 82 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 75 83 //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf); -
modules/LUAScript/script_wrapper.hpp
rd66ccee r04ef932 10 10 #include "luna.h" 11 11 12 #include <scripts/functions.hpp> 12 13 13 14 namespace script_wrapper { … … 304 305 class lua_script { 305 306 Lua_State L; 306 std::wstring script_; 307 public: 308 lua_script(const std::wstring file) : script_(file) { 307 std::string script_; 308 std::string alias_; 309 public: 310 lua_script(const script_container &script) : script_(utf8::cvt<std::string>(script.script.string())), alias_(utf8::cvt<std::string>(script.alias)) { 309 311 load(); 310 312 } … … 312 314 luaL_openlibs(L); 313 315 nsclient_wrapper::luaopen(L); 314 //Luna<Account>::Register(L);315 //lua_register(L, "register_command", register_command);316 317 if (luaL_loadfile(L, strEx::wstring_to_string(script_).c_str()) != 0) { 318 throw LUAException(_T("Failed to load script: ") + script_ + _T(": ") + s2w(lua_tostring(L, -1)));319 }320 321 } 322 std:: wstring get_script() const {316 if (luaL_loadfile(L, script_.c_str()) != 0) { 317 throw LUAException(_T("Failed to load script: ") + get_wscript() + _T(": ") + s2w(lua_tostring(L, -1))); 318 } 319 320 } 321 std::wstring get_wscript() const { 322 return utf8::cvt<std::wstring>(script_); 323 } 324 std::string get_script() const { 323 325 return script_; 324 326 } … … 333 335 lua_manager::set_script(L, this); 334 336 if (lua_pcall(L, 0, 0, 0) != 0) { 335 throw LUAException(_T("Failed to parse script: ") + script_+ _T(": ") + s2w(lua_tostring(L, -1)));337 throw LUAException(_T("Failed to parse script: ") + get_wscript() + _T(": ") + s2w(lua_tostring(L, -1))); 336 338 } 337 339 } … … 368 370 if (!lua_isfunction(L, -1)) { 369 371 lua_pop(L, 1); // remove function from LUA stack 370 throw LUAException(_T("Failed to run script: ") + script_+ _T(": Function not found: handle"));372 throw LUAException(_T("Failed to run script: ") + get_wscript() + _T(": Function not found: handle")); 371 373 } 372 374 lua_pushstring(L, w2s(cmd).c_str()); … … 382 384 if (lua_pcall(L, 2, LUA_MULTRET, 0) != 0) { 383 385 std::wstring err = strEx::string_to_wstring(lua_tostring(L, -1)); 384 NSC_LOG_ERROR_STD(_T("Failed to call main function in script: ") + script_+ _T(": ") + err);386 NSC_LOG_ERROR_STD(_T("Failed to call main function in script: ") + get_wscript() + _T(": ") + err); 385 387 lua_pop(L, 1); // remove error message 386 388 return NSCAPI::returnUNKNOWN; -
modules/NRPEClient/CMakeLists.txt
rd66ccee r04ef932 30 30 31 31 add_library(${TARGET} MODULE ${SRCS}) 32 INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) 32 33 33 34 target_link_libraries(${TARGET} -
modules/NRPEServer/CMakeLists.txt
rd66ccee r04ef932 44 44 45 45 add_library(${TARGET} MODULE ${SRCS}) 46 INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) 46 47 47 48 target_link_libraries(${TARGET} -
modules/NSCAAgent/CMakeLists.txt
rd66ccee r04ef932 38 38 39 39 add_library(${TARGET} MODULE ${SRCS}) 40 INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) 40 41 41 42 target_link_libraries(${TARGET}
Note: See TracChangeset
for help on using the changeset viewer.








