- Timestamp:
- 01/08/11 10:35:05 (2 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 58ee653
- Parents:
- e6792f3
- Location:
- modules
- Files:
-
- 2 added
- 1 deleted
- 5 edited
-
CheckSystem/CheckSystem.cpp (modified) (1 diff)
-
LUAScript/CMakeLists.txt (added)
-
LUAScript/Jamfile (deleted)
-
LUAScript/LUAScript.cpp (modified) (6 diffs)
-
LUAScript/LUAScript.h (modified) (5 diffs)
-
LUAScript/module.cmake (added)
-
LUAScript/script_wrapper.hpp (modified) (6 diffs)
-
LUAScript/stdafx.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
modules/CheckSystem/CheckSystem.cpp
r1ecd26f r87cf3c4 850 850 NSPROCDATA__(const NSPROCDATA__ &other) : count(other.count), hung_count(other.hung_count), entry(other.entry), key(other.key) {} 851 851 } NSPROCDATA; 852 typedef std::map<std::wstring,NSPROCDATA ,strEx::StrICmp> NSPROCLST;852 typedef std::map<std::wstring,NSPROCDATA> NSPROCLST; 853 853 854 854 class NSC_error : public CEnumProcess::error_reporter { -
modules/LUAScript/LUAScript.cpp
r5735dda r87cf3c4 30 30 LUAScript gLUAScript; 31 31 32 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)33 {34 NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);35 return TRUE;36 }37 38 32 LUAScript::LUAScript() { 39 33 } … … 41 35 } 42 36 37 namespace sh = nscapi::settings_helper; 43 38 44 bool LUAScript::loadModule(NSCAPI::moduleLoadMode mode) { 45 //LUA Scripts 39 bool LUAScript::loadModule() { 40 return false; 41 } 42 bool LUAScript::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 43 //std::wstring appRoot = file_helpers::folders::get_local_appdata_folder(SZAPPNAME); 46 44 try { 47 SETTINGS_REG_PATH(lua::SECTION); 48 } catch (NSCModuleHelper::NSCMHExcpetion &e) { 49 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 45 46 sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 47 settings.set_alias(alias, _T("lua")); 48 49 settings.alias().add_path_to_settings() 50 (_T("LUA SCRIPT SECTION"), _T("Section for the LUAScripts module.")) 51 52 (_T("scripts"), sh::fun_values_path(boost::bind(&LUAScript::loadScript, this, _1)), 53 _T("LUA SCRIPTS SECTION"), _T("A list of scripts available to run from the LuaSCript module.")) 54 ; 55 56 settings.register_all(); 57 settings.notify(); 58 59 // if (!scriptDirectory_.empty()) { 60 // addAllScriptsFrom(scriptDirectory_); 61 // } 62 root_ = get_core()->getBasePath(); 63 64 // } catch (nrpe::server::nrpe_exception &e) { 65 // NSC_LOG_ERROR_STD(_T("Exception caught: ") + e.what()); 66 // return false; 50 67 } catch (...) { 51 NSC_LOG_ERROR_STD(_T("Failed to register command.")); 68 NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>")); 69 return false; 52 70 } 53 std::list<std::wstring> commands = NSCModuleHelper::getSettingsSection(settings::lua::SECTION_PATH); 54 std::list<std::wstring>::const_iterator it; 55 for (it = commands.begin(); it != commands.end(); ++it) { 56 loadScript((*it)); 57 } 71 return true; 72 73 // std::list<std::wstring>::const_iterator it; 74 // for (it = commands.begin(); it != commands.end(); ++it) { 75 // loadScript((*it)); 76 // } 58 77 return true; 59 78 } … … 61 80 void LUAScript::register_command(script_wrapper::lua_script* script, std::wstring command, std::wstring function) { 62 81 NSC_LOG_MESSAGE(_T("Script loading: ") + script->get_script() + _T(": ") + command); 63 strEx:: blindstrbstr = command.c_str();82 strEx::wci_string bstr = command.c_str(); 64 83 commands_[bstr] = lua_func(script, function); 65 84 } … … 70 89 71 90 if (!file_helpers::checks::exists(file_)) { 72 file_ = NSCModuleHelper::getBasePath()+ file;91 file_ = root_ + file; 73 92 if (!file_helpers::checks::exists(file_)) { 74 93 NSC_LOG_ERROR(_T("Script not found: ") + file + _T(" (") + file_ + _T(")")); … … 85 104 } catch (...) { 86 105 NSC_LOG_ERROR_STD(_T("Could not load script: (Unknown exception) ") + file); 87 //assert(false);88 106 } 89 107 return false; … … 130 148 131 149 132 NSCAPI::nagiosReturn LUAScript::handleCommand(const strEx:: blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) {150 NSCAPI::nagiosReturn LUAScript::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 133 151 if (command == _T("LuaReload")) { 134 return reload(m sg)?NSCAPI::returnOK:NSCAPI::returnCRIT;152 return reload(message)?NSCAPI::returnOK:NSCAPI::returnCRIT; 135 153 } 136 154 cmd_list::const_iterator cit = commands_.find(command); 137 155 if (cit == commands_.end()) 138 156 return NSCAPI::returnIgnored; 139 return (*cit).second.handleCommand(this, command , argLen, char_args, msg, perf);157 return (*cit).second.handleCommand(this, command.c_str(), arguments, message, perf); 140 158 } 141 159 142 160 161 NSC_WRAP_DLL(); 143 162 NSC_WRAPPERS_MAIN_DEF(gLUAScript); 144 163 NSC_WRAPPERS_IGNORE_MSG_DEF(); -
modules/LUAScript/LUAScript.h
r739db5a r87cf3c4 26 26 #include "script_wrapper.hpp" 27 27 28 class LUAScript : script_wrapper::lua_handler{28 class LUAScript : public nscapi::impl::SimpleCommand, public script_wrapper::lua_handler, public nscapi::impl::simple_plugin { 29 29 private: 30 30 … … 36 36 std::wstring function; 37 37 38 NSCAPI::nagiosReturn handleCommand(lua_handler *handler, st rEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) const {39 return script->handleCommand(handler, function, command, arg Len, char_args, msg, perf);38 NSCAPI::nagiosReturn handleCommand(lua_handler *handler, std::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) const { 39 return script->handleCommand(handler, function, command, arguments, msg, perf); 40 40 } 41 41 }; 42 42 43 typedef std::map<strEx:: blindstr,lua_func> cmd_list;43 typedef std::map<strEx::wci_string,lua_func> cmd_list; 44 44 typedef std::list<script_wrapper::lua_script*> script_list; 45 45 46 46 cmd_list commands_; 47 47 script_list scripts_; 48 std::wstring root_; 48 49 49 50 public: … … 51 52 virtual ~LUAScript(); 52 53 // Module calls 53 bool loadModule(NSCAPI::moduleLoadMode mode); 54 bool loadModule(); 55 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 56 54 57 bool unloadModule(); 55 58 bool reload(std::wstring &msg); … … 61 64 return _T("LUAScript..."); 62 65 } 63 NSCModuleWrapper::module_version getModuleVersion() {64 NSCModuleWrapper::module_version version = {0, 0, 1 };66 nscapi::plugin_wrapper::module_version getModuleVersion() { 67 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 65 68 return version; 66 69 } … … 69 72 bool hasMessageHandler(); 70 73 bool loadScript(const std::wstring script); 71 NSCAPI::nagiosReturn handleCommand(const strEx:: blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf);74 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 72 75 //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 73 76 //NSCAPI::nagiosReturn extract_return(Lua_State &L, int arg_count, std::wstring &message, std::wstring &perf); -
modules/LUAScript/script_wrapper.hpp
r1ff950c r87cf3c4 194 194 int nargs = lua_gettop( L ); 195 195 if (nargs == 0) { 196 return luaL_error(L, "nscp.execute requires at least 1 argument!");196 return luaL_error(L, "nscp.execute requires at least 1 argument!"); 197 197 } 198 198 unsigned int argLen = nargs-1; 199 arrayBuffer::arrayBuffer arguments = arrayBuffer::createArrayBuffer(argLen);199 std::list<std::wstring> arguments; 200 200 for (unsigned int i=argLen;i>0;i--) { 201 std::wstring arg = extract_string(L); 202 arrayBuffer::set(arguments, argLen, i-1, arg); 201 arguments.push_front(extract_string(L)); 203 202 lua_pop(L, 1); 204 203 } 205 204 std::wstring command = extract_string(L); 206 205 lua_pop(L, 1); 207 std::wstring m sg;206 std::wstring message; 208 207 std::wstring perf; 209 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectCommand(command.c_str(), argLen, arguments, msg, perf);208 NSCAPI::nagiosReturn ret = GET_CORE()->InjectSimpleCommand(command, arguments, message, perf); 210 209 push_code(L, ret); 211 lua_pushstring(L, strEx::wstring_to_string(m sg).c_str());210 lua_pushstring(L, strEx::wstring_to_string(message).c_str()); 212 211 lua_pushstring(L, strEx::wstring_to_string(perf).c_str()); 213 212 return 3; … … 242 241 std::wstring k = pop_string(L); 243 242 std::wstring s = pop_string(L); 244 push_string(L, NSCModuleHelper::getSettingsString(s, k, v));243 push_string(L, GET_CORE()->getSettingsString(s, k, v)); 245 244 return 1; 246 245 } … … 253 252 v = pop_string(L); 254 253 try { 255 std::list<std::wstring> list = NSCModuleHelper::getSettingsSection(v);254 std::list<std::wstring> list = GET_CORE()->getSettingsSection(v); 256 255 push_array(L, list); 257 256 } catch (...) { … … 273 272 str += pop_string(L); 274 273 } 275 NSCModuleHelper::Message(mode, w.first, w.second, str);274 GET_CORE()->Message(mode, to_string(w.first), w.second, str); 276 275 return 0; 277 276 } … … 362 361 } 363 362 364 NSCAPI::nagiosReturn handleCommand(lua_handler *handler, std::wstring function, st rEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) {363 NSCAPI::nagiosReturn handleCommand(lua_handler *handler, std::wstring function, std::wstring cmd, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) { 365 364 lua_manager::set_handler(L, handler); 366 365 lua_manager::set_script(L, this); … … 371 370 throw LUAException(_T("Failed to run script: ") + script_ + _T(": Function not found: handle")); 372 371 } 373 std::wstring cmd = command.c_str();374 372 lua_pushstring(L, w2s(cmd).c_str()); 375 373 376 lua_createtable(L, 0, argLen); 377 for (unsigned int i=0;i<argLen;i++) { 378 lua_pushnumber(L,i+1); 379 lua_pushstring(L,strEx::wstring_to_string(char_args[i]).c_str()); 374 lua_createtable(L, 0, arguments.size()); 375 int i=0; 376 BOOST_FOREACH(std::wstring arg, arguments) { 377 lua_pushnumber(L,i++); 378 lua_pushstring(L,strEx::wstring_to_string(arg).c_str()); 380 379 lua_settable(L,-3); 381 380 } -
modules/LUAScript/stdafx.h
r7f9c823 r87cf3c4 21 21 #pragma once 22 22 23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers24 // Windows Header Files:25 #include <windows.h>26 27 23 #include <string> 28 24 #include <functional> 29 25 26 #include <types.hpp> 30 27 #include <NSCAPI.h> 31 #include <NSCHelper.h> 32 #include <nsc_module_wrapper.hpp> 33 34 #ifdef MEMCHECK 35 #include <vld.h> 36 #endif 28 #include <nscapi/plugin.hpp>
Note: See TracChangeset
for help on using the changeset viewer.








