Changeset 227
- Timestamp:
- 12/13/09 22:35:12 (2 years ago)
- Location:
- branches/stable
- Files:
-
- 8 edited
-
. (modified) (1 prop)
-
AutoBuild.h (modified) (1 diff)
-
changelog (modified) (1 diff)
-
include/checkHelpers.hpp (modified) (5 diffs)
-
include/file_helpers.hpp (modified) (1 diff)
-
include/utils.h (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.cpp (modified) (30 diffs)
-
modules/CheckDisk/CheckDisk.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
- Property svn:ignore
-
old new 14 14 NSClient++-2005.suo 15 15 *.bak 16 build.log
-
- Property svn:ignore
-
branches/stable/AutoBuild.h
r225 r227 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,7, 4966 #define PRODUCTVER 0,3,7, 4967 #define STRFILEVER _T("0.3.7. 496")8 #define STRPRODUCTVER _T("0.3.7. 496")9 #define STRPRODUCTDATE _T("2009-12- 06")5 #define FILEVER 0,3,7,512 6 #define PRODUCTVER 0,3,7,512 7 #define STRFILEVER _T("0.3.7.512") 8 #define STRPRODUCTVER _T("0.3.7.512") 9 #define STRPRODUCTDATE _T("2009-12-13") 10 10 #endif // AUTOBUILD_H -
branches/stable/changelog
r225 r227 6 6 * Fix depend onservice LanManWorkStation (old win) 7 7 * Fix RtlStringFromGUID problem on NT4 8 9 2009-12-13 MickeM 10 + Added new command: CheckSingleFile to check spects of a single file use like so: 11 CheckSingleFile file=d:\nrpe_512.pem warn=>100 check=line-count warn=>100 crit=>170 check=size 12 + Added option debug to CheckFile2 to enable priting of debug information 13 + Added ignore-errors to "ignore" any filesystem related errors (NOTICE this is probably not what you want) 14 + Added master-syntax to CheckFile2 to change the overall message like so: 15 It takes three options (and char data): 16 * %list% A list of all "files" (syntax controls this) 17 * %files% number of files 18 * %matches% number of files matched 19 CheckFile2 MinWarn=10 MinCrit=10 path=D:\WINDOWS\system32 filter+size=gt:0 truncate=10 ignore-errors "master-syntax=%matches%/%files%" 20 OK:7177/7...|'found files'=7177;10;10; 8 21 9 22 2009-12-06 MickeM -
branches/stable/include/checkHelpers.hpp
r173 r227 27 27 28 28 namespace checkHolders { 29 29 30 30 31 … … 88 89 } 89 90 91 90 92 typedef enum {showLong, showShort, showProblems, showUnknown} showType; 91 93 template <class TContents> 92 94 struct CheckContainer { 93 95 typedef CheckContainer<TContents> TThisType; 96 typedef typename TContents::TValueType TPayloadValueType; 94 97 TContents warn; 95 98 TContents crit; … … 129 132 } 130 133 std::wstring gatherPerfData(typename TContents::TValueType &value) { 131 return crit.gatherPerfData(getAlias(), value, warn, crit); 134 if (crit.hasBounds()) 135 return crit.gatherPerfData(getAlias(), value, warn, crit); 136 else if (warn.hasBounds()) 137 return warn.gatherPerfData(getAlias(), value, warn, crit); 138 else 139 return getAlias() + _T(": ERROR"); 132 140 } 133 141 bool hasBounds() { … … 156 164 message += tstr; 157 165 //std::wcout << _T("result: ") << tstr << _T("--") << std::endl; 166 } 167 }; 168 169 170 template <class value_type> 171 struct check_proxy_interface { 172 virtual bool showAll() = 0; 173 virtual std::wstring gatherPerfData(value_type &value) = 0; 174 virtual bool hasBounds() = 0; 175 virtual void runCheck(value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) = 0; 176 virtual void set_warn_bound(std::wstring value) = 0; 177 virtual void set_crit_bound(std::wstring value) = 0; 178 //virtual std::wstring get_default_alias() = 0; 179 180 }; 181 182 183 //typedef enum {showLong, showShort, showProblems, showUnknown} showType; 184 template <class container_value_type, class impl_type> 185 class check_proxy_container : public check_proxy_interface<container_value_type> { 186 typedef check_proxy_container<container_value_type, impl_type> TThisType; 187 impl_type impl_; 188 public: 189 virtual typename impl_type::TPayloadValueType get_value(container_value_type &value) = 0; 190 191 void set_warn_bound(std::wstring value) { 192 impl_.warn = value; 193 } 194 void set_crit_bound(std::wstring value) { 195 impl_.crit = value; 196 } 197 void set_alias(std::wstring value) { 198 impl_.alias = value; 199 } 200 201 202 check_proxy_container() {} 203 /* 204 void setDefault(TThisType def) { 205 if (!warn.hasBounds()) 206 warn = def.warn; 207 if (!crit.hasBounds()) 208 crit = def.crit; 209 if (show == showUnknown) 210 show = def.show; 211 } 212 */ 213 bool showAll() { 214 return impl_.showAll(); 215 } 216 std::wstring gatherPerfData(container_value_type &value) { 217 typename impl_type::TPayloadValueType real_value = get_value(value); 218 return impl_.gatherPerfData(real_value); 219 } 220 bool hasBounds() { 221 return impl_.hasBounds(); 222 } 223 void runCheck(container_value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 224 typename impl_type::TPayloadValueType real_value = get_value(value); 225 return impl_.runCheck(real_value, returnCode, message, perf); 226 } 227 }; 228 229 230 template <class value_type> 231 struct check_multi_container { 232 typedef check_multi_container<value_type> TThisType; 233 typedef check_proxy_interface<value_type> check_type; 234 typedef std::list<check_type*> check_list_type; 235 check_list_type checks_; 236 std::wstring data; 237 std::wstring alias; 238 239 std::wstring cached_warn_; 240 std::wstring cached_crit_; 241 242 showType show; 243 bool perfData; 244 245 void set_warn_bound(std::wstring value) { 246 // if (checks_.empty()) 247 cached_warn_ = value; 248 // else 249 // (checks_.back())->set_warn_bound(value); 250 } 251 void set_crit_bound(std::wstring value) { 252 // if (checks_.empty()) 253 cached_crit_ = value; 254 // else 255 // (checks_.back())->set_crit_bound(value); 256 } 257 258 void add_check(check_type *check) { 259 if (check != NULL) { 260 if (!cached_warn_.empty()) 261 check->set_warn_bound(cached_warn_); 262 if (!cached_crit_.empty()) 263 check->set_crit_bound(cached_crit_); 264 checks_.push_back(check); 265 } 266 cached_warn_ = _T(""); 267 cached_crit_ = _T(""); 268 } 269 270 check_multi_container() : show(showUnknown), perfData(true) 271 {} 272 private: 273 check_multi_container(const TThisType &other) 274 : data(other.data), alias(other.alias), checks_(other.checks_), show(other.show) 275 {} 276 public: 277 ~check_multi_container() { 278 for (check_list_type::iterator it=checks_.begin(); it != checks_.end(); ++it) { 279 delete *it; 280 } 281 checks_.clear(); 282 } 283 std::wstring getAlias() { 284 if (alias.empty()) 285 return data; 286 return alias; 287 } 288 void setDefault(TThisType def) { 289 if (show == showUnknown) 290 show = def.show; 291 } 292 bool showAll() { 293 return show != showProblems; 294 } 295 std::wstring gatherPerfData(value_type &value) { 296 std::wstring ret; 297 for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 298 ret += (*cit)->gatherPerfData((*cit)->getAlias(), value); 299 } 300 } 301 bool hasBounds() { 302 for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 303 if ((*cit)->hasBounds()) 304 return true; 305 } 306 return false; 307 } 308 void runCheck(value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 309 for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 310 (*cit)->runCheck(value, returnCode, message, perf); 311 } 312 std::wcout << _T("result: ") << message << std::endl; 158 313 } 159 314 }; … … 878 1033 }; 879 1034 typedef ExactBounds<NumericBounds<unsigned long int, int_handler> > ExactBoundsULongInteger; 1035 typedef ExactBounds<NumericBounds<unsigned int, int_handler> > ExactBoundsUInteger; 1036 typedef ExactBounds<NumericBounds<unsigned long, int_handler> > ExactBoundsULong; 1037 typedef ExactBounds<NumericBounds<time_type, time_handler<__int64> > > ExactBoundsTime; 880 1038 881 1039 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<int ,int>, int_handler> > MaxMinPercentageBoundsInteger; -
branches/stable/include/file_helpers.hpp
r179 r227 30 30 } 31 31 }; 32 class meta { 33 public: 34 static std::wstring get_path(std::wstring file) { 35 std::wstring::size_type pos = file.find_last_of('\\'); 36 if (pos == std::wstring::npos) { 37 return file; 38 } 39 return file.substr(0, pos); 40 } 41 static std::wstring get_filename(std::wstring file) { 42 std::wstring::size_type pos = file.find_last_of('\\'); 43 if (pos == std::wstring::npos || ++pos == std::wstring::npos) { 44 return _T(""); 45 } 46 return file.substr(pos); 47 } 48 }; 32 49 33 50 class patterns { -
branches/stable/include/utils.h
r175 r227 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); } -
branches/stable/modules/CheckDisk/CheckDisk.cpp
r225 r227 26 26 #include <error.hpp> 27 27 #include <file_helpers.hpp> 28 #include <checkHelpers.hpp> 28 29 29 30 CheckDisk gCheckDisk; … … 108 109 109 110 template <class finder_function> 110 void recursive_scan(std::wstring dir, std::wstring pattern, int current_level, int max_level, finder_function & f, error_reporter * errors ) {111 void recursive_scan(std::wstring dir, std::wstring pattern, int current_level, int max_level, finder_function & f, error_reporter * errors, bool debug) { 111 112 if ((max_level != -1) && (current_level > max_level)) 112 113 return; … … 114 115 115 116 DWORD fileAttr = GetFileAttributes(dir.c_str()); 116 NSC_DEBUG_MSG_STD(_T("Input is: ") + dir + _T(" / ") + strEx::ihextos(fileAttr));117 if (debug) NSC_DEBUG_MSG_STD(_T("Input is: ") + dir + _T(" / ") + strEx::ihextos(fileAttr)); 117 118 118 119 if (!is_directory(fileAttr)) { 119 NSC_DEBUG_MSG_STD(_T("Found a file dont do recursive scan: ") + dir);120 if (debug) NSC_DEBUG_MSG_STD(_T("Found a file dont do recursive scan: ") + dir); 120 121 // It is a file check it an return (dont check recursivly) 121 122 pattern_type single_path = split_path_ex(dir); 122 NSC_DEBUG_MSG_STD(_T("Path is: ") + single_path.first);123 if (debug) NSC_DEBUG_MSG_STD(_T("Path is: ") + single_path.first); 123 124 HANDLE hFind = FindFirstFile(dir.c_str(), &wfd); 124 125 if (hFind != INVALID_HANDLE_VALUE) { … … 129 130 } 130 131 std::wstring file_pattern = dir + _T("\\") + pattern; 131 NSC_DEBUG_MSG_STD(_T("File pattern: ") + file_pattern);132 if (debug) NSC_DEBUG_MSG_STD(_T("File pattern: ") + file_pattern); 132 133 HANDLE hFind = FindFirstFile(file_pattern.c_str(), &wfd); 133 134 if (hFind != INVALID_HANDLE_VALUE) { … … 139 140 } 140 141 std::wstring dir_pattern = dir + _T("\\*.*"); 141 NSC_DEBUG_MSG_STD(_T("File pattern: ") + dir_pattern);142 if (debug) NSC_DEBUG_MSG_STD(_T("File pattern: ") + dir_pattern); 142 143 hFind = FindFirstFile(dir_pattern.c_str(), &wfd); 143 144 if (hFind != INVALID_HANDLE_VALUE) { … … 145 146 if (is_directory(wfd.dwFileAttributes)) { 146 147 if ( (wcscmp(wfd.cFileName, _T(".")) != 0) && (wcscmp(wfd.cFileName, _T("..")) != 0) ) 147 recursive_scan<finder_function>(dir + _T("\\") + wfd.cFileName, pattern, current_level+1, max_level, f, errors );148 recursive_scan<finder_function>(dir + _T("\\") + wfd.cFileName, pattern, current_level+1, max_level, f, errors, debug); 148 149 } 149 150 } while (FindNextFile(hFind, &wfd)); … … 355 356 std::list<std::wstring> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 356 357 bool bPerfData = true; 358 bool debug = false; 357 359 if (args.empty()) { 358 360 message = _T("Missing argument(s)."); … … 369 371 MAP_OPTIONS_STR(_T("MaxCrit"), tmpObject.crit.max) 370 372 MAP_OPTIONS_STR(_T("MinCrit"), tmpObject.crit.min) 373 MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) 371 374 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 372 375 MAP_OPTIONS_SECONDARY_BEGIN(_T(":"), p2) … … 388 391 NSC_error errors; 389 392 pattern_type splitpath = split_pattern(path.data); 390 recursive_scan<get_size>(splitpath.first, splitpath.second, -1, -1, sizeFinder, &errors );393 recursive_scan<get_size>(splitpath.first, splitpath.second, -1, -1, sizeFinder, &errors, debug); 391 394 if (sizeFinder.hasError()) { 392 395 message = _T("File not found check log for details"); … … 410 413 file_info() 411 414 : ullCreationTime(0) 415 , ullLastAccessTime(0) 416 , ullLastWriteTime(0) 417 , ullSize(0) 412 418 , cached_version(false, _T("")) 413 419 , cached_count(false, 0) … … 417 423 , filename(filename_) 418 424 , ullCreationTime(0) 425 , ullLastAccessTime(0) 426 , ullLastWriteTime(0) 427 , ullSize(0) 419 428 , cached_version(false, _T("")) 420 429 , cached_count(false, 0) … … 424 433 ullLastAccessTime = ((info.ftLastAccessTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastAccessTime.dwLowDateTime); 425 434 ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime); 435 }; 436 file_info(std::wstring path_, std::wstring filename_) 437 : path(path_) 438 , filename(filename_) 439 , ullCreationTime(0) 440 , ullLastAccessTime(0) 441 , ullLastWriteTime(0) 442 , ullSize(0) 443 , cached_version(false, _T("")) 444 , cached_count(false, 0) 445 { 426 446 }; 427 447 … … 489 509 do { 490 510 c = fgetc (pFile); 491 if (c == '\n') count++; 511 if (c == '\r') { 512 c = fgetc (pFile); 513 count++; 514 } else if (c == '\n') { 515 c = fgetc (pFile); 516 count++; 517 } 492 518 } while (c != EOF); 493 519 fclose (pFile); … … 662 688 unsigned long long now; 663 689 unsigned int hit_count; 664 665 file_filter_function_ex() : hit_count(0), error(false), debug_(false), bFilterIn(true), bFilterAll(true) {} 690 unsigned int file_count; 691 std::wstring last_error; 692 unsigned int error_count; 693 694 file_filter_function_ex() : hit_count(0), file_count(0), error(false), debug_(false), bFilterIn(true), bFilterAll(true), error_count(0) {} 666 695 result_type operator()(argument_type ffd) { 667 696 if (is_directory(ffd.wfd.dwFileAttributes)) … … 687 716 if ((mode == filter_minus)&&(bTmpMatched)) { 688 717 // a -<filter> hit so thrash item and bail out! 689 //if (debug_)718 if (debug_) 690 719 NSC_DEBUG_MSG_STD(_T("Matched: - ") + (*cit3).second.getValue() + _T(" for: ") + info.render(syntax)); 691 720 bMatch = false; … … 693 722 } else if ((mode == filter_plus)&&(!bTmpMatched)) { 694 723 // a +<filter> missed hit so thrash item and bail out! 695 //if (debug_)724 if (debug_) 696 725 NSC_DEBUG_MSG_STD(_T("Matched (missed): + ") + (*cit3).second.getValue() + _T(" for: ") + info.render(syntax)); 697 726 bMatch = false; … … 704 733 } 705 734 706 NSC_DEBUG_MSG_STD(_T("result: ") + strEx::itos(bFilterIn) + _T(" -- ") + strEx::itos(bMatch));735 //NSC_DEBUG_MSG_STD(_T("result: ") + strEx::itos(bFilterIn) + _T(" -- ") + strEx::itos(bMatch)); 707 736 if ((bFilterIn&&bMatch)||(!bFilterIn&&!bMatch)) { 708 737 strEx::append_list(message, info.render(syntax)); … … 715 744 hit_count++; 716 745 } 746 file_count++; 717 747 return true; 718 748 } … … 723 753 if (errors != NULL) 724 754 errors->report_error(msg); 755 last_error = msg; 756 error_count++; 725 757 error = true; 726 758 } 759 760 std::wstring render(std::wstring syntax) { 761 strEx::replace(syntax, _T("%list%"), message); 762 strEx::replace(syntax, _T("%matches%"), strEx::itos(hit_count)); 763 strEx::replace(syntax, _T("%files%"), strEx::itos(file_count)); 764 return syntax; 765 } 766 727 767 }; 728 768 … … 738 778 std::wstring format = _T("%Y years %m mon %d days %H hours %M min %S sec"); 739 779 std::wstring path; 780 bool debug = false; 740 781 find_first_file_info finder; 741 782 MAP_OPTIONS_BEGIN(stl_args) 742 783 MAP_OPTIONS_STR(_T("path"), path) 743 784 MAP_OPTIONS_STR(_T("date"), format) 785 MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) 744 786 MAP_OPTIONS_FALLBACK(format) 745 787 MAP_OPTIONS_END() … … 752 794 NSC_error errors; 753 795 pattern_type splitpath = split_pattern(path); 754 recursive_scan<find_first_file_info>(splitpath.first, splitpath.second, -1, -1, finder, &errors );796 recursive_scan<find_first_file_info>(splitpath.first, splitpath.second, -1, -1, finder, &errors, debug); 755 797 if (finder.hasError()) { 756 798 message = _T("File not found (check log for details)"); … … 783 825 bool bPerfData = true; 784 826 unsigned int max_dir_depth = -1; 827 bool debug = false; 785 828 786 829 try { … … 794 837 MAP_OPTIONS_STR2INT(_T("max-dir-depth"), max_dir_depth) 795 838 MAP_OPTIONS_PUSH(_T("file"), paths) 839 MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) 796 840 MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterIn, _T("in"), _T("out")) 797 841 MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterAll, _T("all"), _T("any")) … … 816 860 for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 817 861 pattern_type path = split_pattern(*pit); 818 recursive_scan<file_filter_function>(path.first, path.second, 0, max_dir_depth, finder, &errors );862 recursive_scan<file_filter_function>(path.first, path.second, 0, max_dir_depth, finder, &errors, debug); 819 863 if (finder.hasError()) { 820 864 message = _T("File not found: ") + (*pit) + _T(" check log for details."); … … 863 907 CheckFileContainer query; 864 908 std::wstring syntax = _T("%filename%"); 909 std::wstring masterSyntax = _T("%list%"); 865 910 std::wstring alias; 866 911 std::wstring pattern = _T("*.*"); 867 912 bool bPerfData = true; 868 913 int max_dir_depth = -1; 914 bool debug = false; 915 bool ignoreError = false; 869 916 870 917 try { … … 874 921 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 875 922 MAP_OPTIONS_STR(_T("syntax"), syntax) 923 MAP_OPTIONS_STR(_T("master-syntax"), masterSyntax) 876 924 MAP_OPTIONS_PUSH(_T("path"), paths) 877 925 MAP_OPTIONS_STR(_T("pattern"), pattern) 878 926 MAP_OPTIONS_STR(_T("alias"), alias) 879 927 MAP_OPTIONS_PUSH(_T("file"), paths) 928 MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) 929 MAP_OPTIONS_BOOL_TRUE(_T("ignore-errors"), ignoreError) 880 930 MAP_OPTIONS_STR2INT(_T("max-dir-depth"), max_dir_depth) 881 931 MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterIn, _T("in"), _T("out")) … … 918 968 FILETIME now; 919 969 GetSystemTimeAsFileTime(&now); 970 finder.debug_ = debug; 920 971 finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 921 972 finder.syntax = syntax; 922 973 NSC_error errors; 923 974 for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 924 recursive_scan<file_filter_function_ex>(*pit, pattern, 0, max_dir_depth, finder, &errors );925 if ( finder.hasError()) {926 message = _T("Error when scanning: ") + (*pit) + _T(" check log for details .");975 recursive_scan<file_filter_function_ex>(*pit, pattern, 0, max_dir_depth, finder, &errors, debug); 976 if (!ignoreError && finder.hasError()) { 977 message = _T("Error when scanning: ") + (*pit) + _T(" check log for details (") + strEx::itos(finder.error_count) + _T(": ") + finder.last_error + _T(")"); 927 978 return NSCAPI::returnUNKNOWN; 928 979 } 929 980 } 930 message = finder.message;981 message = finder.render(masterSyntax); 931 982 if (!alias.empty()) 932 983 query.alias = alias; … … 936 987 if ((truncate > 0) && (message.length() > (truncate-4))) { 937 988 message = message.substr(0, truncate-4) + _T("..."); 938 perf = _T("");989 //perf = _T(""); 939 990 } 940 991 if (message.empty()) … … 942 993 return returnCode; 943 994 } 944 995 struct file_container : public file_info { 996 std::wstring error_; 997 998 999 file_container(const BY_HANDLE_FILE_INFORMATION info, std::wstring file) : file_info(info, file_helpers::meta::get_path(file), file_helpers::meta::get_filename(file)) {} 1000 file_container(std::wstring file, std::wstring error) : error_(error), file_info(file_helpers::meta::get_path(file), file_helpers::meta::get_filename(file)) {} 1001 1002 bool has_errors() { 1003 return !error_.empty(); 1004 } 1005 std::wstring get_error() { 1006 return error_; 1007 } 1008 1009 }; 1010 1011 typedef checkHolders::ExactBounds<checkHolders::NumericBounds<checkHolders::disk_size_type, checkHolders::disk_size_handler<checkHolders::disk_size_type> > > ExactBoundsDiscSize; 1012 1013 1014 typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULong> ExactULongContainer; 1015 typedef checkHolders::CheckContainer<ExactBoundsDiscSize> DiscSizeContainer; 1016 typedef checkHolders::CheckContainer<checkHolders::ExactBoundsTime> DateTimeContainer; 1017 1018 struct check_file_size : public checkHolders::check_proxy_container<file_container, DiscSizeContainer> { 1019 check_file_size() { set_alias(_T("size")); } 1020 checkHolders::disk_size_type get_value(file_container &value) { 1021 return value.ullSize; 1022 } 1023 }; 1024 struct check_file_line_count : public checkHolders::check_proxy_container<file_container, ExactULongContainer> { 1025 check_file_line_count() { set_alias(_T("line-count")); } 1026 unsigned long get_value(file_container &value) { 1027 return value.get_line_count(); 1028 } 1029 }; 1030 struct check_file_dates : public checkHolders::check_proxy_container<file_container, DateTimeContainer> { 1031 enum type_type { 1032 date_access, date_creation, date_written 1033 } ; 1034 type_type type_; 1035 check_file_dates(type_type type) : type_(type) 1036 { 1037 if (type_ == date_creation) 1038 set_alias(_T("creation")); 1039 else if (type_ == date_access) 1040 set_alias(_T("access")); 1041 else if (type_ == date_written) 1042 set_alias(_T("written")); 1043 else 1044 set_alias(_T("unknown date type")); 1045 } 1046 unsigned long long get_value(file_container &value) { 1047 if (type_ == date_creation) 1048 return value.ullCreationTime; 1049 if (type_ == date_access) 1050 return value.ullLastAccessTime; 1051 if (type_ == date_written) 1052 return value.ullLastWriteTime; 1053 return -1; 1054 } 1055 }; 1056 1057 typedef checkHolders::check_multi_container<file_container> check_file_multi; 1058 struct check_file_factories { 1059 static checkHolders::check_proxy_interface<file_container>* size() { 1060 return new check_file_size(); 1061 } 1062 static checkHolders::check_proxy_interface<file_container>* line_count() { 1063 return new check_file_line_count(); 1064 } 1065 static checkHolders::check_proxy_interface<file_container>* access() { 1066 return new check_file_dates(check_file_dates::date_access); 1067 } 1068 static checkHolders::check_proxy_interface<file_container>* creation() { 1069 return new check_file_dates(check_file_dates::date_creation); 1070 } 1071 static checkHolders::check_proxy_interface<file_container>* written() { 1072 return new check_file_dates(check_file_dates::date_written); 1073 } 1074 }; 1075 1076 file_container get_file_info(std::wstring file, unsigned long long now) { 1077 1078 BY_HANDLE_FILE_INFORMATION _info; 1079 1080 HANDLE hFile = CreateFile(file.c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 1081 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 1082 if (hFile == INVALID_HANDLE_VALUE) { 1083 return file_container(file, _T("Could not open file: ") + file); 1084 } 1085 GetFileInformationByHandle(hFile, &_info); 1086 CloseHandle(hFile); 1087 file_container info(_info, file); 1088 info.ullNow = now; 1089 return info; 1090 } 1091 1092 #define MAP_FACTORY_PB(value, obj) \ 1093 else if ((p__.first == _T("check")) && (p__.second == ##value)) { checker.add_check(check_file_factories::obj()); } 1094 1095 1096 NSCAPI::nagiosReturn CheckDisk::CheckSingleFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 1097 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 1098 std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 1099 check_file_multi checker; 1100 typedef std::pair<int,file_filter> filteritem_type; 1101 typedef std::list<filteritem_type > filterlist_type; 1102 if (stl_args.empty()) { 1103 message = _T("Missing argument(s)."); 1104 return NSCAPI::returnUNKNOWN; 1105 } 1106 std::list<std::wstring> files; 1107 unsigned int truncate = 0; 1108 std::wstring syntax = _T("%filename%"); 1109 std::wstring alias; 1110 bool bPerfData = true; 1111 1112 try { 1113 MAP_OPTIONS_BEGIN(stl_args) 1114 //MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 1115 MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 1116 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 1117 MAP_OPTIONS_STR(_T("syntax"), syntax) 1118 MAP_OPTIONS_STR(_T("alias"), alias) 1119 MAP_OPTIONS_PUSH(_T("file"), files) 1120 MAP_OPTIONS_EXACT_NUMERIC_ALL_MULTI(checker, _T("")) 1121 MAP_FACTORY_PB(_T("size"), size) 1122 MAP_FACTORY_PB(_T("line-count"), line_count) 1123 MAP_FACTORY_PB(_T("creation"), creation) 1124 MAP_FACTORY_PB(_T("access"), access) 1125 MAP_FACTORY_PB(_T("written"), written) 1126 /* 1127 MAP_FILTER(_T("creation"), creation) 1128 MAP_FILTER(_T("written"), written) 1129 MAP_FILTER(_T("accessed"), accessed) 1130 MAP_FILTER(_T("version"), version) 1131 MAP_FILTER(_T("line-count"), line_count) 1132 */ 1133 MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) 1134 MAP_OPTIONS_END() 1135 } catch (filters::parse_exception e) { 1136 message = e.getMessage(); 1137 return NSCAPI::returnUNKNOWN; 1138 } catch (filters::filter_exception e) { 1139 message = e.getMessage(); 1140 return NSCAPI::returnUNKNOWN; 1141 } 1142 FILETIME now; 1143 GetSystemTimeAsFileTime(&now); 1144 unsigned __int64 nowi64 = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 1145 //finder.syntax = syntax; 1146 for (std::list<std::wstring>::const_iterator pit = files.begin(); pit != files.end(); ++pit) { 1147 file_container info = get_file_info(*pit, nowi64); 1148 checker.alias = info.render(syntax); 1149 checker.runCheck(info, returnCode, message, perf); 1150 } 1151 if ((truncate > 0) && (message.length() > (truncate-4))) { 1152 message = message.substr(0, truncate-4) + _T("..."); 1153 perf = _T(""); 1154 } 1155 if (message.empty()) 1156 message = _T("CheckSingleFile ok"); 1157 return returnCode; 1158 } 945 1159 NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) { 946 1160 if (command == _T("CheckFileSize")) { … … 952 1166 } else if (command == _T("CheckFile2")) { 953 1167 return CheckFile2(argLen, char_args, msg, perf); 1168 } else if (command == _T("CheckSingleFile")) { 1169 return CheckSingleFile(argLen, char_args, msg, perf); 954 1170 } else if (command == _T("getFileAge")) { 955 1171 return getFileAge(argLen, char_args, msg, perf); -
branches/stable/modules/CheckDisk/CheckDisk.h
r165 r227 57 57 NSCAPI::nagiosReturn CheckFile2(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 58 58 NSCAPI::nagiosReturn getFileAge(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 59 NSCAPI::nagiosReturn CheckSingleFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 59 60 60 61 private:
Note: See TracChangeset
for help on using the changeset viewer.







