Changeset 497b779 in nscp for modules/NRPEServer
- Timestamp:
- 08/19/10 13:36:13 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- de7ec29
- Parents:
- 184d575
- Location:
- modules/NRPEServer
- Files:
-
- 1 added
- 4 edited
-
NRPEServer.cpp (modified) (3 diffs)
-
NRPEServer.def (modified) (1 diff)
-
NRPEServer.h (modified) (2 diffs)
-
handler_impl.hpp (modified) (2 diffs)
-
module.cmake (added)
Legend:
- Unmodified
- Added
- Removed
-
modules/NRPEServer/NRPEServer.cpp
r184d575 r497b779 27 27 #include "handler_impl.hpp" 28 28 29 namespace sh = nscapi::settings_helper; 30 29 31 NRPEListener gNRPEListener; 30 32 31 NRPEListener::NRPEListener() : noPerfData_(false), info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(0))) { 32 } 33 NRPEListener::~NRPEListener() { 34 std::cout << "TERMINATING TERMINATING!!!" << std::endl; 35 } 33 NRPEListener::NRPEListener() : info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(1024))) { 34 } 35 NRPEListener::~NRPEListener() {} 36 36 37 37 std::wstring getAllowedHosts() { … … 44 44 45 45 46 bool NRPEListener::loadModule(NSCAPI::moduleLoadMode mode) { 47 SETTINGS_REG_KEY_I(nrpe::PORT); 48 SETTINGS_REG_KEY_S(nrpe::BINDADDR); 49 SETTINGS_REG_KEY_I(nrpe::LISTENQUE); 50 SETTINGS_REG_KEY_I(nrpe::READ_TIMEOUT); 51 SETTINGS_REG_KEY_B(nrpe::KEYUSE_SSL); 52 SETTINGS_REG_KEY_I(nrpe::PAYLOAD_LENGTH); 53 SETTINGS_REG_KEY_B(nrpe::ALLOW_PERFDATA); 54 SETTINGS_REG_KEY_S(nrpe::SCRIPT_PATH); 55 SETTINGS_REG_KEY_I(nrpe::CMD_TIMEOUT); 56 SETTINGS_REG_KEY_B(nrpe::ALLOW_ARGS); 57 SETTINGS_REG_KEY_B(nrpe::ALLOW_NASTY); 58 59 SETTINGS_REG_PATH(nrpe::SECTION); 60 SETTINGS_REG_PATH(nrpe::SECTION_HANDLERS); 61 62 info_.use_ssl = SETTINGS_GET_BOOL(nrpe::KEYUSE_SSL)==1; 46 bool NRPEListener::loadModule() { 47 return false; 48 } 49 50 bool NRPEListener::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 51 52 /* 53 DEFINE_SETTING_S(ALLOWED_HOSTS, NRPE_SECTION_PROTOCOL, GENERIC_KEY_ALLOWED_HOSTS, ""); 54 DESCRIBE_SETTING(ALLOWED_HOSTS, "ALLOWED HOST ADDRESSES", "This is a comma-delimited list of IP address of hosts that are allowed to talk to NSClient deamon. If you leave this blank the global version will be used instead."); 55 56 DEFINE_SETTING_B(CACHE_ALLOWED, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_CACHE_ALLOWED, false); 57 DESCRIBE_SETTING_ADVANCED(CACHE_ALLOWED, "ALLOWED HOSTS CACHING", "Used to cache looked up hosts if you check dynamic/changing hosts set this to false."); 58 */ 59 try { 60 61 sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 62 settings.set_alias(alias, _T("NRPE/server")); 63 64 settings.add_path_to_settings() 65 (_T("NRPE SERVER SECTION"), _T("Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options.")) 66 ; 67 68 settings.add_key_to_settings() 69 (_T("port"), sh::uint_key(&info_.port, 5666), 70 _T("PORT NUMBER"), _T("Port to use for NRPE.")) 71 72 (_T("bind to"), sh::string_key(&info_.address), 73 _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 74 75 (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 76 _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 77 78 (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 79 _T("THREAD POOL"), _T("")) 80 81 (_T("timeout"), sh::uint_key(&info_.timeout, 30), 82 _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 83 84 (_T("use ssl"), sh::bool_key(&info_.use_ssl, true), 85 _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 86 87 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024), 88 _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work.")) 89 90 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false), 91 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 92 93 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 94 _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 95 96 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true), 97 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 98 99 (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 100 _T("SSL CERTIFICATE"), _T("")) 101 ; 102 103 settings.register_all(); 104 settings.notify(); 105 63 106 64 107 #ifndef USE_SSL 65 if (bUseSSL_) {66 NSC_LOG_ERROR_STD(_T("SSL not avalible! (not compiled with openssl support)"));67 }108 if (info_.use_ssl) { 109 NSC_LOG_ERROR_STD(_T("SSL not avalible! (not compiled with openssl support)")); 110 } 68 111 #endif 69 70 noPerfData_ = SETTINGS_GET_INT(nrpe::ALLOW_PERFDATA)==0; 71 timeout = SETTINGS_GET_INT(nrpe::READ_TIMEOUT); 72 info_.request_handler->set_payload_length(SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH)); 73 if (info_.request_handler->get_payload_length() != 1024) 74 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(info_.request_handler->get_payload_length())); 75 76 boost::asio::io_service io_service_; 77 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 78 NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 79 try { 80 81 boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 82 info_.certificate = to_string(p.string()); 83 if (boost::filesystem::is_regular(p)) { 84 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + p.string()); 85 } 86 info_.port = to_string(SETTINGS_GET_INT(nrpe::PORT)); 87 info_.address = to_string(SETTINGS_GET_STRING(nrpe::BINDADDR)); 88 unsigned int backLog = SETTINGS_GET_INT(nrpe::LISTENQUE); // @todo: add to info block 89 info_.thread_pool_size = 10; // @todo Add as option 112 if (info_.request_handler->get_payload_length() != 1024) 113 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(info_.request_handler->get_payload_length())); 114 if (!boost::filesystem::is_regular(info_.certificate)) 115 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 116 117 boost::asio::io_service io_service_; 118 119 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 120 NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 121 90 122 if (mode == NSCAPI::normalStart) { 91 123 if (info_.use_ssl) { 92 124 #ifdef USE_SSL 93 125 server_.reset(new nrpe::server::server(info_)); 94 // NSC_LOG_ERROR_STD(_T("SSL not implemented"));95 // return false;96 126 #else 97 127 NSC_LOG_ERROR_STD(_T("SSL is not supported (not compiled with openssl)")); … … 114 144 return false; 115 145 } 146 147 116 148 return true; 117 149 } -
modules/NRPEServer/NRPEServer.def
rcad08fb r497b779 4 4 NSModuleHelperInit 5 5 NSLoadModule 6 NSLoadModuleEx 6 7 NSGetModuleName 7 8 NSGetModuleVersion -
modules/NRPEServer/NRPEServer.h
r294b37b r497b779 37 37 }; 38 38 39 unsigned int timeout;40 39 socketHelpers::allowedHosts allowedHosts; 41 bool noPerfData_;42 40 nrpe::server::server::connection_info info_; 43 41 … … 46 44 virtual ~NRPEListener(); 47 45 // Module calls 48 bool loadModule(NSCAPI::moduleLoadMode mode); 46 bool loadModule(); 47 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 49 48 bool unloadModule(); 50 49 -
modules/NRPEServer/handler_impl.hpp
r294b37b r497b779 11 11 bool noPerfData_; 12 12 public: 13 handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false) {}13 handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false), allowNasty_(false), allowArgs_(false) {} 14 14 15 15 unsigned int get_payload_length() { … … 26 26 } 27 27 28 virtual void set_allow_arguments(bool v) { 29 allowArgs_ = v; 30 } 31 virtual void set_allow_nasty_arguments(bool v) { 32 allowNasty_ = v; 33 } 34 virtual void set_perf_data(bool v) { 35 noPerfData_ = !v; 36 } 37 28 38 void log_debug(std::wstring file, int line, std::wstring msg) { 29 39 GET_CORE()->Message(NSCAPI::debug, file, line, msg);
Note: See TracChangeset
for help on using the changeset viewer.








