Changeset b5a03fe in nscp
- Timestamp:
- 05/10/12 07:29:22 (13 months ago)
- Branches:
- master, 0.4.1, 0.4.2
- Children:
- af05fa1
- Parents:
- ef5832c (diff), df109f9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 4 added
- 21 deleted
- 37 edited
-
changelog (modified) (1 diff)
-
include/nscapi/settings_object.hpp (modified) (1 diff)
-
include/pdh/core.hpp (modified) (3 diffs)
-
include/pdh/counters.hpp (modified) (2 diffs)
-
include/pdh/query.hpp (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (1 diff)
-
modules/CheckExternalScripts/commands.hpp (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (1 diff)
-
modules/CheckSystem/PDHCollector.cpp (modified) (1 diff)
-
modules/Scheduler/schedules.hpp (modified) (1 diff)
-
.gitignore (modified) (1 diff)
-
build/cmake/functions.cmake (modified) (2 diffs)
-
docs/CMakeLists.txt (modified) (1 diff)
-
files/CMakeLists.txt (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)
-
scripts/CMakeLists.txt (modified) (4 diffs)
-
version.hpp (deleted)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r9bd40e2 rb5a03fe 4 4 * Fixa dependonservice LanManWorkStation (old win) 5 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-05-07 MickeM 8 * Fixed parsin of empty sections (CheckExternalScripts) - #524 9 * Fixed so duplicate command are not created when both sections and shorthands are used (CheckExternalScripts) 10 * Added a test to see if I can resolve the negative denominator issue. 6 11 7 12 2012-05-06 MickeM -
include/nscapi/settings_object.hpp
r74e060a r67c6d04 52 52 53 53 t_object_type add(boost::shared_ptr<nscapi::settings_proxy> proxy, std::wstring path, std::wstring alias, std::wstring value, bool is_template = false) { 54 optional_object previous = find_object(alias); 55 if (previous) { 56 t_object_type p = *previous; 57 return p; 58 } 54 59 t_object_type object; 55 60 object.alias = alias; -
include/pdh/core.hpp
r1ecd26f rd6c3131 36 36 bool error_; 37 37 bool more_data_; 38 bool negative_denominator_; 38 39 public: 39 40 /* … … 41 42 PDHError(bool error, bool more_data) : error_(error), more_data_(more_data) {} 42 43 */ 43 PDHError() : error_(false) {} 44 PDHError(PDH_STATUS status) : error_(status!=ERROR_SUCCESS), more_data_(status==PDH_MORE_DATA) { 44 PDHError() : error_(false), more_data_(false), negative_denominator_(false) {} 45 PDHError(PDH_STATUS status) : error_(status!=ERROR_SUCCESS), more_data_(status==PDH_MORE_DATA), negative_denominator_(status==PDH_CALC_NEGATIVE_DENOMINATOR) 46 { 45 47 if (is_error()) { 46 48 message_ = error::format::from_module(_T("PDH.DLL"), status); 47 49 } 48 50 } 49 PDHError(const PDHError &other) : error_(other.error_), more_data_(other.more_data_), message_(other.message_) {}51 PDHError(const PDHError &other) : error_(other.error_), more_data_(other.more_data_), message_(other.message_), negative_denominator_(other.negative_denominator_) {} 50 52 PDHError& operator=(PDHError const& other) { 51 53 error_ = other.error_; 52 54 more_data_ = other.more_data_; 53 55 message_ = other.message_; 56 negative_denominator_ = other.negative_denominator_; 54 57 return *this; 55 58 } … … 70 73 bool is_more_data() { 71 74 return more_data_; 75 } 76 bool is_negative_denominator() { 77 return negative_denominator_; 72 78 } 73 79 }; -
include/pdh/counters.hpp
r74e060a rd6c3131 59 59 listener_ = listener; 60 60 } 61 PDH::PDHError validate() { 62 return PDH::PDHFactory::get_impl()->PdhValidatePath(name_.c_str(), false); 63 } 61 64 62 65 PDHCounterInfo getCounterInfo(BOOL bExplainText = FALSE) { … … 109 112 DWORD format = listener_->getFormat(); 110 113 PDH::PDHError status = PDH::PDHFactory::get_impl()->PdhGetFormattedCounterValue(hCounter_, format, NULL, &data_); 114 if (status.is_negative_denominator()) { 115 Sleep(500); 116 status = PDH::PDHFactory::get_impl()->PdhGetFormattedCounterValue(hCounter_, format, NULL, &data_); 117 } 111 118 if (status.is_error()) { 112 119 throw PDHException(name_, _T("PdhGetFormattedCounterValue failed {format: ") + strEx::itos(format) + _T("}"), status); -
include/pdh/query.hpp
r1ecd26f rd6c3131 31 31 namespace PDH { 32 32 class PDHQuery : public PDH::PDHImplSubscriber { 33 p rivate:33 public: 34 34 typedef boost::shared_ptr<PDHCounter> counter_ptr; 35 35 typedef boost::shared_ptr<PDHCounterListener> listener_ptr; -
modules/CheckExternalScripts/CheckExternalScripts.cpp
r6533c1a r67c6d04 249 249 int result = process::executeProcess(args, message, perf); 250 250 if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 251 nscapi::functions::create_simple_query_response_unknown(data.command, _T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result), _T(""), response);251 nscapi::functions::create_simple_query_response_unknown(data.command, _T("The command (") + args.command + _T(") returned an invalid return code: ") + strEx::itos(result), _T(""), response); 252 252 return NSCAPI::returnUNKNOWN; 253 253 } -
modules/CheckExternalScripts/commands.hpp
r8d89d7a r67c6d04 84 84 85 85 void set_command(std::wstring str) { 86 if (str.empty()) 87 return; 86 88 try { 87 89 strEx::parse_command(str, command, arguments); -
modules/CheckSystem/CheckSystem.cpp
rd9cdcb3 rd6c3131 131 131 typedef PDHCollector::system_counter_data::counter cnt; 132 132 if (default_counters) { 133 data->counters.push_back(cnt(PDH_SYSTEM_KEY_MCL, _T("\\4\\30"), cnt::type_int64, cnt::format_large, cnt::value)); 133 134 data->counters.push_back(cnt(PDH_SYSTEM_KEY_CPU, _T("\\238(_total)\\6"), cnt::type_int64, cnt::format_large, cnt::rrd)); 134 135 data->counters.push_back(cnt(PDH_SYSTEM_KEY_MCB, _T("\\4\\26"), cnt::type_int64, cnt::format_large, cnt::value)); 135 data->counters.push_back(cnt(PDH_SYSTEM_KEY_MCL, _T("\\4\\30"), cnt::type_int64, cnt::format_large, cnt::value));136 136 data->counters.push_back(cnt(PDH_SYSTEM_KEY_UPT, _T("\\2\\674"), cnt::type_int64, cnt::format_large, cnt::value)); 137 137 } -
modules/CheckSystem/PDHCollector.cpp
rd9cdcb3 rd6c3131 93 93 try { 94 94 NSC_DEBUG_MSG_STD(_T("Loading counter: ") + c.alias + _T(" = ") + c.path); 95 95 96 c.set_default_buffer_size(default_buffer_length); 96 97 collector_ptr collector = c.create(check_intervall_); 97 98 if (collector) { 98 99 counters_[c.alias] = collector; 99 pdh.addCounter(c.path, collector); 100 PDH::PDHQuery::counter_ptr counter = pdh.addCounter(c.path, collector); 101 PDH::PDHError status = counter->validate(); 102 if (status.is_error()) { 103 NSC_DEBUG_MSG_STD(_T("Counter status: ") + status.to_wstring()); 104 } 100 105 } else { 101 106 NSC_LOG_ERROR_STD(_T("Failed to load counter: ") + c.alias + _T(" = ") + c.path); -
modules/Scheduler/schedules.hpp
r8d89d7a rdf109f9 75 75 } 76 76 void set_command(std::wstring str) { 77 strEx::parse_command(str, command, arguments); 77 if (!str.empty()) { 78 strEx::parse_command(str, command, arguments); 79 } 78 80 } 79 81 -
.gitignore
rd9cdcb3 r53473f7 5 5 # Generated config 6 6 include/config.h 7 version.hpp 7 8 8 9 # Python -
build/cmake/functions.cmake
r441a022 r53473f7 20 20 21 21 22 MACRO(copy_single_file aliassrc destDir)22 MACRO(copy_single_file src destDir) 23 23 GET_FILENAME_COMPONENT(TARGET ${src} NAME) 24 24 SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/${src}) … … 36 36 COMMENT Copying ${source_file} to ${target_file} 37 37 ) 38 ADD_CUSTOM_TARGET(${TARGET}_${alias} ALL DEPENDS ${target_file}) 39 SET_TARGET_PROPERTIES(${TARGET}_${alias} PROPERTIES FOLDER "files/${alias}") 40 INSTALL(CODE "FILE(INSTALL DESTINATION \${CMAKE_INSTALL_PREFIX}/${destDir} TYPE EXECUTABLE FILES \"${source_file}\")") 38 SET(ALL_FILES ${ALL_FILES} ${target_file}) 41 39 ENDMACRO(copy_single_file) 42 40 -
docs/CMakeLists.txt
r7ec3dd1 r53473f7 1 1 cmake_minimum_required(VERSION 2.6) 2 2 3 copy_single_file(docs "Nagios Usage Guide.pdf" docs) 4 copy_single_file(docs "NSClient++ Reference Manual.pdf" docs) 3 SET(ALL_FILES) 4 copy_single_file("Nagios Usage Guide.pdf" docs) 5 copy_single_file("NSClient++ Reference Manual.pdf" docs) 6 7 ADD_CUSTOM_TARGET(copy_docs ALL DEPENDS ${ALL_FILES}) 8 SET_TARGET_PROPERTIES(copy_docs PROPERTIES FOLDER "files") 9 #INSTALL(CODE "FILE(INSTALL DESTINATION \${CMAKE_INSTALL_PREFIX}/${destDir} TYPE EXECUTABLE FILES \"${source_file}\")") -
files/CMakeLists.txt
r7ec3dd1 r53473f7 1 1 cmake_minimum_required(VERSION 2.6) 2 2 3 copy_single_file(files license.txt .) 4 copy_single_file(files nrpe_dh_512.pem security) 5 copy_single_file(files old-settings.map .) 6 copy_single_file(files counters.defs .) 7 copy_single_file(files ../changelog .) 3 SET(ALL_FILES) 4 copy_single_file(license.txt .) 5 copy_single_file(nrpe_dh_512.pem security) 6 copy_single_file(old-settings.map .) 7 copy_single_file(counters.defs .) 8 copy_single_file(../changelog .) 9 10 ADD_CUSTOM_TARGET(copy_files ALL DEPENDS ${ALL_FILES}) 11 SET_TARGET_PROPERTIES(copy_files PROPERTIES FOLDER "files") 12 #INSTALL(CODE "FILE(INSTALL DESTINATION \${CMAKE_INSTALL_PREFIX}/${destDir} TYPE EXECUTABLE FILES \"${source_file}\")") -
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); -
scripts/CMakeLists.txt
r83c2453 r53473f7 13 13 14 14 SET(script_ALL ${scripts_BAT} ${scripts_VBS} ${scripts_PS1}) 15 SET(ALL_FILES) 16 17 15 18 16 19 FOREACH(file ${script_ALL}) 17 20 get_filename_component(filename ${file} NAME) 18 21 #MESSAGE(STATUS " + ${filename} (${file})") 19 copy_single_file( scripts${filename} scripts)22 copy_single_file(${filename} scripts) 20 23 ENDFOREACH(file ${script_ALL}) 21 24 … … 24 27 get_filename_component(filename ${file} NAME) 25 28 #MESSAGE(STATUS " + lib - ${filename}") 26 copy_single_file( "script lib"lib/${filename} scripts/lib)29 copy_single_file(lib/${filename} scripts/lib) 27 30 ENDFOREACH(file ${scripts_LIB}) 28 31 … … 34 37 STRING(REPLACE "." "_" alias "${alias}") 35 38 #MESSAGE(STATUS " + python - ${filename} - ${relpath} - ${alias}") 36 copy_single_file( "python_${alias}"${relpath}/${filename} scripts/${relpath})39 copy_single_file(${relpath}/${filename} scripts/${relpath}) 37 40 ENDFOREACH(file ${scripts_PYT}) 38 41 … … 40 43 get_filename_component(filename ${file} NAME) 41 44 #MESSAGE(STATUS " + lua - ${filename}") 42 copy_single_file( "script lua"lua/${filename} scripts/lua)45 copy_single_file(lua/${filename} scripts/lua) 43 46 ENDFOREACH(file ${scripts_LUA}) 47 48 ADD_CUSTOM_TARGET(copy_scripts ALL DEPENDS ${ALL_FILES}) 49 SET_TARGET_PROPERTIES(copy_scripts PROPERTIES FOLDER "files") 50 #INSTALL(CODE "FILE(INSTALL DESTINATION \${CMAKE_INSTALL_PREFIX}/${destDir} TYPE EXECUTABLE FILES \"${source_file}\")") -
version.txt
rdf109f9 r53473f7 1 version=0.4. 02 build= 1723 date=2012-0 5-081 version=0.4.1 2 build=0 3 date=2012-04-23
Note: See TracChangeset
for help on using the changeset viewer.








