Changeset 8988f9e in nscp
- Timestamp:
- 08/01/10 13:55:49 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 294b37b
- Parents:
- fe9cc46
- Files:
-
- 11 edited
-
CMakeLists.txt (modified) (1 diff)
-
cmake/NSCPPBuffer.cmake (modified) (1 diff)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (2 diffs)
-
include/nscapi/nscapi_plugin_wrapper.hpp (modified) (3 diffs)
-
include/strEx.h (modified) (1 diff)
-
libs/protobuf/plugin.proto (modified) (2 diffs)
-
modules/NRPEServer/NRPEServer.h (modified) (1 diff)
-
modules/NRPEServer/nrpe_handler.cpp (modified) (2 diffs)
-
modules/NRPEServer/nrpe_handler.hpp (modified) (1 diff)
-
modules/NRPEServer/nrpe_server.cpp (modified) (3 diffs)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r5cd6bcf r8988f9e 38 38 IF(WIN32 AND MSVC) 39 39 SET(PROTOBUF_INCLUDE_DIR "${PROTOBUF_DIR}/src" "Path to google protocol buffer source") 40 SET(PROTOBUF_LIBRARYDIR "${PROTOBUF_DIR}/vsprojects/x64/Release") 40 SET(PROTOBUF_LIBRARYDIR_RELEASE "${PROTOBUF_DIR}/vsprojects/x64/Release") 41 SET(PROTOBUF_LIBRARYDIR_DEBUG "${PROTOBUF_DIR}/vsprojects/x64/Debug") 41 42 SET(PROTOBUF_BINARYDIR "${PROTOBUF_DIR}/vsprojects/debug") 42 43 ELSE(WIN32 AND MSVC) -
cmake/NSCPPBuffer.cmake
racf0660 r8988f9e 33 33 ) 34 34 35 FIND_LIBRARY(PROTOBUF_LIBRARY NAMES protobuf libprotobuf 35 FIND_LIBRARY(PROTOBUF_LIBRARY_RELEASE 36 NAMES protobuf libprotobuf 36 37 PATHS 37 38 ${GNUWIN32_DIR}/lib 39 ${PROTOBUF_LIBRARYDIR_RELEASE} 38 40 ${PROTOBUF_LIBRARYDIR} 39 41 ) 40 42 FIND_LIBRARY(PROTOBUF_LIBRARY_DEBUG 43 NAMES protobuf libprotobuf 44 PATHS 45 ${GNUWIN32_DIR}/lib 46 ${PROTOBUF_LIBRARYDIR_DEBUG} 47 ${PROTOBUF_LIBRARYDIR} 48 ) 49 SET(PROTOBUF_LIBRARY 50 debug ${PROTOBUF_LIBRARY_DEBUG} 51 optimized ${PROTOBUF_LIBRARY_RELEASE} 52 ) 53 54 41 55 FIND_PROGRAM(PROTOBUF_PROTOC_EXECUTABLE protoc) 42 56 IF(NOT PROTOBUF_PROTOC_EXECUTABLE) -
include/nscapi/nscapi_core_wrapper.cpp
racf0660 r8988f9e 24 24 25 25 #include <nscapi/nscapi_core_wrapper.hpp> 26 #include <nscapi/nscapi_plugin_wrapper.hpp> 26 27 #include <settings/macros.h> 27 28 #include <arrayBuffer.h> … … 134 135 return NSCAPI::returnUNKNOWN; 135 136 } 136 msg = to_wstring(rsp_msg.payload(0).message()); 137 ::PluginCommand::Response payload = rsp_msg.payload(0); 138 msg = to_wstring(payload.message()); 139 CORE_LOG_ERROR_STD(_T("Attempting to parse perf data")); 140 perf = to_wstring(::nscapi::functions::build_performance_data(payload)); 141 CORE_LOG_ERROR_STD(_T("Attempting to parse perf data: '") + perf + _T("'")); 137 142 } 138 143 return ret; -
include/nscapi/nscapi_plugin_wrapper.hpp
rfe9cc46 r8988f9e 94 94 extern helper_singleton* plugin_singleton; 95 95 96 class functions { 97 public: 98 static PluginCommand::Response_Code nagios_to_gpb(int ret) { 99 if (ret == NSCAPI::returnOK) 100 return PluginCommand::Response_Code_OK; 101 if (ret == NSCAPI::returnWARN) 102 return PluginCommand::Response_Code_WARNING; 103 if (ret == NSCAPI::returnCRIT) 104 return PluginCommand::Response_Code_CRITCAL; 105 return PluginCommand::Response_Code_UNKNOWN; 106 } 107 108 static double trim_to_double(std::wstring s) { 109 std::wstring::size_type pend = s.find_first_not_of(_T("0123456789,.")); 110 if (pend != std::wstring::npos) 111 s = s.substr(0,pend); 112 strEx::replace(s, _T(","), _T(".")); 113 return strEx::stod(s); 114 } 115 116 static void parse_performance_data(PluginCommand::Response *resp, std::wstring &perf) { 117 strEx::splitList items = strEx::splitEx(perf, _T(" ")); 118 for (strEx::splitList::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 119 strEx::splitVector items = strEx::splitV(*cit, _T(";")); 120 if (items.size() < 3) 121 break; 122 123 ::PluginCommand::PerformanceData* perfData = resp->add_perf(); 124 perfData->set_type(PluginCommand::PerformanceData_Type_FLOAT); 125 std::pair<std::wstring,std::wstring> fitem = strEx::split(items[0], _T("=")); 126 perfData->set_alias(to_string(fitem.first)); 127 ::PluginCommand::PerformanceData_FloatValue* floatPerfData = perfData->mutable_float_value(); 128 129 std::wstring::size_type pend = fitem.second.find_first_not_of(_T("0123456789,.")); 130 if (pend == std::wstring::npos) { 131 floatPerfData->set_value(trim_to_double(fitem.second.c_str())); 132 } else { 133 floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend).c_str())); 134 floatPerfData->set_unit(to_string(fitem.second.substr(pend))); 135 } 136 floatPerfData->set_warning(trim_to_double(items[1])); 137 floatPerfData->set_critical(trim_to_double(items[2])); 138 if (items.size() >= 5) { 139 floatPerfData->set_minimum(trim_to_double(items[3])); 140 floatPerfData->set_maximum(trim_to_double(items[4])); 141 } 142 } 143 } 144 static std::string build_performance_data(::PluginCommand::Response &payload) { 145 std::string ret; 146 for (int i=0;i<payload.perf_size();i++) { 147 ::PluginCommand::PerformanceData perfData = payload.perf(i); 148 if (!ret.empty()) 149 ret += " "; 150 ret += perfData.alias() + "="; 151 if (perfData.has_float_value()) { 152 ::PluginCommand::PerformanceData_FloatValue fval = perfData.float_value(); 153 ret += to_string(fval.value()); 154 if (fval.has_unit()) 155 ret += fval.unit(); 156 if (!fval.has_warning()) continue; 157 ret += ";" + to_string(fval.warning()); 158 if (!fval.has_critical()) continue; 159 ret += ";" + to_string(fval.critical()); 160 if (!fval.has_minimum()) continue; 161 ret += ";" + to_string(fval.minimum()); 162 if (!fval.has_maximum()) continue; 163 ret += ";" + to_string(fval.maximum()); 164 } 165 } 166 return ret; 167 } 168 }; 169 96 170 namespace impl { 97 171 … … 108 182 109 183 ::PluginCommand::Response payload = message.payload().Get(0); 184 110 185 std::list<std::wstring> args; 111 186 for (int i=0;i<payload.arguments_size();i++) { 112 187 args.push_back(to_wstring(payload.arguments(i))); 113 188 } 114 std::wstring msg = to_wstring(payload.message()), perf; 189 std::wstring msg = to_wstring(payload.message()); 190 std::wstring perf = to_wstring(::nscapi::functions::build_performance_data(payload)); 115 191 NSCAPI::nagiosReturn ret = handleSimpleNotification(channel, command, code, msg, perf); 116 192 } catch (std::exception &e) { … … 155 231 resp->set_command(to_string(command)); 156 232 resp->set_message(to_string(msg)); 233 ::nscapi::functions::parse_performance_data(resp, perf); 234 157 235 resp->set_version(PluginCommand::Response_Version_VERSION_1); 158 if (ret == NSCAPI::returnOK) 159 resp->set_result(PluginCommand::Response_Code_OK); 160 else if (ret == NSCAPI::returnWARN) 161 resp->set_result(PluginCommand::Response_Code_WARNING); 162 else if (ret == NSCAPI::returnCRIT) 163 resp->set_result(PluginCommand::Response_Code_CRITCAL); 164 else 165 resp->set_result(PluginCommand::Response_Code_UNKNOWN); 166 236 resp->set_result(nscapi::functions::nagios_to_gpb(ret)); 167 237 response_message.SerializeToString(&response); 168 238 return ret; -
include/strEx.h
r5735dda r8988f9e 552 552 553 553 typedef std::list<std::wstring> splitList; 554 inline splitList splitEx( std::wstring str,std::wstring key) {554 inline splitList splitEx(const std::wstring str, const std::wstring key) { 555 555 splitList ret; 556 std::wstring::size_type pos = 0, lpos = 0; 557 while ((pos = str.find(key, pos)) != std::wstring::npos) { 558 ret.push_back(str.substr(lpos, pos-lpos)); 559 lpos = ++pos; 560 } 561 if (lpos < str.size()) 562 ret.push_back(str.substr(lpos)); 563 return ret; 564 } 565 typedef std::vector<std::wstring> splitVector; 566 inline splitVector splitV(const std::wstring str, const std::wstring key) { 567 splitVector ret; 556 568 std::wstring::size_type pos = 0, lpos = 0; 557 569 while ((pos = str.find(key, pos)) != std::wstring::npos) { -
libs/protobuf/plugin.proto
r40970de r8988f9e 37 37 message IntValue { 38 38 required int64 value = 1; 39 required int64 maximum = 2; 40 required int64 minimum = 3; 41 required string unit = 4; 39 optional string unit = 2; 40 optional int64 warning = 3; 41 optional int64 critical = 4; 42 optional int64 minimum = 6; 43 optional int64 maximum = 7; 42 44 } 43 45 message StringValue { … … 45 47 } 46 48 message FloatValue { 47 required float value = 1; 48 required float maximum = 2; 49 required float minimum = 3; 50 required string unit = 4; 49 required double value = 1; 50 optional string unit = 2; 51 optional double warning = 3; 52 optional double critical = 4; 53 optional double minimum = 6; 54 optional double maximum = 7; 51 55 } 52 56 required string alias = 1; -
modules/NRPEServer/NRPEServer.h
rcad08fb r8988f9e 54 54 std::wstring getModuleName() { 55 55 #ifdef USE_SSL 56 return _T("NRPE server (w/ SSL)");56 return _T("NRPE server"); 57 57 #else 58 return _T("NRPE server ");58 return _T("NRPE server (no SSL)"); 59 59 #endif 60 60 } -
modules/NRPEServer/nrpe_handler.cpp
rcad08fb r8988f9e 33 33 NSCAPI::nagiosReturn ret = -3; 34 34 try { 35 NSC_DEBUG_MSG_STD(_T("Running command: ") + cmd.first); 35 36 ret = nscapi::plugin_singleton->get_core()->InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 37 NSC_DEBUG_MSG_STD(_T("Running command: ") + cmd.first + _T(" = ") + msg); 36 38 } catch (...) { 37 39 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal exception"), p.get_payload_length()); … … 50 52 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal error."), p.get_payload_length()); 51 53 } 52 if (msg.length() >= p.get_payload_length()-1) { 54 std::wstring data = msg; 55 if (!perf.empty()&&!noPerfData_) { 56 data += _T("|") + perf; 57 } 58 if (data.length() >= p.get_payload_length()-1) { 53 59 NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :(")); 54 msg = msg.substr(0,p.get_payload_length()-2);60 data = data.substr(0,p.get_payload_length()-2); 55 61 } 56 if (perf.empty()||noPerfData_) { 57 return nrpe::packet::create_response(ret, msg, p.get_payload_length()); 58 } else { 59 return nrpe::packet::create_response(ret, msg + _T("|") + perf, p.get_payload_length()); 60 } 62 return nrpe::packet::create_response(ret, data, p.get_payload_length()); 61 63 } 62 64 } -
modules/NRPEServer/nrpe_handler.hpp
r40970de r8988f9e 11 11 public: 12 12 handler(unsigned int payload_length) 13 : payload_length_(payload_length) 13 : payload_length_(payload_length), noPerfData_(false) 14 14 {} 15 15 handler(const handler &other) { -
modules/NRPEServer/nrpe_server.cpp
rf6fbf6f r8988f9e 7 7 #include <vector> 8 8 9 9 10 namespace nrpe { 10 11 namespace server { 12 13 namespace ip = boost::asio::ip; 14 11 15 server::server(const std::string& address, const std::string& port, 12 16 const std::string& doc_root, std::size_t thread_pool_size) … … 18 22 { 19 23 // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR). 20 boost::asio::ip::tcp::resolver resolver(io_service_); 21 boost::asio::ip::tcp::resolver::query query(address, port); 22 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 23 boost::asio::ip::tcp::resolver::iterator end; 24 ip::tcp::resolver resolver(io_service_); 25 ip::tcp::resolver::iterator endpoint_iterator; 26 if (address.empty()) { 27 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(port)); 28 } else { 29 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(address, port)); 30 } 31 ip::tcp::resolver::iterator end; 24 32 if (endpoint_iterator == end) { 25 33 std::cout << "Failed to lookup: " << address << ":" << port << std::endl; 26 34 } 27 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;35 ip::tcp::endpoint endpoint = *endpoint_iterator; 28 36 std::cout << "Binding to: " << address << ":" << port << std::endl; 29 37 acceptor_.open(endpoint.protocol()); 30 acceptor_.set_option( boost::asio::ip::tcp::acceptor::reuse_address(true));38 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 31 39 acceptor_.bind(endpoint); 32 40 acceptor_.listen(); … … 63 71 std::cout << "accept: " << e.message() << std::endl; 64 72 if (!e) { 73 std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 74 std::cout << "Connecting from: " << s <<std::endl; 75 65 76 new_connection_->start(); 66 77 new_connection_.reset(new connection(io_service_, request_handler_)); -
modules/NSCAAgent/NSCAAgent.cpp
rcad08fb r8988f9e 116 116 boost::asio::io_service io_service; 117 117 NSC_DEBUG_MSG_STD(_T("* * *NSCA * * * message: ") + msg); 118 NSC_DEBUG_MSG_STD(_T("* * *NSCA * * * påerformance: ") + perf); 118 119 nsca::socket socket(io_service); 119 120 socket.connect(nscahost_, nscaport_); … … 121 122 packet.code = code; 122 123 packet.host = "hello"; 123 packet.result = to_string(msg) ;124 packet.result = to_string(msg) + "|" + to_string(perf); 124 125 socket.recv_iv(password_, encryption_method_, boost::posix_time::seconds(timeout_)); 125 126 socket.send_nsca(packet, boost::posix_time::seconds(timeout_));
Note: See TracChangeset
for help on using the changeset viewer.








