Changeset c391984 in nscp for include


Ignore:
Timestamp:
04/03/11 23:05:52 (2 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
b7d17f8
Parents:
2d69ab6
Message:

0.4.x:

  • tweaks to the build environment to make the installer work
  • fixed Unicode issue
  • fixed performance data
  • improved so alias doesn't re-process the data so much
Location:
include
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • include/config.h.in

    r1f24a1c rc391984  
    3333#endif 
    3434 
    35 #define SZAPPNAME WSTR("NSClient++") 
     35#define APPLICATION_NAME WSTR("NSClient++") 
    3636 
    3737// Version 
     
    4040//#define SZBETATAG " BETA " 
    4141#define _SZVERSION WSTR(STRPRODUCTVER) WSTR(SZBETATAG) WSTR(STRPRODUCTDATE) 
    42 #define SZVERSION _SZVERSION 
     42#define CURRENT_SERVICE_VERSION _SZVERSION 
    4343//STRPRODUCTVER SZBETATAG STRPRODUCTDATE 
    4444//FILEVER[0] 
     
    5555 
    5656// internal name of the service 
    57 #define SZSERVICENAME        WSTR("NSClientpp") 
     57#define DEFAULT_SERVICE_NAME        WSTR("NSClientpp") 
    5858 
    5959// Description of service 
    60 #define SZSERVICEDESCRIPTION WSTR("Nagios Windows Agent (Provides performance data for Nagios server)") 
     60#define DEFAULT_SERVICE_DESC WSTR("Windows Monitoring Agent (Provides performance data for monitoring solutions like Nagios)") 
    6161 
    6262// displayed name of the service 
    63 #define SZSERVICEDISPLAYNAME SZSERVICENAME WSTR(" (Nagios) ") SZVERSION WSTR(" ") SZARCH 
     63#define SERVICE_NAME SZAPPNAME WSTR(" ") CURRENT_SERVICE_VERSION WSTR(" ") SZARCH 
    6464 
    6565// list of service dependencies - "dep1\0dep2\0\0" 
    66 #define SZDEPENDENCIES       _T("") 
     66#define DEFAULT_SERVICE_DEPS       _T("") 
    6767 
    6868// Buffer size of incoming data (notice this is the maximum request length!) 
  • include/nrpe/server/connection.cpp

    r1ecd26f rc391984  
    5959 
    6060    void connection::handle_read_request(const boost::system::error_code& e, std::size_t bytes_transferred) { 
    61       handler_->log_debug(__FILE__, __LINE__, _T("handle_read data connection")); 
    6261      if (!e) { 
    6362        bool result; 
     
    9998 
    10099    void connection::handle_write_response(const boost::system::error_code& e) { 
    101       handler_->log_debug(__FILE__, __LINE__, _T("Written data")); 
    102100      if (!e) { 
    103101        // Initiate graceful connection closure. 
  • include/nrpe/server/ssl_connection.cpp

    r1ecd26f rc391984  
    2222 
    2323    void ssl_connection::stop() { 
    24       handler_->log_debug(__FILE__, __LINE__, _T("stopped data connection")); 
    2524    } 
    2625 
    2726    void ssl_connection::start() { 
    28       handler_->log_debug(__FILE__, __LINE__, _T("starting ssl_connection")); 
    2927      socket_.async_handshake(boost::asio::ssl::stream_base::server, 
    3028        strand_.wrap( 
     
    3230          ) 
    3331        ); 
    34       handler_->log_debug(__FILE__, __LINE__, _T("starting ssl_connection (started)")); 
    3532    } 
    3633 
    3734    void ssl_connection::handle_handshake(const boost::system::error_code& error) { 
    38       handler_->log_debug(__FILE__, __LINE__, _T("handle_handshake ssl_connection")); 
    3935      if (!error) 
    4036        connection::start(); 
  • include/nscapi/nscapi_core_wrapper.cpp

    r7443b58 rc391984  
    149149    } 
    150150    ::PluginCommand::Response payload = rsp_msg.payload(0); 
    151     msg = to_wstring(payload.message()); 
    152     CORE_LOG_ERROR_STD(_T("Attempting to parse perf data")); 
    153     perf = to_wstring(::nscapi::functions::build_performance_data(payload)); 
    154     CORE_LOG_ERROR_STD(_T("Attempting to parse perf data: '") + perf + _T("'")); 
     151    msg = utf8::cvt<std::wstring>(payload.message()); 
     152    perf = utf8::cvt<std::wstring>(::nscapi::functions::build_performance_data(payload)); 
    155153  } 
    156154  return ret; 
  • include/nscapi/nscapi_plugin_wrapper.hpp

    r7443b58 rc391984  
    3333#include <strEx.h> 
    3434#include <nscapi/settings_proxy.hpp> 
     35#include <nscapi/functions.hpp> 
    3536 
    3637#include "../libs/protobuf/plugin.proto.h" 
     
    3839 
    3940using namespace nscp::helpers; 
    40  
    41 #ifdef WIN32 
    42 //#include <windows.h> 
    43 #endif 
    44  
    4541 
    4642namespace nscapi { 
     
    9692  extern helper_singleton* plugin_singleton; 
    9793 
    98   class functions { 
    99   public: 
    100     static PluginCommand::Response_Code nagios_to_gpb(int ret) { 
    101       if (ret == NSCAPI::returnOK) 
    102         return PluginCommand::Response_Code_OK; 
    103       if (ret == NSCAPI::returnWARN) 
    104         return PluginCommand::Response_Code_WARNING; 
    105       if (ret == NSCAPI::returnCRIT) 
    106         return PluginCommand::Response_Code_CRITCAL; 
    107       return PluginCommand::Response_Code_UNKNOWN; 
    108     } 
    109  
    110     static double trim_to_double(std::wstring s) { 
    111       std::wstring::size_type pend = s.find_first_not_of(_T("0123456789,.")); 
    112       if (pend != std::wstring::npos) 
    113         s = s.substr(0,pend); 
    114       strEx::replace(s, _T(","), _T(".")); 
    115       return strEx::stod(s); 
    116     } 
    117  
    118     static void parse_performance_data(PluginCommand::Response *resp, std::wstring &perf) { 
    119       strEx::splitList items = strEx::splitEx(perf, _T(" ")); 
    120       for (strEx::splitList::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 
    121         strEx::splitVector items = strEx::splitV(*cit, _T(";")); 
    122         if (items.size() < 3) 
    123           break; 
    124  
    125         ::PluginCommand::PerformanceData* perfData = resp->add_perf(); 
    126         perfData->set_type(PluginCommand::PerformanceData_Type_FLOAT); 
    127         std::pair<std::wstring,std::wstring> fitem = strEx::split(items[0], _T("=")); 
    128         perfData->set_alias(to_string(fitem.first)); 
    129         ::PluginCommand::PerformanceData_FloatValue* floatPerfData = perfData->mutable_float_value(); 
    130  
    131         std::wstring::size_type pend = fitem.second.find_first_not_of(_T("0123456789,.")); 
    132         if (pend == std::wstring::npos) { 
    133           floatPerfData->set_value(trim_to_double(fitem.second.c_str())); 
    134         } else { 
    135           floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend).c_str())); 
    136           floatPerfData->set_unit(to_string(fitem.second.substr(pend))); 
    137         } 
    138         floatPerfData->set_warning(trim_to_double(items[1])); 
    139         floatPerfData->set_critical(trim_to_double(items[2])); 
    140         if (items.size() >= 5) { 
    141           floatPerfData->set_minimum(trim_to_double(items[3])); 
    142           floatPerfData->set_maximum(trim_to_double(items[4])); 
    143         } 
    144       } 
    145     } 
    146     static std::string build_performance_data(::PluginCommand::Response &payload) { 
    147       std::string ret; 
    148       for (int i=0;i<payload.perf_size();i++) { 
    149         ::PluginCommand::PerformanceData perfData = payload.perf(i); 
    150         if (!ret.empty()) 
    151           ret += " "; 
    152         ret += perfData.alias() + "="; 
    153         if (perfData.has_float_value()) { 
    154           ::PluginCommand::PerformanceData_FloatValue fval = perfData.float_value(); 
    155           ret += to_string(fval.value()); 
    156           if (fval.has_unit()) 
    157             ret += fval.unit(); 
    158           if (!fval.has_warning())  continue; 
    159           ret += ";" + to_string(fval.warning()); 
    160           if (!fval.has_critical()) continue; 
    161           ret += ";" + to_string(fval.critical()); 
    162           if (!fval.has_minimum())  continue; 
    163           ret += ";" + to_string(fval.minimum()); 
    164           if (!fval.has_maximum())  continue; 
    165           ret += ";" + to_string(fval.maximum()); 
    166         } 
    167       } 
    168       return ret; 
    169     } 
    170   }; 
     94 
    17195 
    17296  namespace impl { 
     
    218142    public: 
    219143      NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response) { 
    220  
    221         std::wstring command = char_command; 
    222         PluginCommand::RequestMessage request_message; 
    223         request_message.ParseFromString(request); 
    224  
    225         if (request_message.payload_size() != 1) { 
    226           return NSCAPI::returnIgnored; 
    227         } 
    228         ::PluginCommand::Request payload = request_message.payload().Get(0); 
    229         std::list<std::wstring> args; 
    230         for (int i=0;i<payload.arguments_size();i++) { 
    231           args.push_back(to_wstring(payload.arguments(i))); 
    232         } 
     144        nscapi::functions::decoded_simple_command_data data = nscapi::functions::process_simple_command_request(char_command, request); 
    233145        std::wstring msg, perf; 
    234         NSCAPI::nagiosReturn ret = handleCommand(command, args, msg, perf); 
    235  
    236         PluginCommand::ResponseMessage response_message; 
    237         ::PluginCommand::Header* hdr = response_message.mutable_header(); 
    238  
    239         hdr->set_type(PluginCommand::Header_Type_RESPONSE); 
    240         hdr->set_version(PluginCommand::Header_Version_VERSION_1); 
    241  
    242         PluginCommand::Response *resp = response_message.add_payload(); 
    243         resp->set_command(to_string(command)); 
    244         resp->set_message(to_string(msg)); 
    245         ::nscapi::functions::parse_performance_data(resp, perf); 
    246  
    247         resp->set_version(PluginCommand::Response_Version_VERSION_1); 
    248         resp->set_result(nscapi::functions::nagios_to_gpb(ret)); 
    249         response_message.SerializeToString(&response); 
    250         return ret; 
     146        NSCAPI::nagiosReturn ret = handleCommand(data.command, data.args, msg, perf); 
     147        return nscapi::functions::process_simple_command_result(data.command, ret, msg, perf, response); 
    251148      } 
    252149 
  • include/pdh/collectors.hpp

    r1ecd26f rc391984  
    283283  public: 
    284284    RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) {} 
    285     RoundINTPDHBufferListenerImpl(int length_) : length(length_), current(0), hasValue_(false), parent_(NULL) { 
    286       PDHCounterMutexHandler mutex(&mutex_); 
    287       if (!mutex.hasLock()) 
    288         return; 
    289       buffer = new TType[length]; 
    290       for (unsigned int i=0; i<length;i++) 
    291         buffer[i] = 0; 
     285    RoundINTPDHBufferListenerImpl(int length_) : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) { 
     286      resize(length_); 
    292287    } 
    293288    virtual ~RoundINTPDHBufferListenerImpl() { 
     
    343338      if (!hasValue_) 
    344339        throw PDHException(get_name(), _T("No value has been collected yet")); 
    345       if ((backItems == 0) || (backItems >= length)) 
    346         throw PDHException(get_name(), _T("Strange error buffer pointers are f*cked up")); 
     340      if (backItems == 0) 
     341        throw PDHException(get_name(), _T("No timeframe given on command line (ie. time=0)")); 
     342      if (backItems >= length) 
     343        throw PDHException(get_name(), _T("Length given larger then interval: ") + strEx::itos(backItems) + _T(" >= ") + strEx::itos(length)); 
    347344      double ret = 0; 
    348345      if (current >= backItems) { 
  • include/strEx.h

    r1f24a1c rc391984  
    850850} 
    851851 
    852  
     852namespace utf8 { 
     853  /** Converts a std::wstring into a std::string with UTF-8 encoding. */ 
     854  template<typename StringT> 
     855  StringT cvt(std::wstring const & string); 
     856 
     857  /** Converts a std::String with UTF-8 encoding into a std::wstring. */ 
     858  template<typename StringT> 
     859  StringT cvt(std::string const & string ); 
     860 
     861  /** Nop specialization for std::string. */ 
     862  template <> 
     863  inline std::string cvt(std::string const & string) { 
     864    return string; 
     865  } 
     866 
     867  /** Nop specialization for std::wstring. */ 
     868  template<> 
     869  inline std::wstring cvt(std::wstring const & rc_string) { 
     870    return rc_string; 
     871  } 
     872 
     873  template<> 
     874  inline std::string cvt(std::wstring const & str) { 
     875    // figure out how many narrow characters we are going to get  
     876    int nChars = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0, NULL, NULL); 
     877    if (nChars == 0) 
     878      return ""; 
     879 
     880    // convert the wide string to a narrow string 
     881    // nb: slightly naughty to write directly into the string like this 
     882    std::string buf; 
     883    buf.resize(nChars); 
     884    WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.length(), const_cast<char*>(buf.c_str()), nChars, NULL, NULL); 
     885    return buf ;  
     886  } 
     887 
     888  template<> 
     889  inline std::wstring cvt(std::string const & str) { 
     890    // figure out how many wide characters we are going to get  
     891    int nChars = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0); 
     892    if (nChars == 0) 
     893      return L""; 
     894 
     895    // convert the narrow string to a wide string  
     896    // nb: slightly naughty to write directly into the string like this 
     897    std::wstring buf; 
     898    buf.resize(nChars); 
     899    MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), const_cast<wchar_t*>(buf.c_str()), nChars); 
     900    return buf; 
     901  } 
     902} 
  • include/unicode_char.hpp

    r7f9c823 rc391984  
    1010 
    1111#endif 
     12 
     13#include <unicode/ustring.h> 
Note: See TracChangeset for help on using the changeset viewer.