Changeset 246
- Timestamp:
- 02/05/10 09:37:36 (2 years ago)
- Location:
- trunk/include
- Files:
-
- 4 edited
- 12 copied
-
checkHelpers.hpp (modified) (7 diffs)
-
filter_framework.hpp (modified) (5 diffs)
-
pdh (copied) (copied from branches/stable/include/pdh)
-
pdh.hpp (copied) (copied from branches/stable/include/pdh.hpp)
-
pdh/basic_impl.cpp (copied) (copied from branches/stable/include/pdh/basic_impl.cpp)
-
pdh/basic_impl.hpp (copied) (copied from branches/stable/include/pdh/basic_impl.hpp)
-
pdh/collectors.hpp (copied) (copied from branches/stable/include/pdh/collectors.hpp)
-
pdh/core.cpp (copied) (copied from branches/stable/include/pdh/core.cpp)
-
pdh/core.hpp (copied) (copied from branches/stable/include/pdh/core.hpp)
-
pdh/counters.hpp (copied) (copied from branches/stable/include/pdh/counters.hpp)
-
pdh/enumerations.hpp (copied) (copied from branches/stable/include/pdh/enumerations.hpp)
-
pdh/query.hpp (copied) (copied from branches/stable/include/pdh/query.hpp)
-
pdh/resolver.hpp (copied) (copied from branches/stable/include/pdh/resolver.hpp)
-
pdh/thread_safe_impl.hpp (copied) (copied from branches/stable/include/pdh/thread_safe_impl.hpp)
-
strEx.h (modified) (3 diffs)
-
utils.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/checkHelpers.hpp
r207 r246 25 25 26 26 #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("; ") 27 28 28 29 namespace checkHolders { 30 29 31 30 32 … … 88 90 } 89 91 92 90 93 typedef enum {showLong, showShort, showProblems, showUnknown} showType; 91 94 template <class TContents> 92 95 struct CheckContainer { 93 96 typedef CheckContainer<TContents> TThisType; 97 typedef typename TContents::TValueType TPayloadValueType; 94 98 TContents warn; 95 99 TContents crit; … … 129 133 } 130 134 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"); 132 141 } 133 142 bool hasBounds() { … … 156 165 message += tstr; 157 166 //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; 158 314 } 159 315 }; … … 539 695 } 540 696 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; 541 699 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);; 545 705 } 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; 549 717 } else if (type_ == value_upper) { 550 718 std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value.value))); … … 553 721 THandler::print_perf(value.total-warn, unit), THandler::print_perf(value.total-crit, unit)); 554 722 } 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 ; 560 736 } 561 737 private: … … 878 1054 }; 879 1055 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; 880 1059 881 1060 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<int ,int>, int_handler> > MaxMinPercentageBoundsInteger; -
trunk/include/filter_framework.hpp
r201 r246 225 225 #endif 226 226 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; 227 228 228 229 struct filter_all_strings { 229 230 sub_string_filter sub; 230 231 exact_string_filter exact; 232 not_string_filter not; 231 233 std::wstring value_; 232 234 #ifdef USE_BOOST … … 240 242 || regexp.hasFilter() 241 243 #endif 242 || exact.hasFilter(); 244 || exact.hasFilter() 245 || not.hasFilter() 246 ; 243 247 } 244 248 bool matchFilter(const std::wstring str) const { … … 250 254 #endif 251 255 else if ((exact.hasFilter())&&(exact.matchFilter(str))) 256 return true; 257 else if ((not.hasFilter())&&(not.matchFilter(str))) 252 258 return true; 253 259 return false; … … 270 276 } else if (t.first.length() > 1 && t.first[0] == L'=') { 271 277 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); 272 282 } else { 273 283 exact = t.first; … … 364 374 } 365 375 }; 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; 367 378 368 379 template <typename TFilterType, typename TValueType> -
trunk/include/strEx.h
r245 r246 240 240 inline std::wstring format_date(std::time_t time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 241 241 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.0246 if (gmtime_s(&nt, &time) != 0)247 return _T("");248 #else249 struct tm nt; // = new struct tm;250 nt = gmtime(&time);251 if (nt == NULL)252 return "";253 #endif254 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 */260 242 } 261 243 /* … … 286 268 return format_date(static_cast<time_t>(filetime), format); 287 269 } 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 */ 289 278 static const unsigned long long SECS_BETWEEN_EPOCHS = 11644473600; 290 279 static const unsigned long long SECS_TO_100NS = 10000000; 291 280 292 281 inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 293 282 filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); … … 705 694 */ 706 695 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 707 738 #ifdef _DEBUG 708 739 inline void test_getToken(std::wstring in1, char in2, std::wstring out1, std::wstring out2) { -
trunk/include/utils.h
r201 r246 61 61 else if (p__.first == (_T("crit") postfix)) { obj.crit = p__.second; } \ 62 62 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 63 67 #define MAP_OPTIONS_PUSH_WTYPE(type, value, obj, list) \ 64 68 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.







