Changeset d6194a0 in nscp
- Timestamp:
- 07/27/12 07:06:17 (10 months ago)
- Branches:
- master, 0.4.1, 0.4.2
- Children:
- 724a835
- Parents:
- c327ce5
- Files:
-
- 2 added
- 27 edited
-
CMakeLists.txt (modified) (1 diff)
-
build/cmake/GoogleProtoBuf.cmake (modified) (1 diff)
-
build/cmake/functions.cmake (modified) (3 diffs)
-
changelog (modified) (1 diff)
-
files/CMakeLists.txt (modified) (1 diff)
-
files/nsclient.dist (added)
-
helpers/installer-dlls/main_dll/main_dll.cpp (modified) (1 diff)
-
include/nrpe/packet.hpp (modified) (1 diff)
-
include/nsca/client/nsca_client_protocol.hpp (modified) (1 diff)
-
include/nsclient/base_logger_impl.hpp (modified) (1 diff)
-
include/settings/client/settings_client.hpp (modified) (2 diffs)
-
include/socket/client.hpp (modified) (1 diff)
-
libs/cryptopp/CMakeLists.txt (modified) (5 diffs)
-
libs/lua/CMakeLists.txt (modified) (1 diff)
-
libs/lua_pb/CMakeLists.txt (modified) (2 diffs)
-
modules/LUAScript/CMakeLists.txt (modified) (1 diff)
-
modules/LUAScript/LUAScript.cpp (modified) (7 diffs)
-
modules/LUAScript/LUAScript.h (modified) (1 diff)
-
modules/LUAScript/lua_wrappers.cpp (modified) (6 diffs)
-
modules/LUAScript/lua_wrappers.hpp (modified) (18 diffs)
-
modules/LUAScript/script_wrapper.hpp (modified) (20 diffs)
-
modules/NRPEClient/NRPEClient.cpp (modified) (2 diffs)
-
scripts/CMakeLists.txt (modified) (4 diffs)
-
scripts/lua/lib/test_helper.lua (added)
-
scripts/lua/test_nrpe.lua (modified) (8 diffs)
-
service/NSClient++.cpp (modified) (2 diffs)
-
service/NSClient++.h (modified) (1 diff)
-
service/cli_parser.hpp (modified) (4 diffs)
-
service/logger_impl.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r53be5c8 rd6194a0 57 57 ${LUA_DIR}/src 58 58 /usr/include/lua 59 ) 59 /usr/include/lua5.1 60 ) 61 FIND_PROGRAM(PROTOC_GEN_LUA_FOUND 62 NAMES protoc-gen-lua 63 PATHS 64 /usr/local/bin/ 65 /usr/bin/ 66 ) 67 60 68 IF (LUA_INCLUE_DIR) 61 69 message(STATUS "Found lua in ${LUA_INCLUE_DIR}") 62 SET(HAVE_LUA TRUE PARENT_SCOPE)63 70 SET(HAVE_LUA TRUE) 64 71 SET(LUA_SOURCE_DIR ${LUA_INCLUE_DIR}) -
build/cmake/GoogleProtoBuf.cmake
rc327ce5 rd6194a0 38 38 LIST(APPEND ARGS --python_out ${PROJECT_BINARY_DIR}/scripts/python/lib) 39 39 IF(PROTOC_GEN_LUA_FOUND) 40 SET(PROTOC_GEN_LUA_EXTRA --plugin=protoc-gen-lua=${PROTOC_GEN_LUA_CMD}) 40 IF(PROTOC_GEN_LUA_CMD) 41 SET(PROTOC_GEN_LUA_EXTRA --plugin=protoc-gen-lua=${PROTOC_GEN_LUA_CMD}) 42 ENDIF(PROTOC_GEN_LUA_CMD) 41 43 LIST(APPEND ARGS --lua_out ${PROJECT_BINARY_DIR}/libs/lua_pb ${PROTOC_GEN_LUA_EXTRA}) 42 44 ENDIF(PROTOC_GEN_LUA_FOUND) -
build/cmake/functions.cmake
rc327ce5 rd6194a0 20 20 21 21 22 MACRO(copy_single_file target,src destDir)22 MACRO(copy_single_file _TARGET_LIST src destDir) 23 23 GET_FILENAME_COMPONENT(TARGET ${src} NAME) 24 24 SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/${src}) … … 28 28 SET(target_file ${CMAKE_BINARY_DIR}/${destDir}/${TARGET}) 29 29 ENDIF(${destDir} STREQUAL ".") 30 #message(STATUS " - Copying ${source_file} to ${target_file}...")30 message(STATUS " - Copying ${source_file} to ${target_file}...") 31 31 ADD_CUSTOM_COMMAND( 32 32 OUTPUT ${target_file} … … 36 36 DEPENDS ${source_file} 37 37 ) 38 LIST(APPEND ALL_FILES${target_file})38 SET(${_TARGET_LIST} ${${_TARGET_LIST}} ${target_file}) 39 39 ENDMACRO(copy_single_file) 40 40 -
changelog
rc327ce5 rd6194a0 4 4 * Fix dependonservice LanManWorkStation (old win) 5 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-07-26 MickeM 8 * Fixed some memoryelaks in LUAModule 9 * Extracted the test functions into a library 10 * Added lib folder as search path for lua scripts 11 * Tweaks and improvments all around 12 * Improved the build scripts a lot making files work on linux (still need to manually build the targets though) 13 14 2012-07-23 MickeM 15 * Added support for LUAScripts to linux enviornments (still a few warnings to sort out) 16 * Improved lua unit test scripts 17 * Added support for using member functions as handlers in Lua scripts 6 18 7 19 2012-07-17 MickeM -
files/CMakeLists.txt
rc327ce5 rd6194a0 2 2 3 3 SET(ALL_FILES) 4 copy_single_file( copy_fileslicense.txt .)5 copy_single_file( copy_filesnrpe_dh_512.pem security)6 copy_single_file( copy_filesold-settings.map .)7 copy_single_file( copy_filescounters.defs .)8 copy_single_file( copy_filesnsclient.dist .)9 copy_single_file( copy_files../changelog .)4 copy_single_file(ALL_FILES license.txt .) 5 copy_single_file(ALL_FILES nrpe_dh_512.pem security) 6 copy_single_file(ALL_FILES old-settings.map .) 7 copy_single_file(ALL_FILES counters.defs .) 8 copy_single_file(ALL_FILES nsclient.dist .) 9 copy_single_file(ALL_FILES ../changelog .) 10 10 11 11 ADD_CUSTOM_TARGET(copy_files DEPENDS ${ALL_FILES}) -
helpers/installer-dlls/main_dll/main_dll.cpp
r440c0cb rd6194a0 46 46 47 47 48 void do_log(const std::string &data) {48 void do_log(const std::string data) { 49 49 std::wstring str = utf8::cvt<std::wstring>(data); 50 50 if (str.empty()) -
include/nrpe/packet.hpp
ra48fd4c rd6194a0 172 172 unsigned int packet_length = nrpe::length::get_packet_length(payload_length_); 173 173 tmpBuffer = new char[packet_length+1]; 174 memset(tmpBuffer, 0, packet_length+1); 174 175 //TODO readd this ZeroMemory(tmpBuffer, getBufferLength()+1); 175 176 nrpe::data::packet *p = reinterpret_cast<nrpe::data::packet*>(tmpBuffer); -
include/nsca/client/nsca_client_protocol.hpp
rc327ce5 rd6194a0 37 37 sent_request, 38 38 has_request, 39 done ,39 done 40 40 }; 41 41 state current_state_; -
include/nsclient/base_logger_impl.hpp
r6533c1a rd6194a0 66 66 } 67 67 68 virtual void do_log(const std::string &data) = 0;68 virtual void do_log(const std::string data) = 0; 69 69 virtual void configure() = 0; 70 70 virtual bool shutdown() { -
include/settings/client/settings_client.hpp
ra48fd4c rd6194a0 513 513 settings_keys_easy_init(std::wstring path, settings_registry* owner_) : owner(owner_), path_(path) {} 514 514 settings_keys_easy_init(std::wstring path, std::wstring parent, settings_registry* owner_) : owner(owner_), path_(path), parent_(parent) {} 515 virtual ~settings_keys_easy_init() {} 515 516 516 517 settings_keys_easy_init& operator()(std::wstring path, std::wstring key_name, boost::shared_ptr<key_interface> value, std::wstring title, std::wstring description, bool advanced = false) { … … 643 644 public: 644 645 settings_registry(settings_impl_interface_ptr core) : core_(core) {} 646 virtual ~settings_registry() {} 645 647 void add(boost::shared_ptr<key_info> info) { 646 648 keys_.push_back(info); -
include/socket/client.hpp
ra48fd4c rd6194a0 350 350 , dh_key_(dh_key) 351 351 {} 352 virtual ~client_handler() {} 352 353 353 354 bool use_ssl() { return ssl_; } -
libs/cryptopp/CMakeLists.txt
rc327ce5 rd6194a0 2 2 3 3 IF (HAVE_CRYPTOPP) 4 message(STATUS "Found CACHED Crypto++ in ${CRYPTOPP_SOURCE_DIR}")4 MESSAGE(STATUS "Found CACHED Crypto++ in ${CRYPTOPP_SOURCE_DIR}") 5 5 ELSE (HAVE_CRYPTOPP) 6 6 FIND_PATH(CRYPTOPP_SOURCE_DIR cryptlib.h ${CRYPTOPP_DIR}) 7 7 8 8 IF (CRYPTOPP_SOURCE_DIR) 9 message(STATUS "Found Crypto++ in ${CRYPTOPP_SOURCE_DIR}")9 MESSAGE(STATUS "Found Crypto++ in ${CRYPTOPP_SOURCE_DIR}") 10 10 SET(HAVE_CRYPTOPP TRUE PARENT_SCOPE) 11 11 SET(HAVE_CRYPTOPP TRUE) 12 12 ELSE (CRYPTOPP_SOURCE_DIR) 13 message(STATUS "Crypto++ was not found in ${CRYPTOPP_SOURCE_DIR} (CRYPTOPP_SOURCE_DIR)")13 MESSAGE(STATUS "Crypto++ was not found in ${CRYPTOPP_SOURCE_DIR} (CRYPTOPP_SOURCE_DIR)") 14 14 ENDIF (CRYPTOPP_SOURCE_DIR) 15 15 16 16 ENDIF (HAVE_CRYPTOPP) 17 17 18 SET(CRYPTOS des rijndael cast tea 3way blowfish twofish rc2 arc4 serpent gost ) 18 19 19 20 IF (HAVE_CRYPTOPP) 20 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/des.cpp) 21 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/rijndael.cpp) 22 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cast.cpp) 23 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/tea.cpp) 24 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/3way.cpp) 25 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/blowfish.cpp) 26 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/twofish.cpp) 27 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/rc2.cpp) 28 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/arc4.cpp) 29 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/serpent.cpp) 30 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/gost.cpp) 31 21 22 FOREACH(CRYPTO ${CRYPTOS}) 23 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/${CRYPTO}.cpp) 24 IF (WIN32) 25 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/${CRYPTO}.h) 26 ENDIF (WIN32) 27 ENDFOREACH(CRYPTO ${CRYPTOS}) 28 29 32 30 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/filters.cpp) 33 31 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/osrng.cpp) … … 35 33 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cryptlib.cpp) 36 34 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/misc.cpp) 37 38 35 LIST(APPEND cryptopp_SOURCES cryptopp.cpp) 36 39 37 IF (WIN32) 40 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/des.h)41 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/aes.h)42 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cast.h)43 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/tea.h)44 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/3way.h)45 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/blowfish.h)46 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/twofish.h)47 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/rc2.h)48 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/arc4.h)49 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/serpent.h)50 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/gost.h)51 52 38 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/filters.h) 53 39 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/osrng.h) … … 55 41 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cryptlib.h) 56 42 LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/misc.h) 57 58 43 LIST(APPEND cryptopp_SOURCES ${NSCP_INCLUDEDIR}/cryptopp/cryptopp.hpp) 44 59 45 ENDIF (WIN32) 60 message(STATUS "Using Crypto++ from ${CRYPTOPP_SOURCE_DIR}")61 46 IF (MSVC) 62 # ADD_DEFINITIONS (-DCRYPTOPP_GENERATE_X64_MASM)63 # ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM)64 # ADD_DEFINITIONS (-DNDEBUG)47 # ADD_DEFINITIONS (-DCRYPTOPP_GENERATE_X64_MASM) 48 # ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM) 49 # ADD_DEFINITIONS (-DNDEBUG) 65 50 CMAKE_POLICY(SET CMP0008 NEW) 66 51 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi") 52 53 IF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 54 string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 55 ENDIF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 67 56 ENDIF (MSVC) 68 57 … … 85 74 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES FOLDER "libraries") 86 75 #IF(NOT WIN32) 76 MESSAGE(STATUS "===> ${CMAKE_CXX_FLAGS}") 87 77 ADD_LIBRARY(cryptopp_static STATIC ${cryptopp_SOURCES}) 88 78 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES FOLDER "libraries") … … 98 88 99 89 IF(APPLE) 100 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM")101 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM")90 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 91 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 102 92 ELSEIF(UNIX AND NOT APPLE) 103 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3")104 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3")93 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 94 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 105 95 ELSEIF(WIN32) 106 IF(NOT MSVC)107 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32")108 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32")109 ENDIF(NOT MSVC)96 IF(NOT MSVC) 97 #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 98 SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 99 ENDIF(NOT MSVC) 110 100 ENDIF(APPLE) 111 101 ENDIF (HAVE_CRYPTOPP) -
libs/lua/CMakeLists.txt
r53be5c8 rd6194a0 2 2 3 3 IF (HAVE_LUA) 4 SET(LUA_SOURCE_DIR ${LUA_INCLUE_DIR}) 5 #FILE (GLOB lua_SOURCES "${LUA_SOURCE_DIR}/*.c") 4 5 6 FIND_LIBRARY(LUA_LIB 7 NAMES liblua5.1 lua5.1 lua 8 ) 9 IF(LUA_LIB) 10 MESSAGE(STATUS "Found existing LUA lib: ${LUA_LIB}") 11 ELSE(LUA_LIB) 12 FIND_PATH(LUA_SOURCE_DIR lapi.c 13 ${LUA_INCLUE_DIR} 14 ${LUA_INCLUE_DIR}/src 15 ${LUA_DIR} 16 ${LUA_DIR}/src 17 ) 6 18 7 SET(lua_SOURCES 8 ${LUA_SOURCE_DIR}/lapi.c 9 ${LUA_SOURCE_DIR}/lauxlib.c 10 ${LUA_SOURCE_DIR}/lbaselib.c 11 ${LUA_SOURCE_DIR}/lcode.c 12 ${LUA_SOURCE_DIR}/ldblib.c 13 ${LUA_SOURCE_DIR}/ldebug.c 14 ${LUA_SOURCE_DIR}/ldo.c 15 ${LUA_SOURCE_DIR}/ldump.c 16 ${LUA_SOURCE_DIR}/lfunc.c 17 ${LUA_SOURCE_DIR}/lgc.c 18 ${LUA_SOURCE_DIR}/linit.c 19 ${LUA_SOURCE_DIR}/liolib.c 20 ${LUA_SOURCE_DIR}/llex.c 21 ${LUA_SOURCE_DIR}/lmathlib.c 22 ${LUA_SOURCE_DIR}/lmem.c 23 ${LUA_SOURCE_DIR}/loadlib.c 24 ${LUA_SOURCE_DIR}/lobject.c 25 ${LUA_SOURCE_DIR}/lopcodes.c 26 ${LUA_SOURCE_DIR}/loslib.c 27 ${LUA_SOURCE_DIR}/lparser.c 28 ${LUA_SOURCE_DIR}/lstate.c 29 ${LUA_SOURCE_DIR}/lstring.c 30 ${LUA_SOURCE_DIR}/lstrlib.c 31 ${LUA_SOURCE_DIR}/ltable.c 32 ${LUA_SOURCE_DIR}/ltablib.c 33 ${LUA_SOURCE_DIR}/ltm.c 34 ${LUA_SOURCE_DIR}/lundump.c 35 ${LUA_SOURCE_DIR}/lvm.c 36 ${LUA_SOURCE_DIR}/lzio.c 37 ) 38 39 FILE (GLOB lua_HEADERS "${LUA_SOURCE_DIR}/*.h") 40 IF (MSVC) 41 CMAKE_POLICY(SET CMP0008 NEW) 42 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi") 43 ENDIF (MSVC) 19 MESSAGE(STATUS "* * * * * NOT Found LUA sources (will build library): ${LUA_SOURCE_DIR}") 20 21 SET(lua_SOURCES 22 ${LUA_SOURCE_DIR}/lapi.c 23 ${LUA_SOURCE_DIR}/lauxlib.c 24 ${LUA_SOURCE_DIR}/lbaselib.c 25 ${LUA_SOURCE_DIR}/lcode.c 26 ${LUA_SOURCE_DIR}/ldblib.c 27 ${LUA_SOURCE_DIR}/ldebug.c 28 ${LUA_SOURCE_DIR}/ldo.c 29 ${LUA_SOURCE_DIR}/ldump.c 30 ${LUA_SOURCE_DIR}/lfunc.c 31 ${LUA_SOURCE_DIR}/lgc.c 32 ${LUA_SOURCE_DIR}/linit.c 33 ${LUA_SOURCE_DIR}/liolib.c 34 ${LUA_SOURCE_DIR}/llex.c 35 ${LUA_SOURCE_DIR}/lmathlib.c 36 ${LUA_SOURCE_DIR}/lmem.c 37 ${LUA_SOURCE_DIR}/loadlib.c 38 ${LUA_SOURCE_DIR}/lobject.c 39 ${LUA_SOURCE_DIR}/lopcodes.c 40 ${LUA_SOURCE_DIR}/loslib.c 41 ${LUA_SOURCE_DIR}/lparser.c 42 ${LUA_SOURCE_DIR}/lstate.c 43 ${LUA_SOURCE_DIR}/lstring.c 44 ${LUA_SOURCE_DIR}/lstrlib.c 45 ${LUA_SOURCE_DIR}/ltable.c 46 ${LUA_SOURCE_DIR}/ltablib.c 47 ${LUA_SOURCE_DIR}/ltm.c 48 ${LUA_SOURCE_DIR}/lundump.c 49 ${LUA_SOURCE_DIR}/lvm.c 50 ${LUA_SOURCE_DIR}/lzio.c 51 ) 52 53 FILE (GLOB lua_HEADERS "${LUA_SOURCE_DIR}/*.h") 54 IF (MSVC) 55 CMAKE_POLICY(SET CMP0008 NEW) 56 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi") 57 ENDIF (MSVC) 44 58 45 IF (WIN32)46 ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM)47 SET(lua_DEFINES -DCRYPTOPP_DISABLE_ASM)48 ENDIF (WIN32)59 IF (WIN32) 60 ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM) 61 SET(lua_DEFINES -DCRYPTOPP_DISABLE_ASM) 62 ENDIF (WIN32) 49 63 50 ADD_LIBRARY(lua SHARED ${lua_SOURCES})51 SET_TARGET_PROPERTIES(lua PROPERTIES FOLDER "libraries")52 ADD_LIBRARY(lua_static STATIC ${lua_SOURCES})53 SET_TARGET_PROPERTIES(lua_static PROPERTIES FOLDER "libraries")64 ADD_LIBRARY(lua SHARED ${lua_SOURCES}) 65 SET_TARGET_PROPERTIES(lua PROPERTIES FOLDER "libraries") 66 ADD_LIBRARY(lua_static STATIC ${lua_SOURCES}) 67 SET_TARGET_PROPERTIES(lua_static PROPERTIES FOLDER "libraries") 54 68 55 IF(APPLE) 56 SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 57 SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 58 ELSEIF(UNIX AND NOT APPLE) 59 SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 60 SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 61 ELSEIF(WIN32) 62 IF(NOT MSVC) 63 SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 64 SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 65 ENDIF(NOT MSVC) 66 ENDIF(APPLE) 69 IF(APPLE) 70 SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 71 SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-w -DOSX -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 72 ELSEIF(UNIX AND NOT APPLE) 73 SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 74 SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 75 ELSEIF(WIN32) 76 IF(NOT MSVC) 77 SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 78 SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 79 ENDIF(NOT MSVC) 80 ENDIF(APPLE) 81 SET(LUA_LIB lua_static) 82 SET(LUA_LIB lua_static PARENT_SCOPE) 83 ENDIF(LUA_LIB) 67 84 ENDIF (HAVE_LUA) -
libs/lua_pb/CMakeLists.txt
rc327ce5 rd6194a0 31 31 ${PROTOBUF_LIBRARY} 32 32 protobuf 33 lua_static33 ${LUA_LIB} 34 34 ) 35 35 target_link_libraries(lua_pb_static 36 36 ${PROTOBUF_LIBRARY} 37 37 protobuf 38 lua_static38 ${LUA_LIB} 39 39 ) 40 40 … … 44 44 ELSEIF(UNIX AND NOT APPLE) 45 45 SET_TARGET_PROPERTIES(lua_pb PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 46 SET_TARGET_PROPERTIES(lua_pb_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3")46 SET_TARGET_PROPERTIES(lua_pb_static PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 47 47 ELSEIF(WIN32) 48 48 IF(NOT MSVC) -
modules/LUAScript/CMakeLists.txt
r53be5c8 rd6194a0 44 44 ${Boost_PROGRAM_OPTIONS_LIBRARY} 45 45 ${NSCP_DEF_PLUGIN_LIB} 46 lua_static46 ${LUA_LIB} 47 47 ${LUA_PB} 48 48 ) -
modules/LUAScript/LUAScript.cpp
r53be5c8 rd6194a0 26 26 #include <strEx.h> 27 27 #include <time.h> 28 #include <filter_framework.hpp>28 //#include <filter_framework.hpp> 29 29 #include <error.hpp> 30 30 #include <file_helpers.hpp> … … 33 33 34 34 35 LUAScript::LUAScript() : registry(new lua_wrappers::lua_registry()){35 LUAScript::LUAScript() { 36 36 } 37 37 LUAScript::~LUAScript() { … … 45 45 } 46 46 bool LUAScript::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 47 registry.reset(new lua_wrappers::lua_registry()); 47 48 //std::wstring appRoot = file_helpers::folders::get_local_appdata_folder(SZAPPNAME); 48 49 try { … … 72 73 BOOST_FOREACH(script_container &script, scripts_) { 73 74 try { 74 instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, script.alias, script.script.string()));75 instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, script.alias, root_.string(), script.script.string())); 75 76 } catch (const lua_wrappers::LUAException &e) { 76 77 NSC_LOG_ERROR_STD(_T("Could not load script ") + script.to_wstring() + _T(": ") + e.getMessage()); … … 135 136 136 137 bool LUAScript::unloadModule() { 138 BOOST_FOREACH(script_instance &i, instances_) { 139 try { 140 i->unload(); 141 } catch (const lua_wrappers::LUAException &e) { 142 NSC_LOG_ERROR_STD(_T("Exception when unloading script: ") + i->get_wscript() + _T(": ") + e.getMessage()); 143 } catch (...) { 144 NSC_LOG_ERROR_STD(_T("Unhandeled Exception when unloading script: ") + i->get_wscript()); 145 } 146 } 147 if (registry) 148 registry->clear(); 137 149 instances_.clear(); 138 150 scripts_.clear(); 151 registry.reset(); 139 152 return true; 140 153 } … … 210 223 211 224 try { 212 instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, _T("cmdline"), (*ofile).string()));225 instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, _T("cmdline"), root_.string(), (*ofile).string())); 213 226 } catch (const lua_wrappers::LUAException &e) { 214 227 NSC_LOG_ERROR_STD(_T("Could not load script ") + _T(": ") + e.getMessage()); … … 253 266 254 267 255 NSC_WRAP_DLL() ;256 NSC_WRAPPERS_MAIN_DEF(LUAScript) ;257 NSC_WRAPPERS_IGNORE_MSG_DEF() ;258 NSC_WRAPPERS_HANDLE_CMD_DEF() ;259 NSC_WRAPPERS_CLI_DEF() ;260 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() ;268 NSC_WRAP_DLL() 269 NSC_WRAPPERS_MAIN_DEF(LUAScript) 270 NSC_WRAPPERS_IGNORE_MSG_DEF() 271 NSC_WRAPPERS_HANDLE_CMD_DEF() 272 NSC_WRAPPERS_CLI_DEF() 273 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() -
modules/LUAScript/LUAScript.h
r53be5c8 rd6194a0 19 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 20 ***************************************************************************/ 21 NSC_WRAPPERS_MAIN(); 22 NSC_WRAPPERS_CLI(); 23 NSC_WRAPPERS_CHANNELS(); 21 NSC_WRAPPERS_MAIN() 22 NSC_WRAPPERS_CLI() 23 NSC_WRAPPERS_CHANNELS() 24 25 #include <boost/optional.hpp> 24 26 25 27 //#include <config.h> 26 28 #include <strEx.h> 27 29 #include <utils.h> 28 #include <checkHelpers.hpp>29 #include "script_wrapper.hpp"30 31 #include <boost/optional.hpp>32 33 30 #include <scripts/functions.hpp> 34 31 32 #include "script_wrapper.hpp" 35 33 36 34 class LUAScript : public nscapi::impl::simple_command_line_exec, public nscapi::impl::simple_submission_handler, public nscapi::impl::simple_plugin { -
modules/LUAScript/lua_wrappers.cpp
r53be5c8 rd6194a0 49 49 } 50 50 51 int lua_wrappers::lua_wrapper::gc(int what, int data) 52 { 53 return lua_gc(L, what, data); 54 } 55 51 56 NSCAPI::nagiosReturn lua_wrappers::lua_registry::on_query(const wchar_t* command, const std::string &request, std::string &response) { 52 57 function_map::iterator it = functions.find(command); … … 56 61 lua_wrapper lua(prep_function(c)); 57 62 if (c.simple) { 63 int args = 2; 64 if (c.obj_ref != 0) 65 args = 3; 58 66 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(command, request); 59 67 lua.push_string(command); 60 68 lua.push_array(data.args); 61 69 std::wstring msg, perf; 62 if (lua.pcall( 2, LUA_MULTRET, 0) != 0) {70 if (lua.pcall(args, LUA_MULTRET, 0) != 0) { 63 71 NSC_LOG_ERROR_STD(_T("Failed to handle command: ") + command + _T(": ") + lua.pop_string()); 64 72 return NSCAPI::returnUNKNOWN; … … 72 80 if (arg_count > 0) 73 81 ret = lua.pop_code(); 82 lua.gc(LUA_GCCOLLECT, 0); 74 83 nscapi::functions::create_simple_query_response(command, ret, msg, perf, response); 75 84 return ret; 76 85 } else { 86 int args = 2; 87 if (c.obj_ref != 0) 88 args = 3; 77 89 lua.push_string(command); 78 90 lua.push_raw_string(request); 79 if (lua.pcall( 2, LUA_MULTRET, 0) != 0) {91 if (lua.pcall(args, LUA_MULTRET, 0) != 0) { 80 92 NSC_LOG_ERROR_STD(_T("Failed to handle command: ") + command + _T(": ") + lua.pop_string()); 81 93 return NSCAPI::returnUNKNOWN; … … 84 96 if (arg_count > 1) 85 97 response = utf8::cvt<std::string>(lua.pop_string()); 98 lua.gc(LUA_GCCOLLECT, 0); 86 99 if (arg_count > 0) 87 100 return lua.pop_code(); … … 106 119 if (arg_count > 1) 107 120 result = lua.pop_string(); 121 lua.gc(LUA_GCCOLLECT, 0); 108 122 if (arg_count > 0) 109 123 return lua.pop_code(); … … 127 141 return NSCAPI::returnUNKNOWN; 128 142 } 143 lua.gc(LUA_GCCOLLECT, 0); 129 144 if (lua.size() > 0) 130 145 return lua.pop_code(); -
modules/LUAScript/lua_wrappers.hpp
r53be5c8 rd6194a0 11 11 #include <list> 12 12 13 14 #include <boost/weak_ptr.hpp> 13 15 #include <NSCAPI.h> 14 16 #include <nscapi/nscapi_core_wrapper.hpp> … … 31 33 } 32 34 inline lua_State* get_state() const { 33 int i =lua_gettop(L);35 lua_gettop(L); 34 36 return L; 35 37 } … … 46 48 lua_wrapper(lua_State *L) : L(L) {} 47 49 50 51 int append_path(const std::string &path) { 52 lua_getglobal(L, "package"); 53 lua_getfield(L, -1, "path"); 54 std::string cur_path = lua_tostring(L, -1); 55 cur_path.append(";"); 56 cur_path.append(path); 57 lua_pop(L, 1); 58 lua_pushstring(L, cur_path.c_str()); 59 lua_setfield(L, -2, "path"); 60 lua_pop(L, 1); 61 return 0; 62 } 48 63 ////////////////////////////////////////////////////////////////////////// 49 64 /// get_xxx … … 59 74 return _T("<NOT_A_STRING>"); 60 75 } 76 std::string get_sstring(int pos = -1) { 77 if (pos == -1) 78 pos = lua_gettop(L); 79 if (pos == 0) 80 return "<EMPTY>"; 81 if (is_string(pos)) 82 return lua_tostring(L, pos); 83 if (is_number(pos)) 84 return strEx::s::xtos(lua_tonumber(L, pos)); 85 return "<NOT_A_STRING>"; 86 } 61 87 bool get_string(std::wstring &str, int pos = -1) { 62 88 if (pos == -1) … … 68 94 else if (is_number(pos)) 69 95 str = strEx::itos(lua_tonumber(L, pos)); 96 else 97 return false; 98 return true; 99 } 100 bool get_string(std::string &str, int pos = -1) { 101 if (pos == -1) 102 pos = lua_gettop(L); 103 if (pos == 0) 104 return false; 105 if (is_string(pos)) 106 str = lua_tostring(L, pos); 107 else if (is_number(pos)) 108 str = strEx::s::xtos(lua_tonumber(L, pos)); 70 109 else 71 110 return false; … … 109 148 ////////////////////////////////////////////////////////////////////////// 110 149 /// pop_xxx 111 bool eanpop_boolean() {150 bool pop_boolean() { 112 151 int pos = lua_gettop(L); 113 152 if (pos == 0) … … 126 165 return ret; 127 166 } 167 std::string pop_sstring() { 168 std::string ret; 169 int top = lua_gettop(L); 170 if (top == 0) 171 return "<EMPTY>"; 172 ret = get_sstring(top); 173 pop(); 174 return ret; 175 } 128 176 bool pop_string(std::wstring &str) { 129 177 int top = lua_gettop(L); … … 135 183 return true; 136 184 } 137 bool pop_function (int &funref) {185 bool pop_function_ref(int &funref) { 138 186 int top = lua_gettop(L); 139 187 if (top == 0) … … 141 189 if (!is_function(top)) 142 190 return false; 191 funref = luaL_ref(L, LUA_REGISTRYINDEX); 192 if (funref == 0) 193 return false; 194 return true; 195 } 196 bool pop_instance_ref(int &funref) { 197 int top = lua_gettop(L); 198 if (top == 0) 199 return false; 200 // if (!is_function(top)) 201 // return false; 143 202 funref = luaL_ref(L, LUA_REGISTRYINDEX); 144 203 if (funref == 0) … … 263 322 lua_pushlstring(L, s.c_str(), s.size()); 264 323 } 265 void push_array( std::list<std::wstring> &arr) {324 void push_array(const std::list<std::wstring> &arr) { 266 325 lua_createtable(L, 0, arr.size()); 267 326 int i=0; … … 331 390 return luaL_checkstring(L, pos); 332 391 } 392 /* 333 393 std::wstring inline wstring(int pos) { 334 394 return utf8::cvt<std::wstring>(string(pos)); 335 395 } 396 */ 336 397 337 398 std::list<std::wstring> inline checkarray(int pos) { … … 340 401 } 341 402 342 bool eaninline checkbool(int pos) {403 bool inline checkbool(int pos) { 343 404 return lua_toboolean(L, pos); 344 405 } … … 349 410 return luaL_checkint(L, pos); 350 411 } 412 int gc(int what, int data); 351 413 }; 352 414 … … 390 452 , alias(alias) 391 453 , script(script) 392 {} 454 { 455 std::wcout << _T("+++"); 456 } 457 458 virtual ~lua_script_instance() { 459 std::wcout << _T("---"); 460 } 393 461 394 462 int get_plugin_id() const { … … 412 480 }; 413 481 414 class lua_registry {482 class lua_registry : boost::noncopyable { 415 483 struct function_container { 416 484 boost::shared_ptr<lua_script_instance> instance; 417 485 int func_ref; 486 int obj_ref; 418 487 bool simple; 419 488 }; … … 427 496 lua_State *L = c.instance->get_lua_state(); 428 497 lua_rawgeti(L, LUA_REGISTRYINDEX, c.func_ref); 498 if (c.obj_ref != 0) 499 lua_rawgeti(L, LUA_REGISTRYINDEX, c.obj_ref); 429 500 return L; 430 501 } 431 502 public: 503 lua_registry() {} 504 ~lua_registry() {} 505 432 506 433 507 NSCAPI::nagiosReturn on_query(const wchar_t* command, const std::string &request, std::string &response); … … 435 509 NSCAPI::nagiosReturn on_submission(const std::wstring channel, const std::wstring source, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); 436 510 437 void register_query(const std::wstring &command, boost::shared_ptr<lua_script_instance> instance, int func_ref, bool simple = true) {511 void register_query(const std::wstring &command, boost::shared_ptr<lua_script_instance> instance, int obj_ref, int func_ref, bool simple = true) { 438 512 function_container c; 439 513 c.func_ref = func_ref; 514 c.obj_ref = obj_ref; 440 515 c.instance = instance; 441 516 c.simple = simple; … … 476 551 class lua_instance_manager { 477 552 public: 478 typedef boost:: shared_ptr<lua_script_instance> script_instance_type;553 typedef boost::weak_ptr<lua_script_instance> script_instance_type; 479 554 typedef std::vector<script_instance_type> script_map_type; 480 555 private: 481 556 static script_map_type scripts; 482 557 public: 558 static void remove_script(script_instance_type script) { 559 // BOOST_FOREACH(script_instance_type &s, scripts) { 560 // if (s == script) { 561 // s.reset(); 562 // } 563 // } 564 } 483 565 static void set_script(lua_State *L, script_instance_type script) { 484 566 int index = 0; -
modules/LUAScript/script_wrapper.hpp
rc327ce5 rd6194a0 20 20 typedef lua_wrappers::lua_script_instance script_instance; 21 21 typedef lua_wrappers::lua_instance_manager instance_manager; 22 typedef boost::shared_ptr<lua_wrappers::lua_script_instance> script_instance_type; 22 23 23 24 … … 30 31 instance = instance_manager::get_script(L); 31 32 } 32 instance_manager::script_instance_type get_instance() { 33 if (!instance) 33 script_instance_type get_instance() { 34 script_instance_type inst = instance.lock(); 35 if (!inst) 34 36 throw lua_wrappers::LUAException("Invalid instance"); 35 return inst ance;37 return inst; 36 38 } 37 39 }; … … 94 96 lua_wrappers::lua_wrapper lua(L); 95 97 try { 96 int nargs = lua.size(); 97 std::wstring target = lua.wstring(1); 98 std::wstring command = lua.wstring(2); 99 std::list<std::wstring> arguments = lua.checkarray(3); 98 // simple_exec(target, command, arguments) 99 if (lua.size() > 1) 100 return lua.error("Incorrect syntax: simple_exec(target, command, arguments)"); 101 std::list<std::wstring> arguments = lua.pop_array(); 102 std::wstring command = lua.pop_string(); 103 std::wstring target = lua.pop_string(); 100 104 std::list<std::wstring> result; 101 105 NSCAPI::nagiosReturn ret = nscapi::core_helper::exec_simple_command(target, command, arguments, result); … … 115 119 lua_wrappers::lua_wrapper lua(L); 116 120 try { 117 int nargs = lua.size(); 118 std::wstring channel = lua.wstring(1); 119 std::wstring command = lua.wstring(2); 120 NSCAPI::nagiosReturn code = lua.get_code(3); 121 std::wstring message = lua.wstring(4); 122 std::wstring perf = lua.wstring(5); 121 // simple_submit(target, command, arguments) 122 if (lua.size() != 5) 123 return lua.error("Incorrect syntax: simple_submit(channel, command, code, message, perf)"); 124 std::wstring perf = lua.pop_string(); 125 std::wstring message = lua.pop_string(); 126 NSCAPI::nagiosReturn code = lua.pop_code(); 127 std::wstring command = lua.pop_string(); 128 std::wstring channel = lua.pop_string(); 123 129 std::wstring result; 124 130 NSCAPI::nagiosReturn ret = nscapi::core_helper::submit_simple_message(channel, command, code, message, perf, result); … … 143 149 module = lua.pop_string(); 144 150 get_instance()->get_core()->reload(module); 151 return 0; 152 } 153 int log(lua_State *L) { 154 lua_wrappers::lua_wrapper lua(L); 155 // log([level], message) 156 if (lua.size() > 2 || lua.size() < 1) 157 return lua.error("Incorrect syntax: log([<level>], <message>);"); 158 std::wstring level = _T("info"); 159 std::wstring message; 160 message = lua.pop_string(); 161 if (lua.size() > 0) 162 level = lua.pop_string(); 163 get_instance()->get_core()->log(nscapi::logging::parse(level), __FILE__, __LINE__, message); 145 164 return 0; 146 165 } … … 156 175 { "submit", &core_wrapper::submit }, 157 176 { "reload", &core_wrapper::reload }, 177 { "log", &core_wrapper::log }, 158 178 { 0 } 159 179 }; … … 169 189 static const Luna<registry_wrapper>::RegType methods[]; 170 190 171 boost::optional<int> read_registration(lua_wrapper &lua, std::wstring &command, int &funref, std::wstring &description) { 191 boost::optional<int> read_registration(lua_wrapper &lua, std::wstring &command, int &objref, int &funref, std::wstring &description) { 192 // ...(name, function, description) 193 // ...(name, instance, function, description) 172 194 std::wstring funname; 173 if (lua.size() != 2 && lua.size() != 3) 174 return lua.error("Invalid number of arguments: " + strEx::s::xtos(lua.size()) + " expected 2 or 3"); 175 if (lua.size() > 2 && !lua.pop_string(description)) 195 int count = lua.size(); 196 if (count < 2 && count > 4) 197 return lua.error("Invalid number of arguments: " + strEx::s::xtos(lua.size()) + " expected 2-4 arguments"); 198 if (count > 2 && !lua.pop_string(description)) { 176 199 return lua.error("Invalid description"); 200 } 177 201 if (lua.pop_string(funname)) { 178 202 lua.getglobal(funname); 179 203 } 180 if (!lua.pop_function (funref))204 if (!lua.pop_function_ref(funref)) 181 205 return lua.error("Invalid function"); 206 if (count > 3) { 207 if (!lua.pop_instance_ref(objref)) 208 return lua.error("Invalid object"); 209 } 182 210 if (!lua.pop_string(command)) 183 211 return lua.error("Invalid command"); … … 187 215 // void = (cmd, function, desc) 188 216 std::wstring command, description; 189 int funref = 0 ;190 lua_wrapper lua(L); 191 boost::optional<int> error = read_registration(lua, command, funref, description);217 int funref = 0, objref = 0; 218 lua_wrapper lua(L); 219 boost::optional<int> error = read_registration(lua, command, objref, funref, description); 192 220 if (error) 193 221 return *error; … … 196 224 description = _T("Lua script: ") + command; 197 225 get_instance()->get_core()->registerCommand(get_instance()->get_plugin_id(), command, description); 198 get_instance()->get_registry()->register_query(command, get_instance(), funref, false);226 get_instance()->get_registry()->register_query(command, get_instance(), objref, funref, false); 199 227 return 0; 200 228 } … … 202 230 // void = (cmd, function, desc) 203 231 std::wstring command, description; 204 int funref = 0 ;205 lua_wrapper lua(L); 206 boost::optional<int> error = read_registration(lua, command, funref, description);232 int funref = 0, objref = 0; 233 lua_wrapper lua(L); 234 boost::optional<int> error = read_registration(lua, command, objref, funref, description); 207 235 if (error) 208 236 return *error; … … 211 239 description = _T("Lua script: ") + command; 212 240 get_instance()->get_core()->registerCommand(get_instance()->get_plugin_id(), command, description); 213 get_instance()->get_registry()->register_query(command, get_instance(), funref, true);241 get_instance()->get_registry()->register_query(command, get_instance(), objref, funref, true); 214 242 return 0; 215 243 } … … 298 326 int get_string(lua_State *L) { 299 327 lua_wrapper lua(L); 300 std::wstring s = lua.wstring(1); 301 std::wstring k = lua.wstring(2); 302 std::wstring v = lua.op_wstring(3); 328 if (lua.size() != 3 && lua.size() != 2) 329 return lua.error("Invalid syntax: get_string(section, key, [value])"); 330 std::wstring v; 331 if (lua.size() > 2) 332 v = lua.pop_string(); 333 std::wstring k = lua.pop_string(); 334 std::wstring s = lua.pop_string(); 303 335 lua.push_string(get_instance()->get_core()->getSettingsString(s, k, v)); 304 336 return 1; … … 306 338 int set_string(lua_State *L) { 307 339 lua_wrapper lua(L); 308 std::wstring s = lua.wstring(1); 309 std::wstring k = lua.wstring(2); 310 std::wstring v = lua.wstring(3); 340 if (lua.size() != 3) 341 return lua.error("Invalid syntax: set_string(section, key, value)"); 342 std::wstring v = lua.pop_string(); 343 std::wstring k = lua.pop_string(); 344 std::wstring s = lua.pop_string(); 311 345 get_instance()->get_core()->SetSettingsString(s, k, v); 312 346 return 0; … … 314 348 int get_bool(lua_State *L) { 315 349 lua_wrapper lua(L); 316 std::wstring s = lua.wstring(1); 317 std::wstring k = lua.wstring(2); 318 bool v = lua.checkbool(3); 350 if (lua.size() != 3 && lua.size() != 2) 351 return lua.error("Invalid syntax: get_bool(section, key, [value])"); 352 bool v = false; 353 if (lua.size() > 2) 354 v = lua.pop_boolean(); 355 std::wstring k = lua.pop_string(); 356 std::wstring s = lua.pop_string(); 319 357 lua.push_boolean(get_instance()->get_core()->getSettingsInt(s, k, v?1:0)==1); 320 358 return 1; … … 322 360 int set_bool(lua_State *L) { 323 361 lua_wrapper lua(L); 324 std::wstring s = lua.wstring(1); 325 std::wstring k = lua.wstring(2); 326 bool v = lua.checkbool(3); 362 if (lua.size() != 3) 363 return lua.error("Invalid syntax: set_bool(section, key, value)"); 364 bool v = lua.pop_boolean(); 365 std::wstring k = lua.pop_string(); 366 std::wstring s = lua.pop_string(); 327 367 get_instance()->get_core()->SetSettingsInt(s, k, v?1:0); 328 368 return 0; … … 330 370 int get_int(lua_State *L) { 331 371 lua_wrapper lua(L); 332 std::wstring s = lua.wstring(1); 333 std::wstring k = lua.wstring(2); 334 int v = lua.checkint(3); 372 if (lua.size() != 3 && lua.size() != 2) 373 return lua.error("Invalid syntax: get_int(section, key, [value])"); 374 int v = 0; 375 if (lua.size() > 2) 376 v = lua.pop_int(); 377 std::wstring k = lua.pop_string(); 378 std::wstring s = lua.pop_string(); 335 379 lua.push_int(get_instance()->get_core()->getSettingsInt(s, k, v)); 336 380 return 1; … … 338 382 int set_int(lua_State *L) { 339 383 lua_wrapper lua(L); 340 std::wstring s = lua.wstring(1); 341 std::wstring k = lua.wstring(2); 342 int v = lua.checkint(3); 384 if (lua.size() != 3) 385 return lua.error("Invalid syntax: set_int(section, key, value)"); 386 int v = lua.pop_int(); 387 std::wstring k = lua.pop_string(); 388 std::wstring s = lua.pop_string(); 343 389 get_instance()->get_core()->SetSettingsInt(s, k, v); 344 390 return 0; … … 350 396 int register_path(lua_State *L) { 351 397 lua_wrapper lua(L); 352 std::wstring path = lua.wstring(1); 353 std::wstring title = lua.wstring(1); 354 std::wstring description = lua.wstring(1); 398 if (lua.size() != 3) 399 return lua.error("Invalid syntax: register_path(path, title, description)"); 400 std::wstring description = lua.pop_string(); 401 std::wstring title = lua.pop_string(); 402 std::wstring path = lua.pop_string(); 355 403 get_instance()->get_core()->settings_register_path(path, title, description, false); 356 404 return 0; 357 405 } 358 NSCAPI::settings_type script_wrapper::settings_wrapper::get_type(std::string stype) {406 NSCAPI::settings_type get_type(std::string stype) { 359 407 if (stype == "string" || stype == "str" || stype == "s") 360 408 return NSCAPI::key_string; … … 369 417 int register_key(lua_State *L) { 370 418 lua_wrapper lua(L); 371 std::wstring path = lua.wstring(1); 372 std::wstring key = lua.wstring(1); 373 std::string stype = lua.string(1); 374 NSCAPI::settings_type type = get_type(stype); 375 std::wstring title = lua.wstring(1); 376 std::wstring description = lua.wstring(1); 377 std::wstring defaultValue = lua.wstring(1); 419 420 if (lua.size() != 5) 421 return lua.error("Invalid syntax: register_key(path, key, type, title, description, default)"); 422 std::wstring defaultValue = lua.pop_string(); 423 std::wstring description = lua.pop_string(); 424 std::wstring title = lua.pop_string(); 425 NSCAPI::settings_type type = get_type(lua.pop_sstring()); 426 std::wstring key = lua.pop_string(); 427 std::wstring path = lua.pop_string(); 378 428 get_instance()->get_core()->settings_register_key(path, key, type, title, description, defaultValue, false); 379 429 return 0; … … 463 513 464 514 class lua_script : public script_instance, public boost::enable_shared_from_this<lua_script> { 465 lua_script(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::string alias, const std::string script) 466 : script_instance(core, plugin_id, registry, alias, script) {} 515 std::string base_path_; 516 lua_script(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::string alias, const std::string base_path, const std::string script) 517 : script_instance(core, plugin_id, registry, alias, script), base_path_(base_path) { 518 std::wcout << _T("AAA"); 519 } 467 520 public: 468 469 static boost::shared_ptr<lua_script> create_instance(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::wstring alias, const std::wstring script) { 470 boost::shared_ptr<lua_script> instance(new lua_script(core, plugin_id, registry, utf8::cvt<std::string>(alias), utf8::cvt<std::string>(script))); 521 virtual ~lua_script() { 522 std::wcout << _T("XXX"); 523 } 524 525 static boost::shared_ptr<lua_script> create_instance(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::wstring alias, const std::wstring base_path, const std::wstring script) { 526 boost::shared_ptr<lua_script> instance(new lua_script(core, plugin_id, registry, utf8::cvt<std::string>(alias), utf8::cvt<std::string>(base_path), utf8::cvt<std::string>(script))); 471 527 if (instance) { 472 instance->init();473 528 instance->load(); 474 529 } 475 530 return instance; 476 531 } 477 void init() { 532 533 void load() { 534 std::wcout << _T("lll"); 478 535 lua_wrappers::lua_instance_manager::set_script(get_lua_state(), shared_from_this()); 479 }480 481 void load() {482 536 lua_wrappers::lua_wrapper lua(get_lua_state()); 483 537 lua.openlibs(); 484 538 nsclient_wrapper::luaopen(get_lua_state()); 539 lua.append_path(base_path_ + "\\scripts\\lua\\lib\\?.lua;" + base_path_ + "scripts\\lua\\?;"); 485 540 if (lua.loadfile(get_script()) != 0) 486 541 throw lua_wrappers::LUAException(_T("Failed to load script: ") + get_wscript() + _T(": ") + lua.pop_string()); 487 542 if (lua.pcall(0, 0, 0) != 0) 488 543 throw lua_wrappers::LUAException(_T("Failed to execute script: ") + get_wscript() + _T(": ") + lua.pop_string()); 544 std::wcout << _T("LLL"); 489 545 } 490 546 std::wstring get_wscript() const { 491 547 return utf8::cvt<std::wstring>(get_script()); 492 548 } 493 void unload() {} 549 void unload() { 550 std::wcout << _T("uuu"); 551 lua_wrappers::lua_wrapper lua(get_lua_state()); 552 lua.gc(LUA_GCCOLLECT, 0); 553 lua_wrappers::lua_instance_manager::remove_script(shared_from_this()); 554 std::wcout << _T("UUU"); 555 std::wcout << shared_from_this().use_count(); 556 } 494 557 void reload() { 495 558 unload(); -
modules/NRPEClient/NRPEClient.cpp
ra48fd4c rd6194a0 298 298 299 299 } 300 virtual ~client_handler() {} 300 301 void log_debug(std::string file, int line, std::string msg) const { 301 302 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { … … 323 324 socket_helpers::client::client<nrpe::client::protocol> client(boost::shared_ptr<client_handler>(new client_handler(con))); 324 325 client.connect(); 325 packet= client.process_request(packet);326 nrpe::packet response = client.process_request(packet); 326 327 client.shutdown(); 327 return boost::make_tuple(static_cast<int>( packet.getResult()), packet.getPayload());328 return boost::make_tuple(static_cast<int>(response.getResult()), response.getPayload()); 328 329 } catch (nrpe::nrpe_packet_exception &e) { 329 330 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("NRPE Packet errro: ") + e.wwhat()); -
scripts/CMakeLists.txt
rc327ce5 rd6194a0 10 10 #FILE (GLOB scripts_PYT "python/*.py" "python/lib/*.py") 11 11 #ENDIF(WIN32) 12 FILE (GLOB scripts_LUA "lua/*.lua")12 FILE (GLOB_RECURSE scripts_LUA "lua/*.lua") 13 13 14 14 SET(script_ALL ${scripts_BAT} ${scripts_VBS} ${scripts_PS1}) … … 20 20 get_filename_component(filename ${file} NAME) 21 21 #MESSAGE(STATUS " + ${filename} (${file})") 22 copy_single_file( copy_scripts${filename} scripts)22 copy_single_file(ALL_FILES ${filename} scripts) 23 23 ENDFOREACH(file ${script_ALL}) 24 24 … … 27 27 get_filename_component(filename ${file} NAME) 28 28 #MESSAGE(STATUS " + lib - ${filename}") 29 copy_single_file( copy_scriptslib/${filename} scripts/lib)29 copy_single_file(ALL_FILES lib/${filename} scripts/lib) 30 30 ENDFOREACH(file ${scripts_LIB}) 31 31 … … 36 36 STRING(REPLACE "/" "_" alias "${relpath}") 37 37 STRING(REPLACE "." "_" alias "${alias}") 38 MESSAGE(STATUS " + python - ${filename} - ${relpath} - ${alias}")39 copy_single_file( copy_scripts${relpath}/${filename} scripts/${relpath})38 #MESSAGE(STATUS " + python - ${filename} - ${relpath} - ${alias}") 39 copy_single_file(ALL_FILES ${relpath}/${filename} scripts/${relpath}) 40 40 ENDFOREACH(file ${scripts_PYT}) 41 41 42 42 FOREACH(file ${scripts_LUA}) 43 43 get_filename_component(filename ${file} NAME) 44 #MESSAGE(STATUS " + lua - ${filename}") 45 copy_single_file(copy_scripts lua/${filename} scripts/lua) 44 get_filename_component(filepath ${file} PATH) 45 file(RELATIVE_PATH relpath ${CMAKE_CURRENT_SOURCE_DIR} "${filepath}") 46 STRING(REPLACE "/" "_" alias "${relpath}") 47 STRING(REPLACE "." "_" alias "${alias}") 48 #MESSAGE(STATUS " + lua - ${filename} - ${relpath} - ${alias}") 49 copy_single_file(ALL_FILES ${relpath}/${filename} scripts/${relpath}) 46 50 ENDFOREACH(file ${scripts_LUA}) 47 51 -
scripts/lua/test_nrpe.lua
r53be5c8 rd6194a0 1 valid_chars = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 2 "0","1","2","3","4","5","6","7","8","9","-"} 3 4 math.randomseed(os.time()) 5 6 function random(len) -- args: smallest and largest possible password lengths, inclusive 7 pass = {} 8 for z = 1,len do 9 case = math.random(1,2) 10 a = math.random(1,#valid_chars) 11 if case == 1 then 12 x=string.upper(valid_chars[a]) 13 elseif case == 2 then 14 x=string.lower(valid_chars[a]) 15 end 16 table.insert(pass, x) 17 end 18 return(table.concat(pass)) 19 end 20 string.random = random 21 22 function status_to_int(status) 23 if status == 'ok' then 24 return 0 25 elseif status == 'warn' then 26 return 1 27 elseif status == 'crit' then 28 return 2 29 elseif status == 'unknown' then 30 return 3 31 else 32 print("Unknown status: "..status) 33 return 3 34 end 35 end 36 37 TestResult = { status = true; children = {} } 38 function TestResult:new(o) 39 o = o or {} 40 o["children"] = o["children"] or {} 41 if o["status"] == nil then o["status"] = true end 42 setmetatable(o, self) 43 self.__index = self 44 return o 45 46 end 47 function TestResult:add(result) 48 if not result.status then self.status = false end 49 table.insert(self.children,result) 50 end 51 function TestResult:add_message(result, message) 52 table.insert(self.children,TestResult:new{status=status, message=message}) 53 end 54 function TestResult:assert_equals(a, b, message) 55 if a==b then 56 table.insert(self.children,TestResult:new{status=true, message=message}) 57 else 58 table.insert(self.children,TestResult:new{status=false, message=message..': '..tostring(a)..' != '..tostring(b)}) 59 end 60 end 61 62 63 function TestResult:print(indent) 64 indent = indent or 0 65 pad = string.rep(' ', indent) 66 if self.status then 67 print(pad .. "[OK ] - " .. self.message) 68 else 69 print(pad .. "[ERR] - " .. self.message) 70 end 71 if # self.children > 0 then 72 for i,v in ipairs(self.children) do v:print(indent+2) end 73 end 74 end 75 76 function TestResult:print_failed(indent) 77 indent = indent or 0 78 pad = string.rep(' ', indent) 79 if not self.status then 80 print(pad .. "[ERR] - " .. self.message) 81 end 82 if # self.children > 0 then 83 for i,v in ipairs(self.children) do v:print(indent+2) end 84 end 85 end 86 87 function TestResult:count() 88 local ok = 0 89 local err = 0 90 if self.status then 91 ok = ok + 1 92 else 93 err = err + 1 94 end 95 if # self.children > 0 then 96 for i,v in ipairs(self.children) do 97 local lok, lerr = v:count() 98 ok = ok + lok 99 err = err + lerr 100 end 101 end 102 return ok, err 103 end 104 105 106 107 function TestResult:get_nagios() 108 local ok, err = self:count() 109 if not self.status then 110 return 'crit', tostring(err)..' test cases failed', '' 111 else 112 return 'ok', tostring(ok)..' test cases succeded', '' 113 end 114 end 115 1 test = require("test_helper") 116 2 117 3 TestMessage = { … … 150 36 function TestNRPE:setup() 151 37 local reg = Registry(plugin_id) 152 reg:simple_query('check_py_nrpe_test_s', self.simple_handler, 'TODO') 153 reg:query('check_py_nrpe_test', self.handler, 'TODO') 38 reg:simple_query('check_py_nrpe_test_s', self, self.simple_handler, 'TODO') 39 reg:query('check_py_nrpe_test', self, self.handler, 'TODO') 40 end 41 function TestNRPE:teardown() 154 42 end 155 43 … … 208 96 end 209 97 210 function TestNRPE .simple_handler(command, args)211 msg = instance:get_response(args[0])98 function TestNRPE:simple_handler(command, args) 99 msg = self:get_response(args[0]) 212 100 msg.got_simple_response = true 213 instance:set_response(msg)214 rmsg = instance:get_request(args[0])101 self:set_response(msg) 102 rmsg = self:get_request(args[0]) 215 103 return rmsg.status, rmsg.message, rmsg.perfdata 216 104 end 217 105 218 function TestNRPE .handler(req)219 msg = instance:get_response(args[0])106 function TestNRPE:handler(req) 107 msg = self:get_response(args[0]) 220 108 msg.got_response = true 221 instance:set_response(msg)222 rmsg = instance:get_request(args[0])109 self:set_response(msg) 110 rmsg = self:get_request(args[0]) 223 111 end 224 112 225 113 function TestNRPE:submit_payload(tag, ssl, length, source, status, message, perf, target) 226 114 local core = Core() 227 local result = TestResult:new{message='Testing NRPE: '..tag..' for '..target}115 local result = test.TestResult:new{message='Testing NRPE: '..tag..' for '..target} 228 116 229 117 local msg = protobuf.Plugin.QueryRequestMessage.new() … … 270 158 result:add_message(response_message:size_payload() == 1, 'Verify that we only get one payload response for '..tag) 271 159 pl = response_message:get_payload(1) 272 result:assert_equals(pl:get_result(), status_to_int(status), 'Verify that status is sent through '..tag)160 result:assert_equals(pl:get_result(), test.status_to_int(status), 'Verify that status is sent through '..tag) 273 161 result:assert_equals(pl:get_message(), rmsg.message, 'Verify that message is sent through '..tag) 274 162 --#result.assert_equals(rmsg.perfdata, perf, 'Verify that performance data is sent through') … … 290 178 function TestNRPE:test_one(ssl, length, status) 291 179 tag = string.format("%s/%d/%s", tostring(ssl), length, status) 292 result =TestResult:new{message=string.format('Testing: %s with various targets', tag)}180 local result = test.TestResult:new{message=string.format('Testing: %s with various targets', tag)} 293 181 for k,t in pairs({'valid', 'test_rp', 'invalid'}) do 294 182 result:add(self:submit_payload(tag, ssl, length, tag .. 'src' .. tag, status, tag .. 'msg' .. tag, '', t)) … … 321 209 core:reload('test_nrpe_client') 322 210 323 result =TestResult:new{message="Testing "..tostring(ssl)..", "..tostring(length)}211 local result = test.TestResult:new{message="Testing "..tostring(ssl)..", "..tostring(length)} 324 212 result:add(self:test_one(ssl, length, 'unknown')) 325 213 result:add(self:test_one(ssl, length, 'ok')) … … 331 219 332 220 function TestNRPE:run() 333 local result = TestResult:new{message="NRPE Test Suite"}221 local result = test.TestResult:new{message="NRPE Test Suite"} 334 222 result:add(self:do_one_test(true, 1024)) 335 223 result:add(self:do_one_test(false, 1024)) … … 341 229 342 230 343 function lua_unittest_handler(command, args) 344 result = instance:setup() 345 result = instance:run() 346 print "--" 347 result:print() 348 print "--" 349 result:print_failed() 350 print "--" 351 return result:get_nagios() 352 end 353 function install_test_manager() 354 instance:install({}) 355 local reg = Registry(plugin_id) 356 reg:simple_query('lua_unittest', lua_unittest_handler, 'TODO') 357 end 358 359 instance = TestNRPE 360 install_test_manager() 231 instances = { TestNRPE } 232 test.install_test_manager(instances) -
service/NSClient++.cpp
r53be5c8 rd6194a0 263 263 } 264 264 265 NSClientT::~NSClientT() { 266 try { 267 nsclient::logging::logger::destroy(); 268 } catch(...) { 269 std::wcerr << _T("UNknown exception raised: When destroying logger") << std::endl; 270 } 271 } 272 265 273 266 274 NSClientT::plugin_alias_list_type NSClientT::find_all_plugins(bool active) { … … 752 760 } 753 761 commands_.remove_all(); 762 channels_.remove_all(); 763 routers_.remove_all(); 754 764 plugins_.clear(); 755 765 } -
service/NSClient++.h
r53be5c8 rd6194a0 103 103 // c-tor, d-tor 104 104 NSClientT(); 105 virtual ~NSClientT() {}105 virtual ~NSClientT(); 106 106 107 107 // Service helper functions -
service/cli_parser.hpp
r53be5c8 rd6194a0 310 310 if (vm.count("run")) { 311 311 try { 312 mainClient.start_and_wait(name);312 core_->start_and_wait(name); 313 313 } catch (...) { 314 314 get_logger()->error(__FILE__, __LINE__, _T("Unknown exception in service")); … … 544 544 } 545 545 if (args.mode == client_arguments::query) { 546 ret = mainClient.simple_query(args.module, args.command, args.arguments, resp);546 ret = core_->simple_query(args.module, args.command, args.arguments, resp); 547 547 } else if (args.mode == client_arguments::exec || args.mode == client_arguments::combined) { 548 548 ret = mainClient.simple_exec(args.command, args.arguments, resp); … … 551 551 std::wcout << _T("Command not found (by module): ") << args.command << std::endl; 552 552 resp.push_back(_T("Command not found: ") + args.command); 553 mainClient.simple_exec(_T("help"), args.arguments, resp);553 core_->simple_exec(_T("help"), args.arguments, resp); 554 554 } else if (args.mode == client_arguments::combined) { 555 555 if (ret == NSCAPI::returnOK) { 556 mainClient.reload(_T("service"));557 ret = mainClient.simple_query(args.module, args.combined_query, args.arguments, resp);556 core_->reload(_T("service")); 557 ret = core_->simple_query(args.module, args.combined_query, args.arguments, resp); 558 558 } else { 559 559 std::wcerr << _T("Failed to execute command, will not attempt query") << std::endl; … … 565 565 std::wcerr << _T("Need to specify one of --exec, --query or --submit") << std::endl; 566 566 } 567 mainClient.stop_unload_plugins_pre();568 mainClient.stop_exit_pre();569 mainClient.stop_exit_post();567 core_->stop_unload_plugins_pre(); 568 core_->stop_exit_pre(); 569 core_->stop_exit_post(); 570 570 571 571 BOOST_FOREACH(std::wstring r, resp) { -
service/logger_impl.cpp
ra48fd4c rd6194a0 115 115 116 116 117 void do_log(const std::string &data) {117 void do_log(const std::string data) { 118 118 if (file_.empty()) 119 119 return; … … 217 217 simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") {} 218 218 219 void do_log(const std::string &data) {219 void do_log(const std::string data) { 220 220 if (get_console_log()) { 221 221 std::wcout << render_console_message(data); … … 274 274 } 275 275 276 void do_log(const std::string &data) {276 void do_log(const std::string data) { 277 277 if (get_console_log()) { 278 278 std::wcout << render_console_message(data); … … 325 325 return false; 326 326 } 327 background_logger_->shutdown(); 327 328 return nsclient::logging::logging_interface_impl::shutdown(); 328 329 } catch (const std::exception &e) {
Note: See TracChangeset
for help on using the changeset viewer.








