Changeset f0e6036 in nscp for include


Ignore:
Timestamp:
02/05/10 09:37:36 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
6b19198
Parents:
c0d7e82
Message:

Reintegrated stable branch and removed some project files (no longer needed) (part 1 of many)

Location:
include
Files:
11 added
4 edited

Legend:

Unmodified
Added
Removed
  • include/checkHelpers.hpp

    r7f9c823 rf0e6036  
    2525 
    2626#define MAKE_PERFDATA(alias, value, unit, warn, crit) _T("'") + alias + _T("'=") + value + unit + _T(";") + warn + _T(";") + crit + _T("; ") 
     27#define MAKE_PERFDATA_EX(alias, value, unit, warn, crit, xmin, xmax) _T("'") + alias + _T("'=") + value + unit + _T(";") + warn + _T(";") + crit + _T(";") + xmin + _T(";") + xmax + _T("; ") 
    2728 
    2829namespace checkHolders { 
     30 
    2931 
    3032 
     
    8890  } 
    8991 
     92 
    9093  typedef enum {showLong, showShort, showProblems, showUnknown} showType; 
    9194  template <class TContents> 
    9295  struct CheckContainer { 
    9396    typedef CheckContainer<TContents> TThisType; 
     97    typedef typename TContents::TValueType TPayloadValueType; 
    9498    TContents warn; 
    9599    TContents crit; 
     
    129133    } 
    130134    std::wstring gatherPerfData(typename TContents::TValueType &value) { 
    131       return crit.gatherPerfData(getAlias(), value, warn, crit); 
     135      if (crit.hasBounds()) 
     136        return crit.gatherPerfData(getAlias(), value, warn, crit); 
     137      else if (warn.hasBounds()) 
     138        return warn.gatherPerfData(getAlias(), value, warn, crit); 
     139      else 
     140        return getAlias() + _T(": ERROR"); 
    132141    } 
    133142    bool hasBounds() { 
     
    156165        message += tstr; 
    157166      //std::wcout << _T("result: ") << tstr << _T("--") << std::endl; 
     167    } 
     168  }; 
     169 
     170 
     171  template <class value_type> 
     172  struct check_proxy_interface { 
     173    virtual bool showAll() = 0; 
     174    virtual std::wstring gatherPerfData(value_type &value) = 0; 
     175    virtual bool hasBounds() = 0; 
     176    virtual void runCheck(value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) = 0; 
     177    virtual void set_warn_bound(std::wstring value) = 0; 
     178    virtual void set_crit_bound(std::wstring value) = 0; 
     179    //virtual std::wstring get_default_alias() = 0; 
     180 
     181  }; 
     182 
     183 
     184  //typedef enum {showLong, showShort, showProblems, showUnknown} showType; 
     185  template <class container_value_type, class impl_type> 
     186  class check_proxy_container : public check_proxy_interface<container_value_type> { 
     187    typedef check_proxy_container<container_value_type, impl_type> TThisType; 
     188    impl_type impl_; 
     189  public: 
     190    virtual typename impl_type::TPayloadValueType get_value(container_value_type &value) = 0; 
     191 
     192    void set_warn_bound(std::wstring value) { 
     193      impl_.warn = value; 
     194    } 
     195    void set_crit_bound(std::wstring value) { 
     196      impl_.crit = value; 
     197    } 
     198    void set_alias(std::wstring value) { 
     199      impl_.alias = value; 
     200    } 
     201 
     202 
     203    check_proxy_container() {} 
     204    /* 
     205    void setDefault(TThisType def) { 
     206      if (!warn.hasBounds()) 
     207        warn = def.warn; 
     208      if (!crit.hasBounds()) 
     209        crit = def.crit; 
     210      if (show == showUnknown) 
     211        show = def.show; 
     212    } 
     213    */ 
     214    bool showAll() { 
     215      return impl_.showAll(); 
     216    } 
     217    std::wstring gatherPerfData(container_value_type &value) { 
     218      typename impl_type::TPayloadValueType real_value = get_value(value); 
     219      return impl_.gatherPerfData(real_value); 
     220    } 
     221    bool hasBounds() { 
     222      return impl_.hasBounds(); 
     223    } 
     224    void runCheck(container_value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 
     225      typename impl_type::TPayloadValueType real_value = get_value(value); 
     226      return impl_.runCheck(real_value, returnCode, message, perf); 
     227    } 
     228  }; 
     229 
     230 
     231  template <class value_type> 
     232  struct check_multi_container { 
     233    typedef check_multi_container<value_type> TThisType; 
     234    typedef check_proxy_interface<value_type> check_type; 
     235    typedef std::list<check_type*> check_list_type; 
     236    check_list_type checks_; 
     237    std::wstring data; 
     238    std::wstring alias; 
     239 
     240    std::wstring cached_warn_; 
     241    std::wstring cached_crit_; 
     242 
     243    showType show; 
     244    bool perfData; 
     245 
     246    void set_warn_bound(std::wstring value) { 
     247//      if (checks_.empty()) 
     248        cached_warn_ = value; 
     249//      else 
     250//        (checks_.back())->set_warn_bound(value); 
     251    } 
     252    void set_crit_bound(std::wstring value) { 
     253//      if (checks_.empty()) 
     254        cached_crit_ = value; 
     255//      else 
     256//        (checks_.back())->set_crit_bound(value); 
     257    } 
     258 
     259    void add_check(check_type *check) { 
     260      if (check != NULL) { 
     261        if (!cached_warn_.empty()) 
     262          check->set_warn_bound(cached_warn_); 
     263        if (!cached_crit_.empty()) 
     264          check->set_crit_bound(cached_crit_); 
     265        checks_.push_back(check); 
     266      } 
     267      cached_warn_ = _T(""); 
     268      cached_crit_ = _T(""); 
     269    } 
     270 
     271    check_multi_container() : show(showUnknown), perfData(true) 
     272    {} 
     273  private: 
     274    check_multi_container(const TThisType &other)  
     275      : data(other.data), alias(other.alias), checks_(other.checks_), show(other.show)  
     276    {} 
     277  public: 
     278    ~check_multi_container() { 
     279      for (check_list_type::iterator it=checks_.begin(); it != checks_.end(); ++it) { 
     280        delete *it; 
     281      } 
     282      checks_.clear(); 
     283    } 
     284    std::wstring getAlias() { 
     285      if (alias.empty()) 
     286        return data; 
     287      return alias; 
     288    } 
     289    void setDefault(TThisType def) { 
     290      if (show == showUnknown) 
     291        show = def.show; 
     292    } 
     293    bool showAll() { 
     294      return show != showProblems; 
     295    } 
     296    std::wstring gatherPerfData(value_type &value) { 
     297      std::wstring ret; 
     298      for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 
     299        ret += (*cit)->gatherPerfData((*cit)->getAlias(), value); 
     300      } 
     301    } 
     302    bool hasBounds() { 
     303      for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 
     304        if ((*cit)->hasBounds()) 
     305          return true; 
     306      } 
     307      return false; 
     308    } 
     309    void runCheck(value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 
     310      for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 
     311        (*cit)->runCheck(value, returnCode, message, perf); 
     312      } 
     313      std::wcout << _T("result: ") << message << std::endl; 
    158314    } 
    159315  }; 
     
    539695    } 
    540696    std::wstring gatherPerfData(std::wstring alias, TType &value, typename TType::TValueType warn, typename TType::TValueType crit) { 
     697      unsigned int value_p, warn_p, crit_p; 
     698      TType::TValueType value_v, warn_v, crit_v; 
    541699      if (type_ == percentage_upper) { 
    542         return  
    543           MAKE_PERFDATA(alias, THandler::print_unformated(value.getUpperPercentage()), _T("%"),  
    544           THandler::print_unformated(warn), THandler::print_unformated(crit)); 
     700        value_p = value.getUpperPercentage(); 
     701        warn_p = warn; 
     702        crit_p = crit; 
     703        warn_v = static_cast<double>(value.total)*static_cast<double>(warn)/100.0; 
     704        crit_v = value.total*(double(crit)/100);; 
    545705      } else if (type_ == percentage_lower) { 
    546           return  
    547             MAKE_PERFDATA(alias, THandler::print_unformated(value.getLowerPercentage()), _T("%"),  
    548             THandler::print_unformated(warn), THandler::print_unformated(crit)); 
     706        value_p = value.getLowerPercentage(); 
     707        warn_p = warn; 
     708        crit_p = crit; 
     709        warn_v = static_cast<double>(value.total)*static_cast<double>(warn)/100.0; 
     710        crit_v = value.total*(double(crit)/100); 
     711      } else if (type_ == value_upper) { 
     712        value_p = value.getUpperPercentage(); 
     713        warn_p = 100-(warn*100/value.total); 
     714        crit_p = 100-(crit*100/value.total); 
     715        warn_v = warn; 
     716        crit_v = crit; 
    549717      } else if (type_ == value_upper) { 
    550718        std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value.value))); 
     
    553721          THandler::print_perf(value.total-warn, unit), THandler::print_perf(value.total-crit, unit)); 
    554722      } else { 
    555         std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value.value))); 
    556         return  
    557           MAKE_PERFDATA(alias, THandler::print_perf(value.value, unit), unit,  
    558           THandler::print_perf(warn, unit), THandler::print_perf(crit, unit)); 
    559       } 
     723        value_p = value.getLowerPercentage(); 
     724        warn_p = 100-(warn*100/value.total); 
     725        crit_p = 100-(crit*100/value.total); 
     726        warn_v = warn; 
     727        crit_v = crit; 
     728      } 
     729      std::wstring unit = THandler::get_perf_unit(min(warn_v, min(crit_v, value.value))); 
     730      return  
     731        MAKE_PERFDATA(alias + _T(" %"), THandler::print_unformated(value_p), _T("%"), THandler::print_unformated(warn_p), THandler::print_unformated(crit_p)) 
     732        +  
     733        MAKE_PERFDATA_EX(alias, THandler::print_perf(value.value, unit), unit, THandler::print_perf(warn_v, unit), THandler::print_perf(crit_v, unit),  
     734          THandler::print_perf(0, unit), THandler::print_perf(value.total, unit)) 
     735        ; 
    560736    } 
    561737  private: 
     
    8781054  }; 
    8791055  typedef ExactBounds<NumericBounds<unsigned long int, int_handler> > ExactBoundsULongInteger; 
     1056  typedef ExactBounds<NumericBounds<unsigned int, int_handler> > ExactBoundsUInteger; 
     1057  typedef ExactBounds<NumericBounds<unsigned long, int_handler> > ExactBoundsULong; 
     1058  typedef ExactBounds<NumericBounds<time_type, time_handler<__int64> > > ExactBoundsTime; 
    8801059 
    8811060  //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<int ,int>, int_handler> > MaxMinPercentageBoundsInteger; 
  • include/filter_framework.hpp

    r04f2743 rf0e6036  
    225225#endif 
    226226  typedef filter_one<std::wstring, std::wstring, handlers::string_handler, filter::exact_string_filter> exact_string_filter; 
     227  typedef filter_one<std::wstring, std::wstring, handlers::string_handler, filter::not_string_filter> not_string_filter; 
    227228 
    228229  struct filter_all_strings { 
    229230    sub_string_filter sub; 
    230231    exact_string_filter exact; 
     232    not_string_filter not; 
    231233    std::wstring value_; 
    232234#ifdef USE_BOOST 
     
    240242        || regexp.hasFilter()  
    241243#endif 
    242         || exact.hasFilter(); 
     244        || exact.hasFilter() 
     245        || not.hasFilter() 
     246        ; 
    243247    } 
    244248    bool matchFilter(const std::wstring str) const { 
     
    250254#endif 
    251255      else if ((exact.hasFilter())&&(exact.matchFilter(str))) 
     256        return true; 
     257      else if ((not.hasFilter())&&(not.matchFilter(str))) 
    252258        return true; 
    253259      return false; 
     
    270276      } else if (t.first.length() > 1 && t.first[0] == L'=') { 
    271277        exact = t.first.substr(1); 
     278      } else if (t.first.length() > 2 && t.first[0] == L'!' && t.first[1] == L'=') { 
     279        not = t.first.substr(2); 
     280      } else if (t.first.length() > 1 && t.first[0] == L'!') { 
     281        not = t.first.substr(1); 
    272282      } else { 
    273283        exact = t.first; 
     
    364374    } 
    365375  }; 
    366   typedef filter_all_numeric<unsigned long long, checkHolders::time_handler<unsigned long long> > filter_all_times; 
     376  typedef filter_all_numeric<__int64, checkHolders::time_handler<__int64> > filter_all_times; 
     377  typedef filter_all_numeric<unsigned long, checkHolders::int_handler > filter_all_num_ul; 
    367378 
    368379  template <typename TFilterType, typename TValueType> 
  • include/strEx.h

    rc0d7e82 rf0e6036  
    240240  inline std::wstring format_date(std::time_t time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
    241241    return format_date(boost::posix_time::from_time_t(time), format); 
    242     /* 
    243     wchar_t buf[51]; 
    244     struct tm nt; // = new struct tm; 
    245 #if (_MSC_VER > 1300)  // 1300 == VC++ 7.0 
    246     if (gmtime_s(&nt, &time) != 0) 
    247       return _T(""); 
    248 #else 
    249     struct tm nt; // = new struct tm; 
    250     nt = gmtime(&time); 
    251     if (nt == NULL) 
    252       return ""; 
    253 #endif 
    254     size_t l = wcsftime(buf, 50, format.c_str(), &nt); 
    255     if (l <= 0 || l >= 50) 
    256       return _T(""); 
    257     buf[l] = 0; 
    258     return buf; 
    259     */ 
    260242  } 
    261243  /* 
     
    286268    return format_date(static_cast<time_t>(filetime), format); 
    287269  } 
    288 */ 
     270 
     271    int len = wcslen(string); 
     272    for (int i=0;i<len;i++) { 
     273      if (string[i] == 10 || string[i] == 13) 
     274        string[i] = L' '; 
     275    } 
     276  } 
     277  */ 
    289278  static const unsigned long long SECS_BETWEEN_EPOCHS = 11644473600; 
    290279  static const unsigned long long SECS_TO_100NS = 10000000; 
    291  
     280   
    292281  inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
    293282    filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); 
     
    705694  */ 
    706695 
     696 
     697 
     698  class StrICmp 
     699  { 
     700  public: 
     701    StrICmp(const std::string &Lang = "english") : m_locE(Lang.c_str()) 
     702    { 
     703    } 
     704    class CharLessI 
     705    { 
     706    public: 
     707      CharLessI(std::locale &locE) : m_locE(locE) 
     708      { 
     709      } 
     710      template<typename T> 
     711      bool operator()(T c1, T c2) 
     712      { 
     713        return std::tolower(c1, m_locE) < std::tolower(c2, m_locE); 
     714      } 
     715    private: 
     716      std::locale &m_locE; 
     717    }; 
     718    template<typename T> 
     719    int operator()(const T &s1, const T &s2) 
     720    { 
     721      if (std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), CharLessI(m_locE))) 
     722        return -1; 
     723      if (std::lexicographical_compare(s2.begin(), s2.end(), s1.begin(), s1.end(), CharLessI(m_locE))) 
     724        return 1; 
     725      return 0; 
     726    } 
     727  private: 
     728    std::locale m_locE; 
     729  }; 
     730 
     731  template<typename T> 
     732  int StrCmpI(const T &s1, const T &s2, const std::string &Lang = "english") 
     733  { 
     734    return StrICmp(Lang)(s1, s2); 
     735  } 
     736 
     737 
    707738#ifdef _DEBUG 
    708739  inline void test_getToken(std::wstring in1, char in2, std::wstring out1, std::wstring out2) { 
  • include/utils.h

    rdcd5462 rf0e6036  
    6161      else if (p__.first == (_T("crit") postfix)) { obj.crit = p__.second; } \ 
    6262 
     63#define MAP_OPTIONS_EXACT_NUMERIC_ALL_MULTI(obj, postfix) \ 
     64      else if (p__.first == (_T("warn") postfix)) { obj.set_warn_bound(p__.second); } \ 
     65      else if (p__.first == (_T("crit") postfix)) { obj.set_crit_bound(p__.second); } \ 
     66 
    6367#define MAP_OPTIONS_PUSH_WTYPE(type, value, obj, list) \ 
    6468      else if (p__.first == value) { type o; o.obj = p__.second; list.push_back(o); } 
Note: See TracChangeset for help on using the changeset viewer.