Changeset 9bd40e2 in nscp
- Timestamp:
- 05/06/12 21:25:45 (13 months ago)
- Branches:
- master, 0.4.1, 0.4.2
- Children:
- ef5832c
- Parents:
- 53473f7
- Files:
-
- 4 added
- 20 deleted
- 22 edited
-
changelog (modified) (1 diff)
-
include/check_nt/server/connection.cpp (deleted)
-
include/check_nt/server/connection.hpp (deleted)
-
include/check_nt/server/handler.hpp (modified) (1 diff)
-
include/check_nt/server/parser.hpp (modified) (1 diff)
-
include/check_nt/server/protocol.hpp (added)
-
include/check_nt/server/server.cpp (deleted)
-
include/check_nt/server/server.hpp (deleted)
-
include/check_nt/server/ssl_connection.cpp (deleted)
-
include/check_nt/server/ssl_connection.hpp (deleted)
-
include/check_nt/server/tcp_connection.cpp (deleted)
-
include/check_nt/server/tcp_connection.hpp (deleted)
-
include/nrpe/server/connection.cpp (deleted)
-
include/nrpe/server/connection.hpp (deleted)
-
include/nrpe/server/handler.hpp (modified) (1 diff)
-
include/nrpe/server/parser.hpp (modified) (3 diffs)
-
include/nrpe/server/protocol.hpp (added)
-
include/nrpe/server/server.cpp (deleted)
-
include/nrpe/server/server.hpp (deleted)
-
include/nrpe/server/ssl_connection.cpp (deleted)
-
include/nrpe/server/ssl_connection.hpp (deleted)
-
include/nrpe/server/tcp_connection.cpp (deleted)
-
include/nrpe/server/tcp_connection.hpp (deleted)
-
include/nsca/nsca_socket.hpp (modified) (1 diff)
-
include/nsca/server/connection.cpp (deleted)
-
include/nsca/server/connection.hpp (deleted)
-
include/nsca/server/handler.hpp (modified) (1 diff)
-
include/nsca/server/parser.hpp (modified) (2 diffs)
-
include/nsca/server/protocol.hpp (added)
-
include/nsca/server/server.cpp (deleted)
-
include/nsca/server/server.hpp (deleted)
-
include/socket/connection.hpp (added)
-
include/socket/server.hpp (modified) (4 diffs)
-
modules/NRPEServer/CMakeLists.txt (modified) (4 diffs)
-
modules/NRPEServer/NRPEServer.cpp (modified) (8 diffs)
-
modules/NRPEServer/NRPEServer.h (modified) (2 diffs)
-
modules/NRPEServer/handler_impl.hpp (modified) (1 diff)
-
modules/NSCAServer/CMakeLists.txt (modified) (4 diffs)
-
modules/NSCAServer/NSCAServer.cpp (modified) (5 diffs)
-
modules/NSCAServer/NSCAServer.h (modified) (3 diffs)
-
modules/NSCAServer/handler_impl.cpp (modified) (1 diff)
-
modules/NSCAServer/handler_impl.hpp (modified) (3 diffs)
-
modules/NSClientServer/CMakeLists.txt (modified) (3 diffs)
-
modules/NSClientServer/NSClientServer.cpp (modified) (7 diffs)
-
modules/NSClientServer/NSClientServer.h (modified) (2 diffs)
-
modules/NSClientServer/handler_impl.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r53473f7 r9bd40e2 5 5 * Fix RtlStringFromGUID problem on NT4 6 6 7 2012-05-06 MickeM 8 * Refactored server internals to be more uniform (This is the first step to adding more protocols like NRDP and unittests for check_nt) 9 7 10 2012-05-03 MickeM 8 11 * Fixed issue with parsing size-type (usch as MinCritFree=10G) -
include/check_nt/server/handler.hpp
re1d9a58 r9bd40e2 6 6 namespace check_nt { 7 7 namespace server { 8 class handler {8 class handler : public boost::noncopyable { 9 9 public: 10 handler() {}11 handler(const handler &other) {}12 handler& operator= (const handler &other) {13 return *this;14 }15 10 virtual check_nt::packet handle(check_nt::packet packet) = 0; 16 virtual void log_debug(std::string file, int line, std::wstring msg)= 0;17 virtual void log_error(std::string file, int line, std::wstring msg)= 0;11 virtual void log_debug(std::string module, std::string file, int line, std::string msg) const = 0; 12 virtual void log_error(std::string module, std::string file, int line, std::string msg) const = 0; 18 13 virtual check_nt::packet create_error(std::wstring msg) = 0; 19 14 -
include/check_nt/server/parser.hpp
r682ccd2 r9bd40e2 9 9 namespace check_nt { 10 10 namespace server { 11 class parser : public boost::noncopyable {11 class parser : public boost::noncopyable { 12 12 std::vector<char> buffer_; 13 boost::shared_ptr<check_nt::server::handler> handler_;14 13 public: 15 parser( boost::shared_ptr<check_nt::server::handler> handler) : handler_(handler) {}14 parser() {} 16 15 17 16 template <typename InputIterator> -
include/nrpe/server/handler.hpp
r1ecd26f r9bd40e2 6 6 namespace nrpe { 7 7 namespace server { 8 class handler {8 class handler : boost::noncopyable { 9 9 public: 10 handler() {}11 handler(const handler &other) {}12 handler& operator= (const handler &other) {13 return *this;14 }15 10 virtual nrpe::packet handle(nrpe::packet packet) = 0; 16 virtual void log_debug(std::string file, int line, std::wstring msg)= 0;17 virtual void log_error(std::string file, int line, std::wstring msg)= 0;11 virtual void log_debug(std::string module, std::string file, int line, std::string msg) const = 0; 12 virtual void log_error(std::string module, std::string file, int line, std::string msg) const = 0; 18 13 virtual nrpe::packet create_error(std::wstring msg) = 0; 19 14 virtual unsigned int get_payload_length() = 0; -
include/nrpe/server/parser.hpp
re396b2f r9bd40e2 13 13 unsigned int packet_length_; 14 14 unsigned int payload_length_; 15 boost::shared_ptr<nrpe::server::handler> handler_;16 15 public: 17 parser(boost::shared_ptr<nrpe::server::handler> handler) : handler_(handler) { 18 set_payload_length(handler->get_payload_length()); 16 parser(unsigned int payload_length) : payload_length_(payload_length), packet_length_(nrpe::length::get_packet_length(payload_length)) { 19 17 } 20 18 … … 32 30 return packet; 33 31 } 32 /* 34 33 void set_payload_length(unsigned int length) { 35 34 payload_length_ = length; … … 39 38 return payload_length_; 40 39 } 40 */ 41 41 }; 42 42 -
include/nsca/nsca_socket.hpp
r84cdb9b r9bd40e2 92 92 std::string iv = iv_packet.get_iv(); 93 93 time = iv_packet.get_time(); 94 NSC_DEBUG_MSG(_T("Encrypting using when sending: ") + utf8::cvt<std::wstring>(nsca::nsca_encrypt::helpers::encryption_to_string(encryption_method)) + _T(" and ") + utf8::cvt<std::wstring>(password));94 NSC_DEBUG_MSG(_T("Encrypting using: ") + utf8::cvt<std::wstring>(nsca::nsca_encrypt::helpers::encryption_to_string(encryption_method)) + _T(", password '") + utf8::cvt<std::wstring>(password) + _T("'")); 95 95 crypt_inst.encrypt_init(password, encryption_method, iv); 96 96 return true; -
include/nsca/server/handler.hpp
r9b9be81 r9bd40e2 5 5 namespace nsca { 6 6 namespace server { 7 class handler {7 class handler : boost::noncopyable { 8 8 public: 9 handler() {}10 handler(const handler &other) {}11 handler& operator= (const handler &other) {12 return *this;13 }14 9 virtual void handle(nsca::packet packet) = 0; 15 virtual void log_debug(std::string file, int line, std::wstring msg)= 0;16 virtual void log_error(std::string file, int line, std::wstring msg)= 0;10 virtual void log_debug(std::string module, std::string file, int line, std::string msg) const = 0; 11 virtual void log_error(std::string module, std::string file, int line, std::string msg) const = 0; 17 12 virtual unsigned int get_payload_length() = 0; 18 13 virtual void set_payload_length(unsigned int payload) = 0; -
include/nsca/server/parser.hpp
r0f7b655 r9bd40e2 17 17 boost::shared_ptr<nsca::server::handler> handler_; 18 18 public: 19 parser(boost::shared_ptr<nsca::server::handler> handler) : handler_(handler) { 20 set_payload_length(handler->get_payload_length()); 19 parser(unsigned int payload_length) : payload_length_(payload_length), packet_length_(nsca::length::get_packet_length(payload_length)) { 21 20 } 22 21 … … 41 40 return buffer_; 42 41 } 43 void set_payload_length(unsigned int length) {44 payload_length_ = length;45 packet_length_ = nsca::length::get_packet_length(length);46 }47 int get_payload_lenght() const { return payload_length_; }48 42 std::string::size_type size() { 49 43 return buffer_.size(); -
include/socket/server.hpp
ra629015 r9bd40e2 10 10 11 11 #include <socket/socket_helpers.hpp> 12 #include <socket/connection.hpp> 12 13 #include <strEx.h> 13 14 … … 16 17 namespace server { 17 18 namespace str = nscp::helpers; 18 /* 19 struct dummy_handler { 20 handler() {} 21 handler(const handler &other) {} 22 handler& operator= (const handler &other) { 23 return *this; 24 } 25 virtual std::string handle(std::string packet) = 0; 26 virtual void log_debug(std::string file, int line, std::wstring msg) = 0; 27 virtual void log_error(std::string file, int line, std::wstring msg) = 0; 28 virtual std::string create_error(std::wstring msg) = 0; 29 }; 30 struct dummy_connection_info : public socket_helpers::connection_info { 31 dummy_connection_info(boost::shared_ptr<dummy_handler> request_handler) : request_handler(request_handler) {} 32 dummy_connection_info(const connection_info &other) 33 : socket_helpers::connection_info(other) 34 , request_handler(other.request_handler) 35 {} 36 connection_info& operator=(const connection_info &other) { 37 socket_helpers::connection_info::operator=(other); 38 request_handler = other.request_handler; 39 return *this; 40 } 41 boost::shared_ptr<dummy_handler> request_handler; 42 }; 43 44 45 struct dummy_server_definition { 46 typedef boost::shared_ptr<dummy_handler> handler_type; 47 typedef dummy_connection_info connection_info_type; 48 49 static connection_info_type create(boost::asio::io_service& io_service, boost::asio::ssl::context &context, handler_type handler, connection_info_type info); 50 }; 51 52 */ 19 53 20 class server_exception : public std::exception { 54 21 std::string error; … … 74 41 namespace ip = boost::asio::ip; 75 42 76 template<class ServerDefinition> 77 class server : boost::noncopyable { 43 template<class protocol_type, std::size_t N> 44 class server : private boost::noncopyable { 45 46 typedef socket_helpers::server::connection<protocol_type, N> connection_type; 47 #ifdef USE_SSL 48 typedef socket_helpers::server::ssl_connection<protocol_type, N> ssl_connection_type; 49 #endif 78 50 public: 79 server(typename ServerDefinition::connection_info_type info) 80 : acceptor_(io_service_) 51 server(boost::shared_ptr<protocol_type> protocol) 52 : protocol_(protocol) 53 , acceptor_(io_service_) 81 54 , accept_strand_(io_service_) 82 , request_handler_(info.request_handler)83 55 #ifdef USE_SSL 84 56 , context_(io_service_, boost::asio::ssl::context::sslv23) 85 57 #endif 86 , info_(info) {} 58 { 59 if (!protocol_) 60 throw server_exception("Invalid protocol instance"); 61 } 62 ~server() { 87 63 88 void setup() { 89 if (!request_handler_) 90 throw server_exception("Invalid handler when creating server"); 64 } 91 65 92 // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).66 void start() { 93 67 ip::tcp::resolver resolver(io_service_); 94 68 ip::tcp::resolver::iterator endpoint_iterator; 95 if ( info_.address.empty()) {96 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query( info_.get_port()));69 if (protocol_->get_info().address.empty()) { 70 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(protocol_->get_info().get_port())); 97 71 } else { 98 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query( info_.get_address(), info_.get_port()));72 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(protocol_->get_info().get_address(), protocol_->get_info().get_port())); 99 73 } 100 74 ip::tcp::resolver::iterator end; 101 if (endpoint_iterator == end) 102 throw server_exception("Failed to lookup: " + info_.get_endpoint_string()); 75 if (endpoint_iterator == end) { 76 protocol_->log_error(__FILE__, __LINE__, "Failed to lookup: " + protocol_->get_info().get_endpoint_string()); 77 return; 78 } 79 if (protocol_->get_info().use_ssl) { 103 80 #ifdef USE_SSL 104 if (info_.use_ssl) {105 81 SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 106 request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + str::to_wstring(info_.certificate));107 context_.use_tmp_dh_file(to_string( info_.certificate));82 protocol_->log_debug(__FILE__, __LINE__, "Using certificate: " + utf8::cvt<std::string>(protocol_->get_info().certificate)); 83 context_.use_tmp_dh_file(to_string(protocol_->get_info().certificate)); 108 84 context_.set_verify_mode(boost::asio::ssl::context::verify_none); 85 #else 86 protocol_->log_error(__FILE__, __LINE__, "Not compiled with SSL"); 87 #endif 109 88 } 110 #endif111 89 new_connection_.reset(create_connection()); 112 90 … … 114 92 acceptor_.open(endpoint.protocol()); 115 93 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 116 request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info_.get_endpoint_wstring());94 protocol_->log_debug(__FILE__, __LINE__, "Attempting to bind to: " + protocol_->get_info().get_endpoint_string()); 117 95 acceptor_.bind(endpoint); 118 if ( info_.back_log == connection_info::backlog_default)96 if (protocol_->get_info().back_log == connection_info::backlog_default) 119 97 acceptor_.listen(); 120 98 else 121 acceptor_.listen( info_.back_log);99 acceptor_.listen(protocol_->get_info().back_log); 122 100 123 acceptor_.async_accept(new_connection_->socket(), 124 accept_strand_.wrap( 125 boost::bind(&server<ServerDefinition>::handle_accept, this, boost::asio::placeholders::error) 126 ) 127 ); 128 request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info_.get_endpoint_wstring()); 129 } 101 acceptor_.async_accept(new_connection_->socket(),accept_strand_.wrap( 102 boost::bind(&server::handle_accept, this, boost::asio::placeholders::error) 103 )); 104 protocol_->log_debug(__FILE__, __LINE__, "Bound to: " + protocol_->get_info().get_endpoint_string()); 130 105 131 typename ServerDefinition::connection_type* create_connection() { 132 #ifdef USE_SSL 133 return ServerDefinition::create(io_service_, context_, request_handler_, info_); 134 #else 135 return ServerDefinition::create(io_service_, request_handler_, info_); 136 #endif 137 } 138 139 140 virtual ~server() {} 141 142 /// Run the server's io_service loop. 143 void start() { 144 // Create a pool of threads to run all of the io_services. 145 for (std::size_t i = 0; i < info_.thread_pool_size; ++i) { 146 boost::shared_ptr<boost::thread> thread( 147 new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service_) )); 148 threads_.push_back(thread); 106 for (std::size_t i = 0; i < protocol_->get_info().thread_pool_size; ++i) { 107 thread_group_.create_thread(boost::bind(&boost::asio::io_service::run, &io_service_)); 149 108 } 150 request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + str::to_wstring(info_.thread_pool_size));151 109 } 152 110 153 111 void stop() { 154 112 io_service_.stop(); 155 for (std::size_t i = 0; i < threads_.size(); ++i) 156 threads_[i]->join(); 113 thread_group_.join_all(); 157 114 } 158 115 116 private: 159 117 void handle_accept(const boost::system::error_code& e) { 160 118 if (!e) { 161 119 std::list<std::string> errors; 162 try { 163 if (info_.allowed_hosts.is_allowed(new_connection_->socket().remote_endpoint().address(), errors)) { 164 std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 165 request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + str::to_wstring(s)); 166 new_connection_->start(); 167 } else { 168 BOOST_FOREACH(const std::string &e, errors) { 169 request_handler_->log_error(__FILE__, __LINE__, utf8::cvt<std::wstring>(e)); 170 } 171 std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 172 request_handler_->log_error(__FILE__, __LINE__, _T("Rejcted connection from: ") + str::to_wstring(s)); 173 new_connection_->stop(); 174 } 175 } catch(const std::exception &e) { 120 if (protocol_->on_accept(new_connection_->socket())) { 121 new_connection_->start(); 122 } else { 176 123 new_connection_->stop(); 177 request_handler_->log_error(__FILE__, __LINE__, utf8::cvt<std::wstring>(e.what()));178 124 } 125 179 126 new_connection_.reset(create_connection()); 127 180 128 acceptor_.async_accept(new_connection_->socket(), 181 accept_strand_.wrap(boost::bind(&server<ServerDefinition>::handle_accept, this, boost::asio::placeholders::error)) 182 ); 129 accept_strand_.wrap( 130 boost::bind(&server::handle_accept, this, boost::asio::placeholders::error) 131 ) 132 ); 183 133 } else { 184 request_handler_->log_error(__FILE__, __LINE__, _T("Socket ERROR: ") + str::to_wstring(e.message()));134 protocol_->log_error(__FILE__, __LINE__, "Socket ERROR: " + e.message()); 185 135 } 186 136 } 187 137 188 189 private: 138 typename connection_type* create_connection() { 139 #ifdef USE_SSL 140 if (protocol_->get_info().use_ssl) { 141 return new ssl_connection_type(io_service_, context_, protocol_); 142 } 143 #endif 144 return new connection_type(io_service_, protocol_); 145 } 190 146 191 147 boost::asio::io_service io_service_; 192 193 148 boost::asio::ip::tcp::acceptor acceptor_; 194 195 boost::shared_ptr<typename ServerDefinition::connection_type> new_connection_; 196 197 std::vector<boost::shared_ptr<boost::thread> > threads_; 198 199 typename ServerDefinition::handler_type request_handler_; 200 149 boost::shared_ptr<connection_type> new_connection_; 150 boost::thread_group thread_group_; 201 151 #ifdef USE_SSL 202 152 boost::asio::ssl::context context_; 203 153 #endif 154 boost::asio::strand accept_strand_; 155 boost::shared_ptr<protocol_type> protocol_; 204 156 205 boost::asio::strand accept_strand_;206 207 typename ServerDefinition::connection_info_type info_;208 157 }; 209 158 -
modules/NRPEServer/CMakeLists.txt
r8d89d7a r9bd40e2 12 12 "${TARGET}.cpp" 13 13 "handler_impl.cpp" 14 ${NSCP_INCLUDEDIR}/nrpe/server/server.cpp15 ${NSCP_INCLUDEDIR}/nrpe/server/connection.cpp16 ${NSCP_INCLUDEDIR}/nrpe/server/tcp_connection.cpp17 ${NSCP_INCLUDEDIR}/nrpe/server/ssl_connection.cpp18 14 ${NSCP_INCLUDEDIR}/nrpe/packet.cpp 19 15 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp … … 33 29 "${TARGET}.def" 34 30 "handler_impl.hpp" 35 ${NSCP_INCLUDEDIR}/nrpe/server/server.hpp 36 ${NSCP_INCLUDEDIR}/nrpe/server/connection.hpp 37 ${NSCP_INCLUDEDIR}/nrpe/server/tcp_connection.hpp 38 ${NSCP_INCLUDEDIR}/nrpe/server/ssl_connection.hpp 31 ${NSCP_INCLUDEDIR}/nrpe/server/protocol.hpp 39 32 ${NSCP_INCLUDEDIR}/nrpe/server/handler.hpp 40 33 ${NSCP_INCLUDEDIR}/nrpe/server/parser.hpp … … 42 35 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 43 36 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 37 ${NSCP_INCLUDEDIR}/socket/server.hpp 38 ${NSCP_INCLUDEDIR}/socket/connection.hpp 44 39 45 40 ${NSCP_DEF_PLUGIN_HPP} … … 58 53 INCLUDE(${BUILD_CMAKE_FOLDER}/module.cmake) 59 54 SOURCE_GROUP("Server" REGULAR_EXPRESSION .*include/nrpe/.*) 55 SOURCE_GROUP("Socket" REGULAR_EXPRESSION .*include/socket/.*) -
modules/NRPEServer/NRPEServer.cpp
r83c2453 r9bd40e2 31 31 32 32 33 NRPE Listener::NRPEListener() : info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(1024))) {33 NRPEServer::NRPEServer() : handler_(new handler_impl(1024)) { 34 34 } 35 NRPE Listener::~NRPEListener() {}35 NRPEServer::~NRPEServer() {} 36 36 37 bool NRPE Listener::loadModule() {37 bool NRPEServer::loadModule() { 38 38 return false; 39 39 } 40 40 41 bool NRPE Listener::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) {41 bool NRPEServer::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 42 42 try { 43 43 … … 46 46 47 47 settings.alias().add_path_to_settings() 48 (_T("NRPE SERVER SECTION"), _T("Section for NRPE (NRPE Listener.dll) (check_nrpe) protocol options."))48 (_T("NRPE SERVER SECTION"), _T("Section for NRPE (NRPEServer.dll) (check_nrpe) protocol options.")) 49 49 ; 50 50 … … 53 53 _T("PORT NUMBER"), _T("Port to use for NRPE.")) 54 54 55 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024),55 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, handler_, _1), 1024), 56 56 _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."), true) 57 57 58 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false),58 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, handler_, _1), false), 59 59 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 60 60 61 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false),61 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, handler_, _1), false), 62 62 _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.")) 63 63 64 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true),64 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, handler_, _1), true), 65 65 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data)."), true) 66 66 … … 104 104 } 105 105 #endif 106 if ( info_.request_handler->get_payload_length() != 1024)107 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()));106 if (handler_->get_payload_length() != 1024) 107 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(handler_->get_payload_length())); 108 108 if (!boost::filesystem::is_regular(info_.certificate)) 109 109 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); … … 120 120 121 121 if (mode == NSCAPI::normalStart) { 122 #ifndef USE_SSL 122 123 if (info_.use_ssl) { 123 #ifdef USE_SSL124 server_.reset(new nrpe::server::server(info_));125 #else126 124 NSC_LOG_ERROR_STD(_T("SSL is not supported (not compiled with openssl)")); 127 125 return false; 126 } 128 127 #endif 129 } else { 130 server_.reset(new nrpe::server::server(info_)); 131 } 128 server_.reset(new nrpe::server::server(boost::shared_ptr<nrpe::read_protocol>(new nrpe::read_protocol(info_, handler_)))); 132 129 if (!server_) { 133 130 NSC_LOG_ERROR_STD(_T("Failed to create server instance!")); … … 136 133 server_->start(); 137 134 } 138 } catch (nrpe::server::nrpe_exception &e) {139 NSC_LOG_ERROR_STD(_T("Exception caught: ") + e.what());140 return false;141 135 } catch (std::exception &e) { 142 136 NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what())); … … 151 145 } 152 146 153 bool NRPE Listener::unloadModule() {147 bool NRPEServer::unloadModule() { 154 148 try { 155 149 if (server_) { … … 165 159 166 160 167 bool NRPE Listener::hasCommandHandler() {161 bool NRPEServer::hasCommandHandler() { 168 162 return false; 169 163 } 170 bool NRPE Listener::hasMessageHandler() {164 bool NRPEServer::hasMessageHandler() { 171 165 return false; 172 166 } 173 167 174 168 NSC_WRAP_DLL(); 175 NSC_WRAPPERS_MAIN_DEF(NRPE Listener);169 NSC_WRAPPERS_MAIN_DEF(NRPEServer); 176 170 NSC_WRAPPERS_IGNORE_MSG_DEF(); 177 171 NSC_WRAPPERS_IGNORE_CMD_DEF(); -
modules/NRPEServer/NRPEServer.h
r81e420c r9bd40e2 21 21 22 22 #include <socket_helpers.hpp> 23 #include <nrpe/server/server.hpp> 23 #include <nrpe/server/protocol.hpp> 24 #include "handler_impl.hpp" 24 25 25 26 NSC_WRAPPERS_MAIN(); 26 27 27 class NRPEListener : public nscapi::impl::simple_plugin { 28 private: 29 typedef enum { 30 inject, script, script_dir, 31 } command_type; 32 struct command_data { 33 command_data() : type(inject) {} 34 command_data(command_type type_, std::wstring arguments_) : type(type_), arguments(arguments_) {} 35 command_type type; 36 std::wstring arguments; 37 }; 38 39 nrpe::server::server::connection_info info_; 40 28 class NRPEServer : public nscapi::impl::simple_plugin { 41 29 public: 42 NRPE Listener();43 virtual ~NRPE Listener();30 NRPEServer(); 31 virtual ~NRPEServer(); 44 32 // Module calls 45 33 bool loadModule(); … … 67 55 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf); 68 56 std::wstring getConfigurationMeta(); 57 58 private: 59 socket_helpers::connection_info info_; 69 60 boost::shared_ptr<nrpe::server::server> server_; 61 boost::shared_ptr<handler_impl> handler_; 70 62 71 private: 63 72 64 class NRPEException { 73 65 std::wstring error_; -
modules/NRPEServer/handler_impl.hpp
r8013c0c r9bd40e2 35 35 noPerfData_ = !v; 36 36 if (noPerfData_) 37 log_debug( __FILE__, __LINE__, _T("Performance data disabled!"));37 log_debug("nrpe", __FILE__, __LINE__, "Performance data disabled!"); 38 38 } 39 39 40 void log_debug(std::string file, int line, std::wstring msg){40 void log_debug(std::string module, std::string file, int line, std::string msg) const { 41 41 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 42 42 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 43 43 } 44 44 } 45 void log_error(std::string file, int line, std::wstring msg){45 void log_error(std::string module, std::string file, int line, std::string msg) const { 46 46 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 47 47 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); -
modules/NSCAServer/CMakeLists.txt
r8d89d7a r9bd40e2 9 9 "${TARGET}.cpp" 10 10 "handler_impl.cpp" 11 ${NSCP_INCLUDEDIR}/nsca/server/server.cpp 12 ${NSCP_INCLUDEDIR}/nsca/server/connection.cpp 11 ${NSCP_INCLUDEDIR}/nsca/nsca_packet.cpp 13 12 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 14 ${NSCP_INCLUDEDIR}/nsca/nsca_packet.cpp15 13 16 14 ${NSCP_DEF_PLUGIN_CPP} … … 25 23 ENDIF(HAVE_CRYPTOPP) 26 24 25 #IF(OPENSSL_FOUND) 26 # ADD_DEFINITIONS(-DUSE_SSL) 27 #ENDIF(OPENSSL_FOUND) 28 27 29 ADD_DEFINITIONS(${NSCP_GLOBAL_DEFINES}) 28 30 … … 33 35 "${TARGET}.def" 34 36 "handler_impl.hpp" 35 ${NSCP_INCLUDEDIR}/nsca/server/server.hpp 36 ${NSCP_INCLUDEDIR}/nsca/server/connection.hpp 37 ${NSCP_INCLUDEDIR}/nsca/server/protocol.hpp 37 38 ${NSCP_INCLUDEDIR}/nsca/server/handler.hpp 38 39 ${NSCP_INCLUDEDIR}/nsca/server/parser.hpp 39 40 ${NSCP_INCLUDEDIR}/nsca/nsca_packet.hpp 40 41 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 42 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 41 43 ${NSCP_INCLUDEDIR}/socket/server.hpp 42 ${NSCP_INCLUDEDIR}/socket/ socket_helpers.hpp44 ${NSCP_INCLUDEDIR}/socket/connection.hpp 43 45 44 46 ${NSCP_DEF_PLUGIN_HPP} … … 54 56 ${Boost_THREAD_LIBRARY} 55 57 ${NSCP_DEF_PLUGIN_LIB} 58 # ${OPENSSL_LIBRARIES} 56 59 ${CRYPTOPP_LIB} 57 60 ) 58 61 INCLUDE(${BUILD_CMAKE_FOLDER}/module.cmake) 59 62 SOURCE_GROUP("Server" REGULAR_EXPRESSION .*include/nsca/.*) 63 SOURCE_GROUP("Socket" REGULAR_EXPRESSION .*include/socket/.*) -
modules/NSCAServer/NSCAServer.cpp
r9b9be81 r9bd40e2 29 29 namespace str = nscp::helpers; 30 30 31 NSCAServer::NSCAServer() : info_(boost::shared_ptr<nsca::server::handler>(new handler_impl(1024))) {}31 NSCAServer::NSCAServer() : handler_(new nsca_handler_impl(1024)) {} 32 32 33 33 bool NSCAServer::loadModule() { … … 50 50 _T("PORT NUMBER"), _T("Port to use for NSCA.")) 51 51 52 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nsca::server::handler::set_payload_length, info_.request_handler, _1), 512),52 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nsca::server::handler::set_payload_length, handler_, _1), 512), 53 53 _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NSCA agent. This is a hard specific value so you have to \"configure\" (read recompile) your NSCA agent to use the same value for it to work.")) 54 54 55 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nsca::server::handler::set_perf_data, info_.request_handler, _1), true),55 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nsca::server::handler::set_perf_data, handler_, _1), true), 56 56 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 57 57 58 (_T("encryption"), sh::string_fun_key<std::string>(boost::bind(&nsca::server::handler::set_encryption, info_.request_handler, _1), "aes"),58 (_T("encryption"), sh::string_fun_key<std::string>(boost::bind(&nsca::server::handler::set_encryption, handler_, _1), "aes"), 59 59 _T("ENCRYPTION"), _T("Encryption to use")) 60 60 61 (_T("password"), sh::string_fun_key<std::string>(boost::bind(&nsca::server::handler::set_password, info_.request_handler, _1), ""),61 (_T("password"), sh::string_fun_key<std::string>(boost::bind(&nsca::server::handler::set_password, handler_, _1), ""), 62 62 _T("PASSWORD"), _T("Password to use")) 63 63 … … 85 85 _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 86 86 87 (_T("inbox"), sh::string_fun_key<std::wstring>(boost::bind(&nsca::server::handler::set_channel, info_.request_handler, _1), _T("inbox")),87 (_T("inbox"), sh::string_fun_key<std::wstring>(boost::bind(&nsca::server::handler::set_channel, handler_, _1), _T("inbox")), 88 88 _T("INBOX"), _T("The default channel to post incoming messages on")) 89 89 … … 93 93 settings.notify(); 94 94 95 if ( info_.request_handler->get_payload_length() != 512)96 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nsca changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos( info_.request_handler->get_payload_length()));95 if (handler_->get_payload_length() != 512) 96 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nsca changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(handler_->get_payload_length())); 97 97 98 98 std::list<std::string> errors; … … 104 104 105 105 if (mode == NSCAPI::normalStart) { 106 server_.reset(new nsca::server::nsca_server(info_)); 106 #ifndef USE_SSL 107 if (info_.use_ssl) { 108 NSC_LOG_ERROR_STD(_T("SSL is not supported (not compiled with openssl)")); 109 return false; 110 } 111 #endif 112 server_.reset(new nsca::server::server(boost::shared_ptr<nsca::read_protocol>(new nsca::read_protocol(info_, handler_)))); 107 113 if (!server_) { 108 114 NSC_LOG_ERROR_STD(_T("Failed to create server instance!")); 109 115 return false; 110 116 } 111 server_->setup();117 //server_->setup(); 112 118 server_->start(); 113 119 } -
modules/NSCAServer/NSCAServer.h
ra629015 r9bd40e2 21 21 22 22 #include <socket_helpers.hpp> 23 #include <nsca/server/ server.hpp>23 #include <nsca/server/protocol.hpp> 24 24 25 25 NSC_WRAPPERS_MAIN(); … … 27 27 class NSCAServer : public nscapi::impl::simple_plugin { 28 28 private: 29 nsca::server::nsca_connection_info info_;29 socket_helpers::connection_info info_; 30 30 31 31 public: … … 55 55 static std::wstring getCryptos(); 56 56 57 boost::shared_ptr<nsca::server::nsca_server> server_; 57 boost::shared_ptr<nsca::server::server> server_; 58 boost::shared_ptr<nsca::server::handler> handler_; 58 59 }; 59 60 -
modules/NSCAServer/handler_impl.cpp
ree52cdd r9bd40e2 6 6 #include <config.h> 7 7 8 void handler_impl::handle(nsca::packet p) {8 void nsca_handler_impl::handle(nsca::packet p) { 9 9 std::wstring response; 10 10 std::string::size_type pos = p.result.find('|'); -
modules/NSCAServer/handler_impl.hpp
r8013c0c r9bd40e2 9 9 #include <unicode_char.hpp> 10 10 11 class handler_impl : public nsca::server::handler, private boost::noncopyable {11 class nsca_handler_impl : public nsca::server::handler, private boost::noncopyable { 12 12 unsigned int payload_length_; 13 13 bool allowArgs_; … … 18 18 std::string password_; 19 19 public: 20 handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false), allowNasty_(false), allowArgs_(false) {}20 nsca_handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false), allowNasty_(false), allowArgs_(false) {} 21 21 22 22 unsigned int get_payload_length() { … … 50 50 noPerfData_ = !v; 51 51 if (noPerfData_) 52 log_debug( __FILE__, __LINE__, _T("Performance data disabled!"));52 log_debug("nsca", __FILE__, __LINE__, "Performance data disabled!"); 53 53 } 54 54 55 void log_debug(std::string file, int line, std::wstring msg){55 void log_debug(std::string module, std::string file, int line, std::string msg) const { 56 56 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 57 57 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 58 58 } 59 59 } 60 void log_error(std::string file, int line, std::wstring msg){60 void log_error(std::string module, std::string file, int line, std::string msg) const { 61 61 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 62 62 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); -
modules/NSClientServer/CMakeLists.txt
r440c0cb r9bd40e2 11 11 stdafx.cpp 12 12 "${TARGET}.cpp" 13 "handler_impl.cpp"14 ${NSCP_INCLUDEDIR}/check_nt/server/server.cpp15 ${NSCP_INCLUDEDIR}/check_nt/server/connection.cpp16 ${NSCP_INCLUDEDIR}/check_nt/server/tcp_connection.cpp17 ${NSCP_INCLUDEDIR}/check_nt/server/ssl_connection.cpp18 13 ${NSCP_INCLUDEDIR}/check_nt/packet.cpp 19 14 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp … … 33 28 "${TARGET}.def" 34 29 "handler_impl.hpp" 35 ${NSCP_INCLUDEDIR}/check_nt/server/server.hpp 36 ${NSCP_INCLUDEDIR}/check_nt/server/connection.hpp 37 ${NSCP_INCLUDEDIR}/check_nt/server/tcp_connection.hpp 38 ${NSCP_INCLUDEDIR}/check_nt/server/ssl_connection.hpp 39 ${NSCP_INCLUDEDIR}/check_nt/server/handler.hpp 30 ${NSCP_INCLUDEDIR}/check_nt/server/protocol.hpp 40 31 ${NSCP_INCLUDEDIR}/check_nt/server/parser.hpp 41 32 ${NSCP_INCLUDEDIR}/check_nt/packet.hpp 42 33 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 34 43 35 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 36 ${NSCP_INCLUDEDIR}/socket/connection.hpp 37 ${NSCP_INCLUDEDIR}/socket/server.hpp 44 38 45 39 ${NSCP_DEF_PLUGIN_HPP} … … 57 51 ) 58 52 INCLUDE(${BUILD_CMAKE_FOLDER}/module.cmake) 53 SOURCE_GROUP("Server" REGULAR_EXPRESSION .*include/check_nt/.*) 54 SOURCE_GROUP("Socket" REGULAR_EXPRESSION .*include/socket/.*) -
modules/NSClientServer/NSClientServer.cpp
r6533c1a r9bd40e2 26 26 #include "handler_impl.hpp" 27 27 #include <settings/client/settings_client.hpp> 28 #include <nscapi/nscapi_core_helper.hpp> 28 29 29 30 namespace sh = nscapi::settings_helper; 30 31 31 NSClientListener::NSClientListener() : info_(boost::shared_ptr<check_nt::server::handler>(new handler_impl())) { 32 } 33 NSClientListener::~NSClientListener() { 34 } 35 36 bool NSClientListener::loadModule() { 32 NSClientServer::NSClientServer() 33 : noPerfData_(false) 34 , allowNasty_(false) 35 , allowArgs_(false) 36 { 37 } 38 NSClientServer::~NSClientServer() { 39 } 40 41 bool NSClientServer::loadModule() { 37 42 return false; 38 43 } 39 44 40 bool NSClient Listener::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) {45 bool NSClientServer::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 41 46 42 47 try { … … 53 58 _T("PORT NUMBER"), _T("Port to use for check_nt.")) 54 59 55 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(& check_nt::server::handler::set_perf_data, info_.request_handler, _1), true),60 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&NSClientServer::set_perf_data, this, _1), true), 56 61 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 57 62 … … 90 95 _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 91 96 92 (_T("password"), sh::string_fun_key<std::wstring>(boost::bind(& check_nt::server::handler::set_password, info_.request_handler, _1), _T("")),97 (_T("password"), sh::string_fun_key<std::wstring>(boost::bind(&NSClientServer::set_password, this, _1), _T("")), 93 98 _T("PASSWORD"), _T("Password used to authenticate againast server")) 94 99 … … 119 124 if (mode == NSCAPI::normalStart) { 120 125 try { 126 #ifndef USE_SSL 121 127 if (info_.use_ssl) { 122 #ifdef USE_SSL123 server_.reset(new check_nt::server::server(info_));124 #else125 128 NSC_LOG_ERROR_STD(_T("SSL is not supported (not compiled with openssl)")); 126 129 return false; 130 } 127 131 #endif 128 } else { 129 server_.reset(new check_nt::server::server(info_)); 130 } 132 server_.reset(new check_nt::server::server(boost::shared_ptr<check_nt::read_protocol>(new check_nt::read_protocol(info_, this)))); 131 133 if (!server_) { 132 134 NSC_LOG_ERROR_STD(_T("Failed to create server instance!")); … … 134 136 } 135 137 server_->start(); 136 137 } catch (check_nt::server::check_nt_exception &e) {138 NSC_LOG_ERROR_STD(_T("Exception caught: ") + e.what());139 return false;140 138 } catch (std::exception &e) { 141 139 NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what())); … … 148 146 return true; 149 147 } 150 bool NSClient Listener::unloadModule() {148 bool NSClientServer::unloadModule() { 151 149 try { 152 150 if (server_) { … … 161 159 } 162 160 161 162 163 #define REQ_CLIENTVERSION 1 // Works fine! 164 #define REQ_CPULOAD 2 // Quirks 165 #define REQ_UPTIME 3 // Works fine! 166 #define REQ_USEDDISKSPACE 4 // Works fine! 167 #define REQ_SERVICESTATE 5 // Works fine! 168 #define REQ_PROCSTATE 6 // Works fine! 169 #define REQ_MEMUSE 7 // Works fine! 170 #define REQ_COUNTER 8 // Works fine! 171 #define REQ_FILEAGE 9 // Works fine! (i hope) 172 #define REQ_INSTANCES 10 // Works fine! (i hope) 173 174 bool NSClientServer::isPasswordOk(std::wstring remotePassword) { 175 std::wstring localPassword = get_password(); 176 if (localPassword == remotePassword) { 177 return true; 178 } 179 if ((remotePassword == _T("None")) && (localPassword.empty())) { 180 return true; 181 } 182 return false; 183 } 184 185 void split_to_list(std::list<std::wstring> &list, std::wstring str) { 186 strEx::splitList add = strEx::splitEx(str, _T("&")); 187 list.insert(list.begin(), add.begin(), add.end()); 188 } 189 190 check_nt::packet NSClientServer::handle(check_nt::packet p) { 191 std::wstring buffer = p.get_payload(); 192 NSC_DEBUG_MSG_STD(_T("Data: ") + buffer); 193 194 std::wstring::size_type pos = buffer.find_first_of(_T("\n\r")); 195 if (pos != std::wstring::npos) { 196 std::wstring::size_type pos2 = buffer.find_first_not_of(_T("\n\r"), pos); 197 if (pos2 != std::wstring::npos) { 198 std::wstring rest = buffer.substr(pos2); 199 NSC_DEBUG_MSG_STD(_T("Ignoring data: ") + rest); 200 } 201 buffer = buffer.substr(0, pos); 202 } 203 204 strEx::token pwd = strEx::getToken(buffer, '&'); 205 if (!isPasswordOk(pwd.first)) { 206 NSC_LOG_ERROR_STD(_T("Invalid password (") + pwd.first + _T(").")); 207 return check_nt::packet("ERROR: Invalid password."); 208 } 209 if (pwd.second.empty()) 210 return check_nt::packet("ERROR: No command specified."); 211 strEx::token cmd = strEx::getToken(pwd.second, '&'); 212 if (cmd.first.empty()) 213 return check_nt::packet("ERROR: No command specified."); 214 215 int c = boost::lexical_cast<int>(cmd.first.c_str()); 216 217 NSC_DEBUG_MSG_STD(_T("Data: ") + cmd.second); 218 219 std::list<std::wstring> args; 220 221 // prefix various commands 222 switch (c) { 223 case REQ_CPULOAD: 224 cmd.first = _T("checkCPU"); 225 split_to_list(args, cmd.second); 226 args.push_back(_T("nsclient")); 227 break; 228 case REQ_UPTIME: 229 cmd.first = _T("checkUpTime"); 230 args.push_back(_T("nsclient")); 231 break; 232 case REQ_USEDDISKSPACE: 233 cmd.first = _T("CheckDriveSize"); 234 split_to_list(args, cmd.second); 235 args.push_back(_T("nsclient")); 236 break; 237 case REQ_CLIENTVERSION: 238 { 239 //std::wstring v = SETTINGS_GET_STRING(nsclient::VERSION); 240 //if (v == _T("auto")) 241 std::wstring v = nscapi::plugin_singleton->get_core()->getApplicationName() + _T(" ") + nscapi::plugin_singleton->get_core()->getApplicationVersionString(); 242 return strEx::wstring_to_string(v); 243 } 244 case REQ_SERVICESTATE: 245 cmd.first = _T("checkServiceState"); 246 split_to_list(args, cmd.second); 247 args.push_back(_T("nsclient")); 248 break; 249 case REQ_PROCSTATE: 250 cmd.first = _T("checkProcState"); 251 split_to_list(args, cmd.second); 252 args.push_back(_T("nsclient")); 253 break; 254 case REQ_MEMUSE: 255 cmd.first = _T("checkMem"); 256 args.push_back(_T("nsclient")); 257 break; 258 case REQ_COUNTER: 259 cmd.first = _T("checkCounter"); 260 args.push_back(_T("Counter=") + cmd.second); 261 args.push_back(_T("nsclient")); 262 break; 263 case REQ_FILEAGE: 264 cmd.first = _T("getFileAge"); 265 args.push_back(_T("path=") + cmd.second); 266 break; 267 case REQ_INSTANCES: 268 cmd.first = _T("listCounterInstances"); 269 args.push_back(cmd.second); 270 break; 271 272 273 default: 274 split_to_list(args, cmd.second); 275 } 276 277 std::wstring message, perf; 278 NSCAPI::nagiosReturn ret = nscapi::core_helper::simple_query(cmd.first.c_str(), args, message, perf); 279 if (!nscapi::plugin_helper::isNagiosReturnCode(ret)) { 280 if (message.empty()) 281 return check_nt::packet("ERROR: Could not complete the request check log file for more information."); 282 return check_nt::packet("ERROR: " + strEx::wstring_to_string(message)); 283 } 284 switch (c) { 285 case REQ_UPTIME: // Some check_nt commands has no return code syntax 286 case REQ_MEMUSE: 287 case REQ_CPULOAD: 288 case REQ_CLIENTVERSION: 289 case REQ_USEDDISKSPACE: 290 case REQ_COUNTER: 291 case REQ_FILEAGE: 292 return check_nt::packet(message); 293 294 case REQ_SERVICESTATE: // Some check_nt commands return the return code (coded as a string) 295 case REQ_PROCSTATE: 296 return check_nt::packet(strEx::itos(nscapi::plugin_helper::nagios2int(ret)) + _T("& ") + message); 297 298 default: // "New" check_nscp also returns performance data 299 if (perf.empty()) 300 return check_nt::packet(nscapi::plugin_helper::translateReturn(ret) + _T("&") + message); 301 return check_nt::packet(nscapi::plugin_helper::translateReturn(ret) + _T("&") + message + _T("&") + perf); 302 } 303 304 return check_nt::packet("FOO"); 305 } 306 307 308 163 309 NSC_WRAP_DLL(); 164 NSC_WRAPPERS_MAIN_DEF(NSClient Listener);310 NSC_WRAPPERS_MAIN_DEF(NSClientServer); 165 311 NSC_WRAPPERS_IGNORE_MSG_DEF(); 166 312 NSC_WRAPPERS_IGNORE_CMD_DEF(); -
modules/NSClientServer/NSClientServer.h
r81e420c r9bd40e2 19 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 20 ***************************************************************************/ 21 //#include <Socket.h>22 21 #include <socket_helpers.hpp> 23 #include <check_nt/server/ server.hpp>22 #include <check_nt/server/protocol.hpp> 24 23 25 24 NSC_WRAPPERS_MAIN(); 26 25 27 class NSClientListener : public nscapi::impl::simple_plugin { 28 private: 29 30 check_nt::server::server::connection_info info_; 31 boost::shared_ptr<check_nt::server::server> server_; 32 26 class NSClientServer : public nscapi::impl::simple_plugin, public check_nt::server::handler { 33 27 public: 34 NSClient Listener();35 virtual ~NSClient Listener();28 NSClientServer(); 29 virtual ~NSClientServer(); 36 30 // Module calls 37 31 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); … … 50 44 return _T("A simple server that listens for incoming NSClient (check_nt) connection and handles them.\nAlthough NRPE is the preferred method NSClient is fully supported and can be used for simplicity or for compatibility."); 51 45 } 46 47 48 check_nt::packet handle(check_nt::packet packet); 49 50 check_nt::packet create_error(std::wstring msg) { 51 return check_nt::packet("ERROR: Failed to parse"); 52 } 53 54 void log_debug(std::string module, std::string file, int line, std::string msg) const { 55 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 56 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 57 } 58 } 59 void log_error(std::string module, std::string file, int line, std::string msg) const { 60 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 61 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); 62 } 63 } 64 65 std::wstring get_password() const { 66 return password_; 67 } 68 69 private: 70 void set_password(std::wstring password) { 71 password_ = password; 72 } 73 virtual void set_allow_arguments(bool v) { 74 allowArgs_ = v; 75 } 76 virtual void set_allow_nasty_arguments(bool v) { 77 allowNasty_ = v; 78 } 79 virtual void set_perf_data(bool v) { 80 noPerfData_ = !v; 81 } 82 bool isPasswordOk(std::wstring remotePassword); 83 84 private: 85 socket_helpers::connection_info info_; 86 boost::shared_ptr<check_nt::server::server> server_; 87 88 bool allowArgs_; 89 bool allowNasty_; 90 bool noPerfData_; 91 std::wstring password_; 92 52 93 }; -
modules/NSClientServer/handler_impl.hpp
r8013c0c r9bd40e2 30 30 31 31 32 void log_debug(std::string file, int line, std::wstring msg) {32 void log_debug(std::string module, std::string file, int line, std::string msg) { 33 33 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 34 34 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 35 35 } 36 36 } 37 void log_error(std::string file, int line, std::wstring msg) {37 void log_error(std::string module, std::string file, int line, std::string msg) { 38 38 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 39 39 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg);
Note: See TracChangeset
for help on using the changeset viewer.








