Changeset 40970de in nscp
- Timestamp:
- 02/11/10 19:44:30 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 47bcf6f
- Parents:
- 1d4878e
- Files:
-
- 11 added
- 1 deleted
- 30 edited
- 5 moved
-
CMakeLists.txt (modified) (3 diffs)
-
include/NSCHelper.cpp (modified) (5 diffs)
-
include/NSCHelper.h (modified) (3 diffs)
-
include/file/file_finder.cpp (added)
-
include/file/file_finder.hpp (added)
-
include/filter_framework.hpp (modified) (1 diff)
-
include/nrpe/nrpe_packet.cpp (moved) (moved from include/nrpe/nrpepacket.cpp) (1 diff)
-
include/nrpe/nrpe_packet.hpp (moved) (moved from include/nrpe/nrpepacket.hpp) (9 diffs)
-
include/nrpe/nrpe_socket.cpp (added)
-
include/nrpe/nrpe_socket.hpp (added)
-
include/nsc_module_wrapper.hpp (modified) (2 diffs)
-
include/nsca/nsca_enrypt.hpp (added)
-
include/nsca/nsca_packet.hpp (added)
-
include/nsca/nsca_socket.hpp (added)
-
include/socket_helpers.hpp (modified) (1 diff)
-
include/strEx.h (modified) (5 diffs)
-
include/swap_bytes.hpp (added)
-
libs/cryptopp/CMakeLists.txt (added)
-
libs/protobuf/CMakeLists.txt (moved) (moved from proto/CMakeLists.txt) (1 diff)
-
libs/protobuf/plugin.proto (moved) (moved from proto/plugin.proto)
-
libs/protobuf/plugin.proto.h.in (moved) (moved from proto/plugin.proto.h.in)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (2 diffs)
-
modules/NRPEClient/CMakeLists.txt (modified) (2 diffs)
-
modules/NRPEClient/NRPEClient.cpp (modified) (4 diffs)
-
modules/NRPEClient/NRPEClient.h (modified) (2 diffs)
-
modules/NRPEServer/CMakeLists.txt (modified) (2 diffs)
-
modules/NRPEServer/nrpe_connection.cpp (modified) (1 diff)
-
modules/NRPEServer/nrpe_handler.hpp (modified) (1 diff)
-
modules/NRPEServer/nrpe_parser.hpp (modified) (3 diffs)
-
modules/NRPEServer/stdafx.h (modified) (1 diff)
-
modules/NSCAAgent/CMakeLists.txt (added)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (6 diffs)
-
modules/NSCAAgent/NSCAAgent.def (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent.h (modified) (2 diffs)
-
modules/NSCAAgent/NSCAThread.cpp (modified) (3 diffs)
-
modules/NSCAAgent/NSCAThread.h (modified) (4 diffs)
-
modules/NSCAAgent/nsca_enrypt.hpp (deleted)
-
modules/NSCAAgent/stdafx.h (modified) (3 diffs)
-
modules/Scheduler/Scheduler.cpp (modified) (1 diff)
-
service/CMakeLists.txt (modified) (1 diff)
-
service/NSCPlugin.cpp (modified) (4 diffs)
-
service/NSCPlugin.h (modified) (3 diffs)
-
service/NSClient++.cpp (modified) (5 diffs)
-
service/NSClient++.h (modified) (4 diffs)
-
service/channels.hpp (added)
-
service/core_api.cpp (modified) (1 diff)
-
service/core_api.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r920626f r40970de 26 26 27 27 SET(NSCP_INCLUDE_PATH "${NSCP_SOURCE_DIR}/include" CACHE PATH "directory containing NSCP specific includes") 28 SET(PB_PATH "${NSCP_SOURCE_DIR}/proto" CACHE PATH "directory containing NSCP specific protocol buffer files")28 #SET(PB_PATH "${NSCP_SOURCE_DIR}/proto" CACHE PATH "directory containing NSCP specific protocol buffer files") 29 29 INCLUDE_DIRECTORIES(${NSCP_INCLUDE_PATH}) 30 INCLUDE_DIRECTORIES(${PB_PATH})30 #INCLUDE_DIRECTORIES(${PB_PATH}) 31 31 32 32 SET(BOOST_LIBRARYDIR ${BOOST_LIBRARYDIR} CACHE PATH "") … … 169 169 ${EXTRA_LIBS} 170 170 ${PROTOBUF_LIBRARY} 171 proto 172 ) 173 message(STATUS, "LIB: ${NSCP_DEF_PLUGIN_LIB}") 174 171 protobuf 172 ) 173 message(STATUS, "LIB: ${NSCP_DEF_PLUGIN_LIB}") 174 175 176 SET(ALL_LIB_NAMES) 177 FILE(GLOB ALL_LIB_PROJECTS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "libs/*/CMakeLists.txt") 178 foreach(CURRENT_LIB ${ALL_LIB_PROJECTS}) 179 get_filename_component(CURRENT_LIB_PATH ${CURRENT_LIB} PATH) 180 get_filename_component(CURRENT_LIB_NAME ${CURRENT_LIB_PATH} NAME) 181 message(STATUS "Adding library: ${CURRENT_LIB_PATH} (${CURRENT_LIB_NAME})") 182 ADD_SUBDIRECTORY("${CURRENT_LIB_PATH}") 183 SET(ALL_LIB_NAMES ${ALL_LIB_NAMES} ${CURRENT_LIB_NAME}) 184 endforeach(CURRENT_LIB ${ALL_LIB_PROJECTS}) 185 175 186 176 187 # Compile time constants & make sure our build finds it … … 189 200 MESSAGE(STATUS "Build path: ${PROJECT_BINARY_DIR}") 190 201 ADD_SUBDIRECTORY("service") 191 ADD_SUBDIRECTORY("proto")192 202 193 203 SET(ALL_MODULE_NAMES) -
include/NSCHelper.cpp
rc0d7e82 r40970de 358 358 } 359 359 360 NSCAPI::errorReturn NSCModuleHelper::NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std:: wstring message, std::wstring perf) {360 NSCAPI::errorReturn NSCModuleHelper::NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::string result) { 361 361 if (!fNSAPINotify) 362 362 throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 363 return fNSAPINotify(channel.c_str(), command.c_str(), code, message.c_str(), perf.c_str());363 return fNSAPINotify(channel.c_str(), command.c_str(), code, result.c_str(), result.size()); 364 364 } 365 365 … … 422 422 throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 423 423 424 425 PluginCommand::RequestMessage message; 426 PluginCommand::Header *hdr = message.mutable_header(); 427 hdr->set_type(PluginCommand::Header_Type_REQUEST); 428 hdr->set_version(PluginCommand::Header_Version_VERSION_1); 429 430 PluginCommand::Request *req = message.add_payload(); 431 req->set_command(to_string(command)); 432 req->set_version(PluginCommand::Request_Version_VERSION_1); 433 434 BOOST_FOREACH(std::wstring s, argument) 435 req->add_arguments(to_string(s)); 436 437 std::string request; 438 message.SerializeToString(&request); 439 440 char *buffer = NULL; 441 unsigned int buffer_size = 0; 442 443 NSCAPI::nagiosReturn retC = InjectCommandRAW(command.c_str(), request.c_str(), request.size(), &buffer, &buffer_size); 444 445 if (buffer_size > 0 && buffer != NULL) { 424 std::string response; 425 NSCAPI::nagiosReturn ret = InjectCommand(command, argument, response); 426 if (!response.empty()) { 446 427 PluginCommand::ResponseMessage rsp_msg; 447 std::string response(buffer, buffer_size);448 428 rsp_msg.ParseFromString(response); 449 429 if (rsp_msg.payload_size() != 1) { … … 452 432 } 453 433 msg = to_wstring(rsp_msg.payload(0).message()); 434 } 435 return ret; 436 } 437 /** 438 * Inject a request command in the core (this will then be sent to the plug-in stack for processing) 439 * @param command Command to inject (password should not be included. 440 * @param argLen The length of the argument buffer 441 * @param **argument The argument buffer 442 * @param message The return message buffer 443 * @param perf The return performance data buffer 444 * @return The return of the command 445 */ 446 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommand(const std::wstring command, const std::list<std::wstring> argument, std::string & result) 447 { 448 if (!fNSAPIInject) 449 throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 450 451 452 PluginCommand::RequestMessage message; 453 PluginCommand::Header *hdr = message.mutable_header(); 454 hdr->set_type(PluginCommand::Header_Type_REQUEST); 455 hdr->set_version(PluginCommand::Header_Version_VERSION_1); 456 457 PluginCommand::Request *req = message.add_payload(); 458 req->set_command(to_string(command)); 459 req->set_version(PluginCommand::Request_Version_VERSION_1); 460 461 BOOST_FOREACH(std::wstring s, argument) 462 req->add_arguments(to_string(s)); 463 464 std::string request; 465 message.SerializeToString(&request); 466 467 char *buffer = NULL; 468 unsigned int buffer_size = 0; 469 470 NSCAPI::nagiosReturn retC = InjectCommandRAW(command.c_str(), request.c_str(), request.size(), &buffer, &buffer_size); 471 472 if (buffer_size > 0 && buffer != NULL) { 473 PluginCommand::ResponseMessage rsp_msg; 474 result = std::string(buffer, buffer_size); 454 475 } 455 476 … … 944 965 */ 945 966 NSCAPI::boolReturn NSCModuleWrapper::wrapHasCommandHandler(bool has) { 946 if (has) 947 return NSCAPI::istrue; 948 return NSCAPI::isfalse; 967 return has?NSCAPI::istrue:NSCAPI::isfalse; 949 968 } 950 969 /** … … 954 973 */ 955 974 NSCAPI::boolReturn NSCModuleWrapper::wrapHasMessageHandler(bool has) { 956 if (has) 957 return NSCAPI::istrue; 958 return NSCAPI::isfalse; 959 } 975 return has?NSCAPI::istrue:NSCAPI::isfalse; 976 } 977 NSCAPI::boolReturn NSCModuleWrapper::wrapHasNotificationHandler(bool has) { 978 return has?NSCAPI::istrue:NSCAPI::isfalse; 979 } 980 981 NSCAPI::nagiosReturn NSCModuleWrapper::wrapHandleNotification(NSCAPI::nagiosReturn retResult) { 982 return retResult; 983 } 984 960 985 /** 961 986 * Wrap the HandleCommand call -
include/NSCHelper.h
rc0d7e82 r40970de 140 140 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 141 141 typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 142 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t* command, const char *request, const unsigned int request_len, char **response, unsigned int *response_len);142 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const char *, const unsigned int, char **, unsigned int *); 143 143 typedef void (*lpNSAPIDestroyBuffer)(char**); 144 144 145 typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const wchar_t*, const wchar_t*);145 typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 146 146 147 147 typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); … … 177 177 NSCAPI::nagiosReturn InjectCommandRAW(const wchar_t* command, const char *request, const unsigned int request_len, char **response, unsigned int *response_len); 178 178 void DestroyBuffer(char**buffer); 179 NSCAPI::nagiosReturn InjectCommand(const std::wstring command, const std::list<std::wstring> argument, std::string & result); 179 180 NSCAPI::nagiosReturn InjectSimpleCommand(const std::wstring command, const std::list<std::wstring> argument, std::wstring & message, std::wstring & perf); 180 NSCAPI::errorReturn NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std:: wstring message, std::wstring perf);181 NSCAPI::errorReturn NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::string result); 181 182 NSCAPI::nagiosReturn InjectSplitAndCommand(const wchar_t* command, wchar_t* buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf); 182 183 NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf, bool escape = false); … … 201 202 202 203 204 class SimpleNotificationHandler { 205 public: 206 NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, std::string result) { 207 try { 208 PluginCommand::ResponseMessage message; 209 message.ParseFromString(result); 210 if (message.payload_size() != 1) { 211 //NSC_LOG_ERROR_STD(_T("Unsupported payload size: ") + to_wstring(request_message.payload_size())); 212 return NSCAPI::returnIgnored; 213 } 214 215 ::PluginCommand::Response payload = message.payload().Get(0); 216 std::list<std::wstring> args; 217 for (int i=0;i<payload.arguments_size();i++) { 218 args.push_back(to_wstring(payload.arguments(i))); 219 } 220 std::wstring msg = to_wstring(payload.message()), perf; 221 NSCAPI::nagiosReturn ret = handleSimpleNotification(channel, command, code, msg, perf); 222 } catch (std::exception &e) { 223 std::cout << "Failed to parse data from: " << strEx::strip_hex(result) << e.what() << std::endl;; 224 } catch (...) { 225 std::cout << "Failed to parse data from: " << strEx::strip_hex(result) << std::endl;; 226 } 227 228 return -1; 229 } 230 virtual NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf) = 0; 231 232 }; 233 203 234 class SimpleCommand { 204 235 -
include/filter_framework.hpp
rf0e6036 r40970de 51 51 static bool filter(std::wstring filter, std::wstring str) { 52 52 return str == filter; 53 } 54 }; 55 struct not_string_filter { 56 static bool filter(std::wstring filter, std::wstring str) { 57 return !(str == filter); 53 58 } 54 59 }; -
include/nrpe/nrpe_packet.cpp
r9b3f53c r40970de 21 21 #include <strEx.h> 22 22 #include <utils.h> 23 #include <nrpe/nrpe packet.hpp>23 #include <nrpe/nrpe_packet.hpp> 24 24 25 25 //unsigned int nrpe::length::payload_length_ = 980; -
include/nrpe/nrpe_packet.hpp
r79e734f r40970de 25 25 #include <unicode_char.hpp> 26 26 #include <boost/asio/buffer.hpp> 27 27 #include <swap_bytes.hpp> 28 28 29 29 namespace nrpe { 30 // this function swap the bytes of values given it's size as a template31 // parameter (could sizeof be used?).32 template <class T, unsigned int size>33 inline T SwapBytes(T value) {34 union {35 T value;36 char bytes[size];37 } in, out;38 39 in.value = value;40 41 for (unsigned int i = 0; i < size / 2; ++i) {42 out.bytes[i] = in.bytes[size - 1 - i];43 out.bytes[size - 1 - i] = in.bytes[i];44 }45 46 return out.value;47 }48 49 template<EEndian from, EEndian to, class T>50 inline T EndianSwapBytes(T value) {51 BOOST_STATIC_ASSERT(sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8);52 BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);53 if (from == to)54 return value;55 return SwapBytes<T, sizeof(T)>(value);56 }57 58 template<class T>59 inline T ntoh(T value) {60 return EndianSwapBytes<BIG_ENDIAN_ORDER, HOST_ENDIAN_ORDER, T >(value);61 }62 template<typename T>63 inline T hton(T value) {64 return EndianSwapBytes<HOST_ENDIAN_ORDER, BIG_ENDIAN_ORDER, T >(value);65 }66 30 67 31 … … 95 59 } 96 60 static size_type get_packet_length(size_type payload_length) { 97 std::cout << "get_packet: " << sizeof(nrpe::data::packet) << ":" << payload_length << std::endl;98 61 return sizeof(nrpe::data::packet)+payload_length*sizeof(char); 99 62 } … … 102 65 } 103 66 static size_type get_payload_length(size_type packet_length) { 104 std::cout << "get_payload: " << sizeof(nrpe::data::packet) << ":" << packet_length << std::endl;105 67 return (packet_length-sizeof(nrpe::data::packet))/sizeof(char); 106 68 } … … 120 82 }; 121 83 122 class packet {84 class packet /*: public boost::noncopyable*/ { 123 85 public: 124 86 … … 195 157 //TODO readd this ZeroMemory(tmpBuffer, getBufferLength()+1); 196 158 nrpe::data::packet *p = reinterpret_cast<nrpe::data::packet*>(tmpBuffer); 197 p->result_code = nrpe::hton<int16_t>(result_);198 p->packet_type = nrpe::hton<int16_t>(type_);199 p->packet_version = nrpe::hton<int16_t>(version_);159 p->result_code = swap_bytes::hton<int16_t>(result_); 160 p->packet_type = swap_bytes::hton<int16_t>(type_); 161 p->packet_version = swap_bytes::hton<int16_t>(version_); 200 162 if (payload_.length() >= payload_length_-1) 201 163 throw nrpe::nrpe_packet_exception(_T("To much data cant create return packet (truncate datat)")); … … 204 166 p->buffer[payload_.length()] = 0; 205 167 p->crc32_value = 0; 206 p->crc32_value = nrpe::hton<u_int32_t>(calculate_crc32(tmpBuffer, packet_length));168 p->crc32_value = swap_bytes::hton<u_int32_t>(calculate_crc32(tmpBuffer, packet_length)); 207 169 std::wcout << _T("About to send: ") << to_string() << std::endl; 208 170 std::wcout << _T("About to send: ") … … 213 175 << std::endl; 214 176 return tmpBuffer; 177 } 178 179 std::vector<char> get_buffer() { 180 const char *c = create_buffer(); 181 std::vector<char> buf(c, c+get_packet_length()); 182 return buf; 215 183 } 216 184 … … 227 195 throw nrpe::nrpe_packet_exception(_T("Invalid packet length: ") + strEx::itos(length) + _T(" != ") + strEx::itos(get_packet_length()) + _T(" configured payload is: ") + to_wstring(get_payload_length())); 228 196 const nrpe::data::packet *p = reinterpret_cast<const nrpe::data::packet*>(buffer); 229 type_ = nrpe::ntoh<int16_t>(p->packet_type);197 type_ = swap_bytes::ntoh<int16_t>(p->packet_type); 230 198 if ((type_ != nrpe::data::queryPacket)&&(type_ != nrpe::data::responsePacket)) 231 199 throw nrpe::nrpe_packet_exception(_T("Invalid packet type: ") + strEx::itos(type_)); 232 version_ = nrpe::ntoh<int16_t>(p->packet_version);200 version_ = swap_bytes::ntoh<int16_t>(p->packet_version); 233 201 if (version_ != nrpe::data::version2) 234 202 throw nrpe::nrpe_packet_exception(_T("Invalid packet version.") + strEx::itos(version_)); 235 crc32_ = nrpe::ntoh<u_int32_t>(p->crc32_value);203 crc32_ = swap_bytes::ntoh<u_int32_t>(p->crc32_value); 236 204 // Verify CRC32 237 205 // @todo Fix this, currently we need a const buffer so we cannot change the CRC to 0. … … 247 215 + _T("!=") + strEx::ihextos(calculatedCRC32_)); 248 216 // Verify CRC32 end 249 result_ = nrpe::ntoh<u_int32_t>(p->result_code);217 result_ = swap_bytes::ntoh<u_int32_t>(p->result_code); 250 218 payload_ = strEx::string_to_wstring(std::string(p->buffer)); 251 219 } -
include/nsc_module_wrapper.hpp
r2018659 r40970de 23 23 NSCAPI::boolReturn wrapHasCommandHandler(bool has); 24 24 NSCAPI::boolReturn wrapHasMessageHandler(bool has); 25 NSCAPI::boolReturn wrapHasNotificationHandler(bool has); 26 NSCAPI::nagiosReturn wrapHandleNotification(NSCAPI::nagiosReturn retResult); 25 27 int wrapUnloadModule(bool success); 26 28 NSCAPI::nagiosReturn wrapHandleCommand(NSCAPI::nagiosReturn retResult, const std::string &reply, char **reply_buffer, unsigned int *size); … … 170 172 extern NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) \ 171 173 { \ 172 try { \173 std::string request(request_buffer, request_buffer_len), reply; \174 NSCAPI::nagiosReturn retCode = (&toObject)->handleRAWCommand(command, request, reply); \175 return NSCModuleWrapper::wrapHandleCommand(retCode, reply, reply_buffer, reply_buffer_len); \176 } catch (...) { \ 177 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \178 return NSCAPI::returnIgnored; \174 try { \ 175 std::string request(request_buffer, request_buffer_len), reply; \ 176 NSCAPI::nagiosReturn retCode = (&toObject)->handleRAWCommand(command, request, reply); \ 177 return NSCModuleWrapper::wrapHandleCommand(retCode, reply, reply_buffer, reply_buffer_len); \ 178 } catch (...) { \ 179 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 180 return NSCAPI::returnIgnored; \ 179 181 } \ 180 182 } \ 181 183 extern NSCAPI::boolReturn NSHasCommandHandler() { \ 182 try { \183 return NSCModuleWrapper::wrapHasCommandHandler(toObject.hasCommandHandler()); \184 } catch (...) { \ 185 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \186 return NSCAPI::isfalse; \184 try { \ 185 return NSCModuleWrapper::wrapHasCommandHandler(toObject.hasCommandHandler()); \ 186 } catch (...) { \ 187 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 188 return NSCAPI::isfalse; \ 187 189 } \ 188 190 } 189 191 #define NSC_WRAPPERS_IGNORE_CMD_DEF() \ 190 192 extern NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 191 wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \192 return NSCAPI::returnIgnored; \193 wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \ 194 return NSCAPI::returnIgnored; \ 193 195 } \ 194 196 extern NSCAPI::boolReturn NSHasCommandHandler() { return NSCAPI::isfalse; } 197 #define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \ 198 extern void NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int) {} \ 199 extern NSCAPI::boolReturn NSHasNotificationHandler() { return NSCAPI::isfalse; } 200 #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(toObject) \ 201 extern NSCAPI::nagiosReturn NSHandleNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const char* result_buffer, unsigned int result_buffer_len) \ 202 { \ 203 try { \ 204 std::string result(result_buffer, result_buffer_len); \ 205 return NSCModuleWrapper::wrapHandleNotification((&toObject)->handleRAWNotification(channel, command, code, result)); \ 206 } catch (...) { \ 207 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ 208 return NSCAPI::returnIgnored; \ 209 } \ 210 } \ 211 extern NSCAPI::boolReturn NSHasNotificationHandler() { \ 212 try { \ 213 return NSCModuleWrapper::wrapHasNotificationHandler(toObject.hasNotificationHandler()); \ 214 } catch (...) { \ 215 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ 216 return NSCAPI::isfalse; \ 217 } \ 218 } 195 219 196 220 -
include/socket_helpers.hpp
r79e734f r40970de 115 115 } 116 116 }; 117 118 namespace io { 119 void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) { 120 a->reset(b); 121 } 122 123 template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 124 void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 125 boost::optional<boost::system::error_code> timer_result; 126 boost::asio::deadline_timer timer(sock.io_service()); 127 timer.expires_from_now(duration); 128 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 129 130 boost::optional<boost::system::error_code> read_result; 131 async_read(sock, buffers, boost::bind(set_result, &read_result, _1)); 132 133 sock.io_service().reset(); 134 while (sock.io_service().run_one()) { 135 if (read_result) 136 timer.cancel(); 137 else if (timer_result) 138 rawSocket.close(); 139 } 140 141 if (*read_result) 142 throw boost::system::system_error(*read_result); 143 } 144 145 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 146 void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 147 boost::optional<boost::system::error_code> timer_result; 148 boost::asio::deadline_timer timer(sock.io_service()); 149 timer.expires_from_now(duration); 150 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 151 152 boost::optional<boost::system::error_code> read_result; 153 async_write(sock, buffers, boost::bind(set_result, &read_result, _1)); 154 155 sock.io_service().reset(); 156 while (sock.io_service().run_one()) { 157 if (read_result) 158 timer.cancel(); 159 else if (timer_result) 160 rawSocket.close(); 161 } 162 163 if (*read_result) 164 throw boost::system::system_error(*read_result); 165 } 166 167 } 117 168 } 169 -
include/strEx.h
rf0e6036 r40970de 74 74 std::locale loc; 75 75 for(unsigned int i= 0; i < arg.size(); ++i) 76 result += std::use_facet<std::ctype< char> >(loc).narrow(arg[i], 0);76 result += std::use_facet<std::ctype<wchar_t> >(loc).narrow(arg[i], 0); 77 77 return result; 78 78 } … … 112 112 if (c==0||c==7||c==10||c==11||c==12||c==13||c==127) 113 113 ret.push_back(L'?'); 114 else 115 ret.push_back(c); 116 } 117 return ret; 118 } 119 inline std::string strip_hex(std::string str) { 120 std::string ret; ret.reserve(str.size()); 121 BOOST_FOREACH(char c, str) 122 { 123 if (c==0||c==7||c==10||c==11||c==12||c==13||c==127) 124 ret.push_back('?'); 114 125 else 115 126 ret.push_back(c); … … 404 415 return value * smallest_unit; 405 416 } 417 inline long stol_as_time_sec(std::wstring time, unsigned int smallest_unit = 1) { 418 long neg = 1; 419 if (time.length() > 1 && time[0] == L'-') 420 return -stoui_as_time_sec(time.substr(1), smallest_unit); 421 return stoui_as_time_sec(time, smallest_unit); 422 } 406 423 407 424 inline unsigned long long stoi64_as_time(std::wstring time, unsigned int smallest_unit = 1000) { … … 809 826 return boost::lexical_cast<std::string>(arg) ; 810 827 } 811 catch( boost::bad_lexical_cast& e) {828 catch(...) { 812 829 return ""; 813 830 } … … 817 834 return boost::lexical_cast<std::wstring>(arg) ; 818 835 } 819 catch( boost::bad_lexical_cast& e) {836 catch(...) { 820 837 return _T(""); 821 838 } -
libs/protobuf/CMakeLists.txt
rdad34ea r40970de 3 3 WRAP_PROTO(PB_PLUGIN plugin.proto) 4 4 5 SET(TARGET proto )5 SET(TARGET protobuf) 6 6 7 7 #PROJECT(${TARGET}) -
modules/CheckExternalScripts/CheckExternalScripts.cpp
rb4110d8 r40970de 35 35 36 36 CheckExternalScripts gCheckExternalScripts; 37 #ifdef _WIN3238 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)39 {40 NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);41 return TRUE;42 }43 #endif44 37 45 38 CheckExternalScripts::CheckExternalScripts() {} … … 174 167 175 168 169 NSC_WRAP_DLL(); 176 170 NSC_WRAPPERS_MAIN_DEF(gCheckExternalScripts); 177 171 NSC_WRAPPERS_IGNORE_MSG_DEF(); -
modules/NRPEClient/CMakeLists.txt
r3080680 r40970de 8 8 stdafx.cpp 9 9 "${TARGET}.cpp" 10 ${NSCP_INCLUDE_PATH}/nrpe/nrpe packet.cpp10 ${NSCP_INCLUDE_PATH}/nrpe/nrpe_packet.cpp 11 11 12 12 ${NSCP_DEF_PLUGIN_CPP} … … 20 20 "${TARGET}.h" 21 21 "${TARGET}.def" 22 ${NSCP_INCLUDE_PATH}/nrpe/nrpepacket.hpp23 22 ${NSCP_INCLUDE_PATH}/socket_helpers.hpp 23 ${NSCP_INCLUDE_PATH}/nrpe/nrpe_packet.hpp 24 ${NSCP_INCLUDE_PATH}/nrpe/nrpe_socket.hpp 25 ${NSCP_INCLUDE_PATH}/swap_bytes.hpp 24 26 25 27 ${NSCP_DEF_PLUGIN_HPP} -
modules/NRPEClient/NRPEClient.cpp
rb4110d8 r40970de 29 29 #include <boost/filesystem.hpp> 30 30 #include <strEx.h> 31 #include <nrpe/nrpe_socket.hpp> 31 32 32 33 … … 217 218 } 218 219 } 219 /* 220 NRPEPacket NRPEClient::send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet) 221 { 222 #ifndef USE_SSL 223 return send_nossl(host, port, timeout, packet); 224 #else 225 226 simpleSSL::Socket socket(true); 227 socket.connect(host, port); 228 NSC_DEBUG_MSG_STD(_T(">>>length: ") + strEx::itos(packet.getBufferLength())); 229 socket.sendAll(packet.getBuffer(), packet.getBufferLength()); 230 simpleSocket::DataBuffer buffer; 231 socket.readAll(buffer, packet.getBufferLength()); 232 NSC_DEBUG_MSG_STD(_T("<<<length: ") + strEx::itos(buffer.getLength())); 233 packet.readFrom(buffer.getBuffer(), buffer.getLength()); 234 return packet; 235 236 237 boost::asio::ssl::context ctx(io_service, boost::asio::ssl::context::sslv23); 238 ctx.use_tmp_dh_file("d:\\nrpe_512.pem"); 239 ctx.set_verify_mode(boost::asio::ssl::context::verify_peer); 240 nrpe_ssl_socket socket(io_service, ctx, host, port); 241 //socket. 242 243 #endif 244 } 245 */ 246 using boost::asio::ip::tcp; 247 248 void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) 249 { 250 a->reset(b); 251 } 252 template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 253 void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) 254 { 255 boost::optional<boost::system::error_code> timer_result; 256 boost::asio::deadline_timer timer(sock.io_service()); 257 timer.expires_from_now(duration); 258 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 259 260 boost::optional<boost::system::error_code> read_result; 261 async_read(sock, buffers, boost::bind(set_result, &read_result, _1)); 262 263 sock.io_service().reset(); 264 while (sock.io_service().run_one()) 265 { 266 if (read_result) 267 timer.cancel(); 268 else if (timer_result) 269 rawSocket.close(); 270 } 271 272 if (*read_result) 273 throw boost::system::system_error(*read_result); 274 } 275 276 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 277 void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) 278 { 279 boost::optional<boost::system::error_code> timer_result; 280 boost::asio::deadline_timer timer(sock.io_service()); 281 timer.expires_from_now(duration); 282 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 283 284 boost::optional<boost::system::error_code> read_result; 285 async_write(sock, buffers, boost::bind(set_result, &read_result, _1)); 286 287 sock.io_service().reset(); 288 while (sock.io_service().run_one()) 289 { 290 if (read_result) 291 timer.cancel(); 292 else if (timer_result) 293 rawSocket.close(); 294 } 295 296 if (*read_result) 297 throw boost::system::system_error(*read_result); 298 } 299 300 class nrpe_socket : public boost::noncopyable { 301 public: 302 tcp::socket socket_; 303 304 public: 305 nrpe_socket(boost::asio::io_service &io_service, std::wstring host, int port) : socket_(io_service) { 306 tcp::resolver resolver(io_service); 307 tcp::resolver::query query(to_string(host), to_string(port)); 308 //tcp::resolver::query query("www.medin.name", "80"); 309 //tcp::resolver::query query("test_server", "80"); 310 311 tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 312 tcp::resolver::iterator end; 313 314 boost::system::error_code error = boost::asio::error::host_not_found; 315 while (error && endpoint_iterator != end) 316 { 317 tcp::resolver::endpoint_type ep = *endpoint_iterator; 318 NSC_DEBUG_MSG_STD(_T("Attempting to connect to: ") + to_wstring(ep.address().to_string()) + _T(":") + to_wstring(ep.port())); 319 socket_.close(); 320 socket_.connect(*endpoint_iterator++, error); 321 } 322 if (error) 323 throw boost::system::system_error(error); 324 } 325 ~nrpe_socket() { 326 socket_.close(); 327 } 328 329 void send(nrpe::packet &packet, boost::posix_time::seconds timeout) { 330 std::vector<char> buf(packet.get_packet_length()); 331 write_with_timeout(socket_, socket_, boost::asio::buffer(packet.create_buffer(), packet.get_packet_length()), timeout); 332 } 333 nrpe::packet recv(const nrpe::packet &packet, boost::posix_time::seconds timeout) { 334 std::vector<char> buf(packet.get_packet_length()); 335 std::cout << "About to read: " << buf.size() << std::endl; 336 read_with_timeout(socket_, socket_, boost::asio::buffer(buf), timeout); 337 std::cout << "Read data: " << buf.size() << std::endl; 338 return nrpe::packet(&buf[0], buf.size(), packet.get_payload_length()); 339 } 340 }; 220 221 341 222 #ifdef USE_SSL 342 343 class nrpe_ssl_socket { 344 345 private: 346 boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_; 347 public: 348 nrpe_ssl_socket(boost::asio::io_service &io_service, boost::asio::ssl::context &ctx, std::wstring host, int port) : socket_(io_service, ctx) { 349 NSC_LOG_CRITICAL(_T("Looking up...")); 350 tcp::resolver resolver(io_service); 351 tcp::resolver::query query(to_string(host), to_string(port)); 352 //tcp::resolver::query query("www.medin.name", "80"); 353 //tcp::resolver::query query("test_server", "80"); 354 355 tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 356 tcp::resolver::iterator end; 357 358 boost::system::error_code error = boost::asio::error::host_not_found; 359 NSC_LOG_CRITICAL(_T("Connecting...")); 360 while (error && endpoint_iterator != end) 361 { 362 tcp::resolver::endpoint_type ep = *endpoint_iterator; 363 NSC_DEBUG_MSG_STD(_T("Attempting to connect to: ") + to_wstring(ep.address().to_string()) + _T(":") + to_wstring(ep.port())); 364 socket_.lowest_layer().close(); 365 socket_.lowest_layer().connect(*endpoint_iterator++, error); 366 } 367 if (error) 368 throw boost::system::system_error(error); 369 NSC_LOG_CRITICAL(_T("Connected...")); 370 371 NSC_LOG_CRITICAL(_T("Handshaking...")); 372 //socket_.handshake(boost::asio::ssl::stream_base::client); 373 socket_.handshake(boost::asio::ssl::stream_base::client); 374 NSC_LOG_CRITICAL(_T("Handshook...") + strEx::itos(error.value())); 375 376 } 377 378 void send(nrpe::packet &packet, boost::posix_time::seconds timeout) { 379 std::vector<char> buf(packet.get_packet_length()); 380 write_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(packet.create_buffer(), packet.get_packet_length()), timeout); 381 } 382 nrpe::packet recv(const nrpe::packet &packet, boost::posix_time::seconds timeout) { 383 std::vector<char> buf(packet.get_packet_length()); 384 read_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(buf), timeout); 385 return nrpe::packet(&buf[0], buf.size(), packet.get_payload_length()); 386 } 387 }; 388 nrpe::packet NRPEClient::send_ssl(std::wstring host, int port, int timeout, nrpe::packet packet) 389 { 223 nrpe::packet NRPEClient::send_ssl(std::wstring host, int port, int timeout, nrpe::packet packet) { 390 224 boost::asio::io_service io_service; 391 225 boost::asio::ssl::context ctx(io_service, boost::asio::ssl::context::sslv23); … … 393 227 ctx.use_tmp_dh_file(to_string(cert_)); 394 228 ctx.set_verify_mode(boost::asio::ssl::context::verify_none); 395 nrpe _ssl_socket socket(io_service, ctx, host, port);229 nrpe::ssl_socket socket(io_service, ctx, host, port); 396 230 socket.send(packet, boost::posix_time::seconds(timeout)); 397 231 return socket.recv(packet, boost::posix_time::seconds(timeout)); … … 399 233 #endif 400 234 401 nrpe::packet NRPEClient::send_nossl(std::wstring host, int port, int timeout, nrpe::packet packet) 402 { 235 nrpe::packet NRPEClient::send_nossl(std::wstring host, int port, int timeout, nrpe::packet packet) { 403 236 boost::asio::io_service io_service; 404 nrpe _socket socket(io_service, host, port);237 nrpe::socket socket(io_service, host, port); 405 238 socket.send(packet, boost::posix_time::seconds(timeout)); 406 239 return socket.recv(packet, boost::posix_time::seconds(timeout)); -
modules/NRPEClient/NRPEClient.h
rb4110d8 r40970de 22 22 NSC_WRAPPERS_MAIN(); 23 23 #include <map> 24 #include <nrpe/nrpe packet.hpp>24 #include <nrpe/nrpe_packet.hpp> 25 25 26 26 … … 127 127 nrpe::packet send_ssl(std::wstring host, int port, int timeout, nrpe::packet packet); 128 128 void add_options(po::options_description &desc, nrpe_connection_data &command_data); 129 #ifdef USE_BOOST130 #endif131 129 132 130 private: -
modules/NRPEServer/CMakeLists.txt
r3080680 r40970de 14 14 nrpe_connection.cpp 15 15 nrpe_handler.cpp 16 ${NSCP_INCLUDE_PATH}/nrpe/nrpe packet.cpp16 ${NSCP_INCLUDE_PATH}/nrpe/nrpe_packet.cpp 17 17 18 18 ${NSCP_DEF_PLUGIN_CPP} … … 30 30 nrpe_handler.hpp 31 31 nrpe_parser.hpp 32 ${NSCP_INCLUDE_PATH}/nrpe/nrpepacket.hpp33 32 ${NSCP_INCLUDE_PATH}/socket_helpers.hpp 33 ${NSCP_INCLUDE_PATH}/nrpe/nrpe_packet.hpp 34 ${NSCP_INCLUDE_PATH}/swap_bytes.hpp 34 35 35 36 ${NSCP_DEF_PLUGIN_HPP} -
modules/NRPEServer/nrpe_connection.cpp
rf6fbf6f r40970de 41 41 boost::tie(result, begin) = parser_.digest(begin, end); 42 42 if (begin == old_begin) { 43 std::cout << "Whoops, this is wrong...";43 handler_.create_error(_T("Something strange happened...")); 44 44 return; 45 45 } -
modules/NRPEServer/nrpe_handler.hpp
rf6fbf6f r40970de 1 #include <nrpe/nrpe packet.hpp>1 #include <nrpe/nrpe_packet.hpp> 2 2 #include <boost/tuple/tuple.hpp> 3 3 -
modules/NRPEServer/nrpe_parser.hpp
rf6fbf6f r40970de 1 #include <nrpe/nrpe packet.hpp>1 #include <nrpe/nrpe_packet.hpp> 2 2 #include <boost/tuple/tuple.hpp> 3 3 #include <boost/noncopyable.hpp> … … 13 13 : payload_length_(payload_length) 14 14 , packet_length_(nrpe::length::get_packet_length(payload_length)) 15 { 16 std::cout << "== ctor length: " << payload_length_ << "/" << packet_length_ << std::endl; 17 } 15 {} 18 16 19 17 template <typename InputIterator> 20 18 boost::tuple<bool, InputIterator> digest(InputIterator begin, InputIterator end) { 21 std::cout << "== Parsing: " << payload_length_ << "/" << packet_length_ << std::endl;22 19 int count = packet_length_ - buffer_.size(); 23 std::cout << "Bytes already: " << buffer_.size() << ", need more: " << count << " got: " << (end-begin) << std::endl;24 20 for (; count > 0&& begin != end; ++begin, --count) 25 21 buffer_.push_back(*begin); … … 35 31 payload_length_ = length; 36 32 packet_length_ = nrpe::length::get_packet_length(length); 37 std::cout << "== Setting length: " << payload_length_ << "/" << packet_length_ << std::endl;38 33 } 39 34 }; -
modules/NRPEServer/stdafx.h
rf029bc2 r40970de 48 48 #include <NSCHelper.h> 49 49 #include <nsc_module_wrapper.hpp> 50 #include <nrpe/nrpe packet.hpp>50 #include <nrpe/nrpe_packet.hpp> 51 51 -
modules/NSCAAgent/NSCAAgent.cpp
rf0eb62d r40970de 25 25 #include <list> 26 26 #include <string> 27 #include <nsca/nsca_enrypt.hpp> 28 #include <nsca/nsca_packet.hpp> 29 #include <nsca/nsca_socket.hpp> 27 30 28 31 NSCAAgent gNSCAAgent; … … 63 66 SETTINGS_REG_PATH(nsca::CMD_SECTION); 64 67 65 SETTINGS_REG_KEY_I(nsca::INTERVAL);66 68 SETTINGS_REG_KEY_S(nsca::HOSTNAME); 67 69 SETTINGS_REG_KEY_S(nsca::SERVER_HOST); … … 69 71 SETTINGS_REG_KEY_I(nsca::ENCRYPTION); 70 72 SETTINGS_REG_KEY_S(nsca::PASSWORD); 71 SETTINGS_REG_KEY_I(nsca::THREADS);72 73 SETTINGS_REG_KEY_B(nsca::CACHE_HOST); 74 75 hostname_ = to_string(SETTINGS_GET_STRING(nsca::HOSTNAME)); 76 nscahost_ = SETTINGS_GET_STRING(nsca::SERVER_HOST); 77 nscaport_ = SETTINGS_GET_INT(nsca::SERVER_PORT); 78 79 encryption_method_ = SETTINGS_GET_INT(nsca::ENCRYPTION); 80 password_ = strEx::wstring_to_string(SETTINGS_GET_STRING(nsca::PASSWORD)); 81 cacheNscaHost_ = SETTINGS_GET_INT(nsca::CACHE_HOST); 82 timeout_ = SETTINGS_GET_INT(nsca::READ_TIMEOUT); 83 payload_length_ = SETTINGS_GET_INT(nsca::PAYLOAD_LENGTH); 84 time_delta_ = strEx::stol_as_time_sec(SETTINGS_GET_STRING(nsca::TIME_DELTA_DEFAULT), 1); 73 85 74 86 … … 79 91 } 80 92 81 if (mode == NSCAPI::normalStart) {82 int e_threads = SETTINGS_GET_INT(nsca::THREADS);83 93 84 for (int i=0;i<e_threads;i++) {85 std::wstring id = _T("nsca_t_") + strEx::itos(i);86 NSCAThreadImpl *thread = new NSCAThreadImpl(id);87 extra_threads.push_back(thread);88 }89 for (std::list<NSCAThreadImpl*>::const_iterator cit=extra_threads.begin();cit != extra_threads.end(); ++cit) {90 (*cit)->createThread(reinterpret_cast<LPVOID>(rand()));91 }92 }93 94 94 return true; 95 95 } … … 100 100 */ 101 101 bool NSCAAgent::unloadModule() { 102 /*103 if (!pdhThread.exitThread(20000)) {104 std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl;105 NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result..."));106 }107 */108 for (std::list<NSCAThreadImpl*>::iterator it=extra_threads.begin();it != extra_threads.end(); ++it) {109 if (!(*it)->exitThread(20000)) {110 std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl;111 NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result..."));112 }113 }114 102 return true; 115 }116 /**117 * Check if we have a command handler.118 * @return true (as we have a command handler)119 */120 bool NSCAAgent::hasCommandHandler() {121 return false;122 }123 /**124 * Check if we have a message handler.125 * @return false as we have no message handler126 */127 bool NSCAAgent::hasMessageHandler() {128 return false;129 }130 131 int NSCAAgent::commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR** args) {132 return -1;133 }134 135 136 /**137 * Main command parser and delegator.138 * This also handles a lot of the simpler responses (though some are deferred to other helper functions)139 *140 *141 * @param command142 * @param argLen143 * @param **args144 * @return145 */146 NSCAPI::nagiosReturn NSCAAgent::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) {147 return NSCAPI::returnIgnored;148 103 } 149 104 std::wstring NSCAAgent::getCryptos() { 150 105 std::wstring ret = _T("{"); 151 106 for (int i=0;i<LAST_ENCRYPTION_ID;i++) { 152 if (nsca _encrypt::hasEncryption(i)) {107 if (nsca::nsca_encrypt::hasEncryption(i)) { 153 108 std::wstring name; 154 109 try { 155 nsca _encrypt::any_encryption *core =nsca_encrypt::get_encryption_core(i);110 nsca::nsca_encrypt::any_encryption *core = nsca::nsca_encrypt::get_encryption_core(i); 156 111 if (core == NULL) 157 112 name = _T("Broken<NULL>"); 158 113 else 159 114 name = core->getName(); 160 } catch (nsca _encrypt::encryption_exception &e) {115 } catch (nsca::nsca_encrypt::encryption_exception &e) { 161 116 name = e.getMessage(); 162 117 } … … 169 124 } 170 125 126 NSCAPI::nagiosReturn NSCAAgent::handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf) { 127 try { 128 NSC_DEBUG_MSG_STD(_T("* * *NSCA * * * Handling command: ") + command); 129 boost::asio::io_service io_service; 130 NSC_DEBUG_MSG_STD(_T("* * *NSCA * * * message: ") + msg); 131 nsca::socket socket(io_service); 132 socket.connect(nscahost_, nscaport_); 133 nsca::packet packet(hostname_, payload_length_, time_delta_); 134 packet.code = code; 135 packet.host = "hello"; 136 packet.result = to_string(msg); 137 socket.recv_iv(password_, encryption_method_, boost::posix_time::seconds(timeout_)); 138 socket.send_nsca(packet, boost::posix_time::seconds(timeout_)); 139 return 1; 140 } catch (std::exception &e) { 141 NSC_LOG_ERROR_STD(_T("Failed to send data: ") + to_wstring(e.what())); 142 } catch (...) { 143 NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN")); 144 } 145 } 146 171 147 172 148 NSC_WRAPPERS_MAIN_DEF(gNSCAAgent); 173 149 NSC_WRAPPERS_IGNORE_MSG_DEF(); 174 NSC_WRAPPERS_HANDLE_CMD_DEF(gNSCAAgent); 175 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNSCAAgent); 176 NSC_WRAPPERS_CLI_DEF(gNSCAAgent); 177 178 179 180 MODULE_SETTINGS_START(NSCAAgent, _T("NRPE Listener configuration"), _T("...")) 181 182 PAGE(_T("NRPE Listsner configuration")) 183 184 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the NRPEListener.dll will listen to.")) 185 ITEM_MAP_TO(_T("basic_ini_text_mapper")) 186 OPTION(_T("section"), _T("NRPE")) 187 OPTION(_T("key"), _T("port")) 188 OPTION(_T("default"), _T("5666")) 189 ITEM_END() 190 191 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed.")) 192 ITEM_MAP_TO(_T("basic_ini_bool_mapper")) 193 OPTION(_T("section"), _T("NRPE")) 194 OPTION(_T("key"), _T("allow_arguments")) 195 OPTION(_T("default"), _T("false")) 196 OPTION(_T("true_value"), _T("1")) 197 OPTION(_T("false_value"), _T("0")) 198 ITEM_END() 199 200 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)")) 201 ITEM_MAP_TO(_T("basic_ini_bool_mapper")) 202 OPTION(_T("section"), _T("NRPE")) 203 OPTION(_T("key"), _T("allow_nasty_meta_chars")) 204 OPTION(_T("default"), _T("false")) 205 OPTION(_T("true_value"), _T("1")) 206 OPTION(_T("false_value"), _T("0")) 207 ITEM_END() 208 209 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat.")) 210 ITEM_MAP_TO(_T("basic_ini_bool_mapper")) 211 OPTION(_T("section"), _T("NRPE")) 212 OPTION(_T("key"), _T("use_ssl")) 213 OPTION(_T("default"), _T("true")) 214 OPTION(_T("true_value"), _T("1")) 215 OPTION(_T("false_value"), _T("0")) 216 ITEM_END() 217 218 PAGE_END() 219 ADVANCED_PAGE(_T("Access configuration")) 220 221 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server.")) 222 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)")) 223 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server")) 224 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:")) 225 OPTION(_T("separator"), _T(",")) 226 OPTION(_T("disabled"), _T("")) 227 ITEM_MAP_TO(_T("basic_ini_text_mapper")) 228 OPTION(_T("section"), _T("NRPE")) 229 OPTION(_T("key"), _T("allowed_hosts")) 230 OPTION(_T("default"), _T("")) 231 ITEM_END() 232 233 PAGE_END() 234 MODULE_SETTINGS_END() 150 NSC_WRAPPERS_IGNORE_CMD_DEF(); 151 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(gNSCAAgent); -
modules/NSCAAgent/NSCAAgent.def
r5ca3931 r40970de 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 NSCommandLineExec 14 NSDeleteBuffer 15 NSHandleNotification 16 NSHasNotificationHandler -
modules/NSCAAgent/NSCAAgent.h
r5da0459 r40970de 21 21 #pragma once 22 22 23 #include "NSCAThread.h"24 23 #include <CheckMemory.h> 25 24 26 25 NSC_WRAPPERS_MAIN(); 27 NSC_WRAPPERS_CLI();28 26 29 class NSCAAgent {27 class NSCAAgent : public NSCModuleHelper::SimpleNotificationHandler { 30 28 private: 31 CheckMemory memoryChecker;32 int processMethod_;33 // NSCAThreadImpl pdhThread;34 std::list<NSCAThreadImpl*> extra_threads;35 29 36 public: 30 std::string hostname_; 31 std::wstring nscahost_; 32 unsigned int nscaport_; 33 unsigned int payload_length_; 34 bool cacheNscaHost_; 35 std::string password_; 36 int encryption_method_; 37 unsigned int timeout_; 38 int time_delta_; 37 39 38 40 public: … … 66 68 return std::wstring(_T("Passive check support (needs NSCA on nagios server).\nAvalible crypto are: ")) + getCryptos(); 67 69 } 68 69 bool hasCommandHandler(); 70 bool hasMessageHandler(); 71 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf); 72 int commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR** args); 70 bool hasNotificationHandler() { return true; } 73 71 74 72 std::wstring getCryptos(); 75 73 74 NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); 75 76 76 77 }; -
modules/NSCAAgent/NSCAThread.cpp
rf0eb62d r40970de 90 90 read_timeout_ = SETTINGS_GET_INT(nsca::READ_TIMEOUT); 91 91 92 std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(setting s::nsca::CMD_SECTION_TITLE);92 std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(setting_keys::nsca::CMD_SECTION_TITLE); 93 93 for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 94 94 addCommand(*cit); … … 118 118 std::wstring msg; 119 119 std::wstring perf; 120 NSCAPI::nagiosReturn ret = NSCModuleHelper::Inject Command(cmd_.c_str(), args_.getLen(), args_.get(), msg, perf);120 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSimpleCommand(cmd_.c_str(), args_, msg, perf); 121 121 result.service = alias_; 122 122 if (ret == NSCAPI::returnIgnored) { … … 139 139 140 140 void NSCAThread::addCommand(std::wstring key) { 141 std::wstring value = NSCModuleHelper::getSettingsString(setting s::nsca::CMD_SECTION_PATH, key, _T(""));141 std::wstring value = NSCModuleHelper::getSettingsString(setting_keys::nsca::CMD_SECTION_PATH, key, _T("")); 142 142 if ((key.length() > 4) && (key.substr(0,4) == _T("host"))) 143 143 commands_.push_back(Command(_T(""), value)); -
modules/NSCAAgent/NSCAThread.h
re7dbac9 r40970de 24 24 #include <Mutex.h> 25 25 #include <arrayBuffer.h> 26 #include <Socket.h>27 26 #include "nsca_enrypt.hpp" 28 27 … … 93 92 94 93 95 class Arguments { 96 arrayBuffer::arrayBuffer arglist_; 97 unsigned int arglen_; 98 public: 99 Arguments() : arglist_(NULL), arglen_(0) {} 100 ~Arguments() { 101 arrayBuffer::destroyArrayBuffer(arglist_, arglen_); 102 arglist_ = NULL; 103 } 104 Arguments(const Arguments& other) : arglist_(NULL), arglen_(0) { 105 arglen_ = other.getLen(); 106 arglist_ = arrayBuffer::copy(other.get(), other.getLen()); 107 } 108 Arguments& operator=(Arguments& other) { 109 if (this != &other){ 110 arglen_ = other.getLen(); 111 arglist_ = other.detach(); 112 } 113 return *this; 114 } 115 Arguments& operator=(const Arguments& other) { 116 if (this != &other){ 117 arglen_ = other.getLen(); 118 arglist_ = arrayBuffer::copy(other.get(), other.getLen()); 119 } 120 return *this; 121 } 122 Arguments(const std::wstring &other) : arglist_(NULL), arglen_(0) { 123 arglist_ = arrayBuffer::split2arrayBuffer(other, ' ', arglen_, true); 124 } 125 arrayBuffer::arrayBuffer detach() { 126 arrayBuffer::arrayBuffer ret = arglist_; 127 arglist_ = NULL; 128 arglen_ = 0; 129 return ret; 130 } 131 const arrayBuffer::arrayBuffer get() const { 132 return arglist_; 133 } 134 unsigned int getLen() const { 135 return arglen_; 136 } 137 }; 94 138 95 class Command { 139 96 std::wstring cmd_; 140 97 std::wstring alias_; 141 Argumentsargs_;98 std::list<std::wstring> args_; 142 99 public: 143 100 … … 160 117 } 161 118 162 simpleSocket::DataBuffer getBuffer(nsca_encrypt &crypt_inst, __time32_t time_delta, unsigned int pluginoutput_length) const { 119 std::string getBuffer(nsca_encrypt &crypt_inst, __time32_t time_delta, unsigned int pluginoutput_length) const { 120 std::string ret; ret.resize(buffer_len); 163 121 std::string s = strEx::wstring_to_string(service); 164 122 std::string r = strEx::wstring_to_string(result); … … 203 161 strEx::token token = strEx::getToken(raw, ' '); 204 162 cmd_ = token.first; 205 args_ = token.second;163 args_.push_back(token.second); 206 164 } 207 165 static unsigned int conv_code(NSCAPI::nagiosReturn ret) { -
modules/NSCAAgent/stdafx.h
r7f9c823 r40970de 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 #define COMPILE_NEWAPIS_STUBS28 23 #define WANT_GETLONGPATHNAME_WRAPPER 29 24 //#include <NewAPIs.h> … … 34 29 #include <hash_map> 35 30 #include <list> 31 32 33 #include <boost/asio.hpp> 34 #ifdef USE_SSL 35 #include <boost/asio/ssl.hpp> 36 #endif 37 36 38 #include <NSCAPI.h> 37 39 #include <NSCHelper.h> … … 41 43 #include <error.hpp> 42 44 45 43 46 #ifdef MEMCHECK 44 47 #include <vld.h> -
modules/Scheduler/Scheduler.cpp
rc0d7e82 r40970de 123 123 void Scheduler::handle_schedule(scheduler::target item) { 124 124 try { 125 std:: wstring msg, perf;126 NSCAPI::nagiosReturn code = NSCModuleHelper::Inject SimpleCommand(item.command.c_str(), item.arguments, msg, perf);125 std::string response; 126 NSCAPI::nagiosReturn code = NSCModuleHelper::InjectCommand(item.command.c_str(), item.arguments, response); 127 127 if (NSCHelper::report::matches(item.report, code)) { 128 NSCModuleHelper::NotifyChannel(item.channel, item.alias, code, msg, perf);128 NSCModuleHelper::NotifyChannel(item.channel, item.alias, code, response); 129 129 } 130 130 } catch (NSCModuleHelper::NSCMHExcpetion &e) { -
service/CMakeLists.txt
r920626f r40970de 40 40 41 41 commands.hpp 42 channels.hpp 42 43 logger.hpp 43 44 settings_logger_impl.hpp -
service/NSCPlugin.cpp
r3080680 r40970de 48 48 ,fShowTray(NULL) 49 49 ,fHideTray(NULL) 50 ,fHasNotificationHandler(NULL) 51 ,fHandleNotification(NULL) 50 52 ,bLoaded_(false) 51 53 ,lastIsMsgPlugin_(false) … … 206 208 } 207 209 } 210 bool NSCPlugin::hasNotificationHandler() { 211 if (!isLoaded()) 212 throw NSPluginException(module_, _T("Module not loaded")); 213 if (!fHasNotificationHandler) 214 return false; 215 try { 216 if (fHasNotificationHandler()) { 217 return true; 218 } 219 return false; 220 } catch (...) { 221 throw NSPluginException(module_, _T("Unhandled exception in hasMessageHandler.")); 222 } 223 } 208 224 /** 209 225 * Allow for the plug in to handle a command from the input core. … … 231 247 } 232 248 249 bool NSCPlugin::handleNotification(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len) { 250 if (!isLoaded() || fHandleNotification == NULL) 251 throw NSPluginException(module_, _T("Library is not loaded")); 252 try { 253 return fHandleNotification(channel, command, code, result, result_len); 254 } catch (...) { 255 throw NSPluginException(module_, _T("Unhandled exception in handleCommand.")); 256 } 257 } 258 259 233 260 234 261 void NSCPlugin::deleteBuffer(char** buffer) { … … 386 413 fGetConfigurationMeta = (lpGetConfigurationMeta)module_.load_proc("NSGetConfigurationMeta"); 387 414 fCommandLineExec = (lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 388 415 fHandleNotification = (lpHandleNotification)module_.load_proc("NSHandleNotification"); 416 fHasNotificationHandler = (lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 417 389 418 fShowTray = (lpShowTray)module_.load_proc("ShowIcon"); 390 419 fHideTray = (lpHideTray)module_.load_proc("HideIcon"); -
service/NSCPlugin.h
r2018659 r40970de 126 126 typedef void (*lpShowTray)(); 127 127 typedef void (*lpHideTray)(); 128 typedef int (*lpHasNotificationHandler)(); 129 typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 128 130 129 131 … … 143 145 lpShowTray fShowTray; 144 146 lpHideTray fHideTray; 147 lpHasNotificationHandler fHasNotificationHandler; 148 lpHandleNotification fHandleNotification; 145 149 146 150 public: … … 157 161 bool getVersion(int *major, int *minor, int *revision); 158 162 bool hasCommandHandler(void); 163 bool hasNotificationHandler(void); 159 164 bool hasMessageHandler(void); 160 165 NSCAPI::nagiosReturn handleCommand(const wchar_t *command, const char* dataBuffer, const unsigned int dataBuffer_len, char** returnBuffer, unsigned int *returnBuffer_len); 161 166 NSCAPI::nagiosReturn handleCommand(const wchar_t* command, std::string &request, std::string &reply); 167 bool handleNotification(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 162 168 void deleteBuffer(char**buffer); 163 169 void handleMessage(int msgType, const wchar_t* file, const int line, const wchar_t *message); -
service/NSClient++.cpp
rc0d7e82 r40970de 872 872 return; 873 873 } 874 commandHandlers_.clear();875 874 if (unloadLoggers) 876 875 messageHandlers_.clear(); … … 989 988 plugins_.insert(plugins_.end(), plugin); 990 989 commands_.add_plugin(plugin); 991 if (plugin->hasCommandHandler()) 992 commandHandlers_.insert(commandHandlers_.end(), plugin); 990 channels_.add_plugin(plugin); 991 if (plugin->hasNotificationHandler()) { 992 channels_.register_listener(plugin->get_id(), _T("NSCA")); 993 } 993 994 if (plugin->hasMessageHandler()) 994 995 messageHandlers_.insert(messageHandlers_.end(), plugin); … … 1109 1110 } 1110 1111 } else */{ 1111 /*1112 1112 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 1113 1113 if (!readLock.owns_lock()) { … … 1115 1115 return NSCAPI::returnUNKNOWN; 1116 1116 } 1117 */1118 1117 try { 1119 1118 nsclient::commands::plugin_type plugin = commands_.get(command); … … 1132 1131 return NSCAPI::returnIgnored; 1133 1132 } 1133 } 1134 } 1135 1136 1137 NSCAPI::errorReturn NSClientT::send_notification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len) { 1138 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 1139 if (!readLock.owns_lock()) { 1140 LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex.")); 1141 return NSCAPI::hasFailed; 1142 } 1143 try { 1144 LOG_ERROR_CORE_STD(_T("Notifying: ") + strEx::strip_hex(to_wstring(std::string(result,result_len)))); 1145 bool found = false; 1146 BOOST_FOREACH(nsclient::channels::plugin_type p, channels_.get(channel)) { 1147 p->handleNotification(channel, command, code, result, result_len); 1148 found = true; 1149 } 1150 if (!found) { 1151 LOG_ERROR_CORE_STD(_T("Noone listens for events from: ") + std::wstring(channel)); 1152 } 1153 return NSCAPI::isSuccess; 1154 } catch (nsclient::channels::channel_exception &e) { 1155 LOG_ERROR_CORE(_T("No handler for channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what())); 1156 return NSCAPI::hasFailed; 1157 } catch (...) { 1158 LOG_ERROR_CORE(_T("Error handling channel: ") + std::wstring(channel)); 1159 return NSCAPI::hasFailed; 1134 1160 } 1135 1161 } -
service/NSClient++.h
r2018659 r40970de 30 30 #include "NSCPlugin.h" 31 31 #include "commands.hpp" 32 #include "channels.hpp" 32 33 #include "logger.hpp" 33 34 … … 101 102 typedef std::list<cached_log_entry> log_cache_type; 102 103 pluginList plugins_; 103 pluginList commandHandlers_;104 104 pluginList messageHandlers_; 105 105 boost::filesystem::wpath basePath; … … 122 122 bool enable_shared_session_; 123 123 nsclient::commands commands_; 124 nsclient::channels channels_; 124 125 125 126 126 127 public: 127 128 // c-tor, d-tor 128 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this) {}129 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this) {} 129 130 virtual ~NSClientT(void) {} 130 131 void enableDebug(bool debug = true) { … … 163 164 // Member functions 164 165 boost::filesystem::wpath getBasePath(void); 166 NSCAPI::errorReturn send_notification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 165 167 NSCAPI::nagiosReturn injectRAW(const wchar_t* command, std::string &request, std::string &response); 166 168 NSCAPI::nagiosReturn inject(std::wstring command, std::wstring arguments, std::wstring &msg, std::wstring & perf); -
service/core_api.cpp
rc0d7e82 r40970de 433 433 } 434 434 435 NSCAPI::errorReturn NSAPINotify(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const wchar_t* message, const wchar_t* perf) { 436 LOG_ERROR_STD(_T("TODO: implment channels: ") + std::wstring(command)); 437 return NSCAPI::hasFailed; 435 NSCAPI::errorReturn NSAPINotify(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len) { 436 return mainClient.send_notification(channel, command, code, result, result_len); 438 437 } 439 438 -
service/core_api.h
r2018659 r40970de 58 58 NSCAPI::errorReturn NSAPIReleasePluginList(int,NSCAPI::plugin_info*[]); 59 59 NSCAPI::errorReturn NSAPISettingsSave(void); 60 NSCAPI::errorReturn NSAPINotify(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, c onst wchar_t*, const wchar_t*);60 NSCAPI::errorReturn NSAPINotify(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, char*, unsigned int); 61 61 void NSAPIDestroyBuffer(char**);
Note: See TracChangeset
for help on using the changeset viewer.








