Changeset 273
- Timestamp:
- 06/13/10 22:02:07 (3 months ago)
- Author:
- mickem
- Message:
-
Merged back all (some?) of the new changes from 0.3.8
- Location:
- trunk
- Files:
-
- 6 removed
- 20 modified
- 22 copied
Legend:
- Unmodified
- Added
- Removed
-
- Property svn:mergeinfo changed
-
|
r66
|
r273
|
|
| 3 | 3 | // change the FALSE to TRUE for autoincrement of build number |
| 4 | 4 | #define INCREMENT_VERSION TRUE |
| 5 | | #define FILEVER 1,0,0,13 |
| 6 | | #define PRODUCTVER 1,0,0,13 |
| 7 | | #define STRFILEVER "1.0.0.13" |
| 8 | | #define STRPRODUCTVER "1.0.0.13" |
| 9 | | #define STRPRODUCTDATE "2007-11-03" |
| | 5 | #define FILEVER 1,0,0,14 |
| | 6 | #define PRODUCTVER 1,0,0,14 |
| | 7 | #define STRFILEVER _T("1.0.0.14") |
| | 8 | #define STRPRODUCTVER _T("1.0.0.14") |
| | 9 | #define STRPRODUCTDATE _T("2010-02-27") |
| 10 | 10 | #endif // AUTOBUILD_H |
-
|
r246
|
r273
|
|
| 309 | 309 | void runCheck(value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { |
| 310 | 310 | for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { |
| | 311 | (*cit)->set_showall(show); |
| 311 | 312 | (*cit)->runCheck(value, returnCode, message, perf); |
| 312 | 313 | } |
| … |
… |
|
| 329 | 330 | } |
| 330 | 331 | static TType parse(std::wstring s) { |
| 331 | | return strEx::stoi64_as_BKMG(s); |
| | 332 | TType val = strEx::stoi64_as_BKMG(s); |
| | 333 | if (val == 0 && s.length() > 1 && s[0] != L'0') |
| | 334 | NSC_LOG_MESSAGE_STD(_T("Maybe this is not what you want: ") + s + _T(" = ") + strEx::itos(val)); |
| | 335 | return val; |
| 332 | 336 | } |
| 333 | 337 | static TType parse_percent(std::wstring s) { |
| … |
… |
|
| 364 | 368 | public: |
| 365 | 369 | static TType parse(std::wstring s) { |
| 366 | | return strEx::stoi64_as_time(s); |
| | 370 | TType val = strEx::stoi64_as_time(s); |
| | 371 | if (val == 0 && s.length() > 1 && s[0] != L'0') |
| | 372 | NSC_LOG_MESSAGE_STD(_T("Maybe this is not what you want: ") + s + _T(" = 0")); |
| | 373 | return val; |
| 367 | 374 | } |
| 368 | 375 | static TType parse_percent(std::wstring s) { |
| … |
… |
|
| 397 | 404 | public: |
| 398 | 405 | static int parse(std::wstring s) { |
| 399 | | return strEx::stoi(s); |
| | 406 | int val = strEx::stoi(s); |
| | 407 | if (val == 0 && s.length() > 1 && s[0] != L'0') |
| | 408 | NSC_LOG_MESSAGE_STD(_T("Maybe this is not what you want: ") + s + _T(" = 0")); |
| | 409 | return val; |
| 400 | 410 | } |
| 401 | 411 | static int parse_percent(std::wstring s) { |
| … |
… |
|
| 427 | 437 | public: |
| 428 | 438 | static __int64 parse(std::wstring s) { |
| 429 | | return strEx::stoi64(s); |
| | 439 | __int64 val = strEx::stoi64(s); |
| | 440 | if (val == 0 && s.length() > 1 && s[0] != L'0') |
| | 441 | NSC_LOG_MESSAGE_STD(_T("Maybe this is not what you want: ") + s + _T(" = 0")); |
| | 442 | return val; |
| 430 | 443 | } |
| 431 | 444 | static __int64 parse_percent(std::wstring s) { |
| … |
… |
|
| 716 | 729 | crit_v = crit; |
| 717 | 730 | } else if (type_ == value_upper) { |
| 718 | | std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value.value))); |
| 719 | | return |
| 720 | 731 | MAKE_PERFDATA(alias, THandler::print_perf((value.value), unit), unit, |
| 721 | 732 | THandler::print_perf(value.total-warn, unit), THandler::print_perf(value.total-crit, unit)); |
| … |
… |
|
| 865 | 876 | }; |
| 866 | 877 | |
| | 878 | template <class TFilterType> |
| | 879 | class FilterBounds { |
| | 880 | public: |
| | 881 | TFilterType filter; |
| | 882 | typedef typename TFilterType::TValueType TValueType; |
| | 883 | typedef FilterBounds<TFilterType> TMyType; |
| | 884 | |
| | 885 | FilterBounds() {} |
| | 886 | FilterBounds(const FilterBounds &other) { |
| | 887 | filter = other.filter; |
| | 888 | } |
| | 889 | bool hasBounds() { |
| | 890 | return filter.hasFilter(); |
| | 891 | } |
| | 892 | |
| | 893 | static std::wstring toStringLong(typename TValueType &value) { |
| | 894 | //return filter.to_string() + _T(" matches ") + value; |
| | 895 | // TODO FIx this; |
| | 896 | return value; |
| | 897 | //return TNumericHolder::toStringLong(value.count) + _T(", ") + TStateHolder::toStringLong(value.state); |
| | 898 | } |
| | 899 | static std::wstring toStringShort(typename TValueType &value) { |
| | 900 | // TODO FIx this; |
| | 901 | return value; |
| | 902 | //return TNumericHolder::toStringShort(value.count); |
| | 903 | } |
| | 904 | std::wstring gatherPerfData(std::wstring alias, typename TValueType &value, TMyType &warn, TMyType &crit) { |
| | 905 | return _T(""); |
| | 906 | } |
| | 907 | bool check(typename TValueType &value, std::wstring lable, std::wstring &message, ResultType type) { |
| | 908 | if (filter.hasFilter()) { |
| | 909 | if (!filter.matchFilter(value)) |
| | 910 | return false; |
| | 911 | message = lable + _T(": ") + filter.to_string() + _T(" matches ") + value; |
| | 912 | return true; |
| | 913 | } else { |
| | 914 | NSC_LOG_MESSAGE_STD(_T("Missing bounds for filter check: ") + lable); |
| | 915 | } |
| | 916 | return false; |
| | 917 | } |
| | 918 | const TMyType & operator=(std::wstring value) { |
| | 919 | filter = value; |
| | 920 | return *this; |
| | 921 | } |
| | 922 | |
| | 923 | }; |
| | 924 | |
| | 925 | |
| 867 | 926 | template <class TStateHolder = StateBounds<state_type, state_handler> > |
| 868 | 927 | class SimpleStateBounds { |
| … |
… |
|
| 932 | 991 | return min.gatherPerfData(alias, value, warn.min.getPerfBound(value), crit.min.getPerfBound(value)); |
| 933 | 992 | } else { |
| 934 | | NSC_DEBUG_MSG_STD(_T("Missing bounds for maxmin-bounds check: ") + alias); |
| | 993 | NSC_LOG_MESSAGE_STD(_T("Missing bounds for maxmin-bounds check: ") + alias); |
| 935 | 994 | return min.gatherPerfData(alias, value, 0, 0); |
| 936 | 995 | } |
-
|
r254
|
r273
|
|
| 68 | 68 | struct numeric_max_filter { |
| 69 | 69 | static bool filter(TType filter, TType value) { |
| | 70 | //std::wcout << filter << _T(" >= ") << value << std::endl; |
| 70 | 71 | return value >= filter; |
| 71 | 72 | } |
| … |
… |
|
| 113 | 114 | static std::wstring parse(std::wstring str) { |
| 114 | 115 | return str; |
| | 116 | } |
| | 117 | static std::wstring print(std::wstring value) { |
| | 118 | return value; |
| 115 | 119 | } |
| 116 | 120 | }; |
| … |
… |
|
| 194 | 198 | template <typename TFilterType, typename TValueType, class THandler, class TFilter> |
| 195 | 199 | struct filter_one { |
| 196 | | TFilterType filter; |
| | 200 | TFilterType filter_; |
| 197 | 201 | bool hasFilter_; |
| 198 | 202 | std::wstring value_; |
| 199 | 203 | filter_one() : hasFilter_(false) {} |
| 200 | | filter_one(const filter_one &other) : hasFilter_(other.hasFilter_), filter(other.filter), value_(other.value_) { |
| | 204 | filter_one(const filter_one &other) : hasFilter_(other.hasFilter_), filter_(other.filter_), value_(other.value_) { |
| 201 | 205 | } |
| 202 | 206 | |
| … |
… |
|
| 205 | 209 | } |
| 206 | 210 | bool matchFilter(const TValueType value) const { |
| 207 | | return TFilter::filter(filter, value); |
| | 211 | return TFilter::filter(filter_, value); |
| 208 | 212 | } |
| 209 | 213 | const filter_one & operator=(std::wstring value) { |
| … |
… |
|
| 211 | 215 | hasFilter_ = false; |
| 212 | 216 | try { |
| 213 | | filter = THandler::parse(value); |
| | 217 | filter_ = THandler::parse(value); |
| 214 | 218 | hasFilter_ = true; |
| 215 | 219 | } catch (handlers::handler_exception e) { |
| … |
… |
|
| 237 | 241 | not_string_filter not; |
| 238 | 242 | std::wstring value_; |
| | 243 | typedef std::wstring TValueType; |
| 239 | 244 | #ifdef USE_BOOST |
| 240 | 245 | regexp_string_filter regexp; |
| … |
… |
|
| 366 | 371 | return *this; |
| 367 | 372 | } |
| 368 | | #define NSCP_FF_DEBUG_NUM(key) if (key.hasFilter()) return _T( # key ) + key.value_; |
| | 373 | #define NSCP_FF_DEBUG_NUM(key) if (key.hasFilter()) strEx::append_list(str, std::wstring(_T( # key )) + _T(" ") + key.getValue(), _T(",")); |
| 369 | 374 | std::wstring to_string() const { |
| | 375 | std::wstring str; |
| 370 | 376 | NSCP_FF_DEBUG_NUM(max); |
| 371 | 377 | NSCP_FF_DEBUG_NUM(min); |
| 372 | 378 | NSCP_FF_DEBUG_NUM(eq); |
| 373 | 379 | NSCP_FF_DEBUG_NUM(neq); |
| 374 | | //NSCP_FF_DEBUG_NUM(inList); |
| 375 | | return _T(" MISSING! "); |
| | 380 | NSCP_FF_DEBUG_NUM(inList); |
| | 381 | return str; |
| 376 | 382 | } |
| 377 | 383 | std::wstring getValue() const { |
| … |
… |
|
| 381 | 387 | typedef filter_all_numeric<__int64, checkHolders::time_handler<__int64> > filter_all_times; |
| 382 | 388 | typedef filter_all_numeric<unsigned long, checkHolders::int_handler > filter_all_num_ul; |
| | 389 | typedef filter_all_numeric<long long, checkHolders::int_handler > filter_all_num_ll; |
| 383 | 390 | |
| 384 | 391 | template <typename TFilterType, typename TValueType> |
-
|
r257
|
r273
|
|
| 79 | 79 | #define EXTSCRIPT_SCRIPT_SECTION "/settings/external scripts/scripts" |
| 80 | 80 | #define EXTSCRIPT_ALIAS_SECTION "/settings/external scripts/alias" |
| | 81 | #define EXTSCRIPT_WRAPPINGS_SECTION "/settings/external scripts/wrappings" |
| | 82 | #define EXTSCRIPT_WRAPPED_SCRIPT "/settings/external scripts/wrapped scripts" |
| 81 | 83 | #define CHECK_SYSTEM_SECTION "/settings/system" |
| 82 | 84 | #define CHECK_SYSTEM_COUNTERS_SECTION "/settings/system/PDH counters" |
| … |
… |
|
| 250 | 252 | DESCRIBE_SETTING(ALIAS_SECTION, "EXTERNAL SCRIPT ALIAS SECTION", "Works like the \"inject\" concept of NRPE scripts module. But in short a list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)"); |
| 251 | 253 | |
| | 254 | DEFINE_PATH(WRAPPINGS_SECTION, EXTSCRIPT_WRAPPINGS_SECTION); |
| | 255 | DESCRIBE_SETTING(WRAPPINGS_SECTION, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); |
| | 256 | |
| | 257 | DEFINE_PATH(WRAPPED_SCRIPT, EXTSCRIPT_WRAPPED_SCRIPT); |
| | 258 | DESCRIBE_SETTING(WRAPPED_SCRIPT, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); |
| | 259 | |
| 252 | 260 | } |
| 253 | 261 | |
-
|
r271
|
r273
|
|
| 271 | 271 | return buf; |
| 272 | 272 | } |
| | 273 | #define MK_FORMAT_FTD(min, key, val) \ |
| | 274 | if (mtm->tm_year > min) \ |
| | 275 | strEx::replace(format, key, strEx::itos(val)); \ |
| | 276 | else \ |
| | 277 | strEx::replace(format, key, _T("0")); |
| | 278 | |
| | 279 | |
| 273 | 280 | |
| 274 | 281 | static const __int64 SECS_BETWEEN_EPOCHS = 11644473600; |
| 275 | 282 | static const __int64 SECS_TO_100NS = 10000000; |
| 276 | 283 | inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { |
| | 284 | if (filetime == 0) |
| | 285 | return _T("ZERO"); |
| 277 | 286 | filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); |
| 278 | 287 | filetime /= SECS_TO_100NS; |
| … |
… |
|
| 326 | 335 | } |
| 327 | 336 | inline std::wstring itos(unsigned long long i) { |
| | 337 | std::wstringstream ss; |
| | 338 | ss << i; |
| | 339 | return ss.str(); |
| | 340 | } |
| | 341 | inline std::wstring itos(long long i) { |
| 328 | 342 | std::wstringstream ss; |
| 329 | 343 | ss << i; |
| … |
… |
|
| 440 | 454 | } |
| 441 | 455 | |
| 442 | | #define MK_FORMAT_FTD(min, key, val) \ |
| 443 | | if (mtm->tm_year > min) \ |
| 444 | | strEx::replace(format, key, strEx::itos(val)); \ |
| 445 | | else \ |
| 446 | | strEx::replace(format, key, _T("0")); |
| 447 | | |
| 448 | | inline std::wstring format_time_delta(struct tm *mtm, std::wstring format = _T("%Y years %m months %d days %H hours %M minutes")) { |
| 449 | | // "Date: %Y-%m-%d %H:%M:%S" |
| 450 | | MK_FORMAT_FTD(70, _T("%Y"), mtm->tm_year); |
| 451 | | MK_FORMAT_FTD(0, _T("%m"), mtm->tm_mon); |
| 452 | | MK_FORMAT_FTD(0, _T("%d"), mtm->tm_mday-1); |
| 453 | | MK_FORMAT_FTD(0, _T("%H"), mtm->tm_hour); |
| 454 | | MK_FORMAT_FTD(0, _T("%M"), mtm->tm_min); |
| 455 | | MK_FORMAT_FTD(0, _T("%S"), mtm->tm_sec); |
| 456 | | return format; |
| 457 | | } |
| 458 | 456 | |
| 459 | 457 | #define WEEK (7 * 24 * 60 * 60 * 1000) |
| … |
… |
|
| 752 | 750 | } |
| 753 | 751 | |
| | 752 | #define MK_FORMAT_FTD(min, key, val) \ |
| | 753 | if (mtm->tm_year > min) \ |
| | 754 | strEx::replace(format, key, strEx::itos(val)); \ |
| | 755 | else \ |
| | 756 | strEx::replace(format, key, _T("0")); |
| | 757 | |
| | 758 | inline std::wstring format_time_delta(struct tm *mtm, std::wstring format = _T("%Y years %m months %d days %H hours %M minutes")) { |
| | 759 | // "Date: %Y-%m-%d %H:%M:%S" |
| | 760 | MK_FORMAT_FTD(70, _T("%Y"), mtm->tm_year); |
| | 761 | MK_FORMAT_FTD(0, _T("%m"), mtm->tm_mon); |
| | 762 | MK_FORMAT_FTD(0, _T("%d"), mtm->tm_mday-1); |
| | 763 | MK_FORMAT_FTD(0, _T("%H"), mtm->tm_hour); |
| | 764 | MK_FORMAT_FTD(0, _T("%M"), mtm->tm_min); |
| | 765 | MK_FORMAT_FTD(0, _T("%S"), mtm->tm_sec); |
| | 766 | return format; |
| | 767 | } |
| | 768 | inline std::wstring format_time_delta(time_t time, std::wstring format = _T("%Y years %m months %d days %H hours %M minutes")) { |
| | 769 | struct tm nt; // = new struct tm; |
| | 770 | #if (_MSC_VER > 1300) // 1300 == VC++ 7.0 |
| | 771 | if (gmtime_s(&nt, &time) != 0) |
| | 772 | return _T(""); |
| | 773 | #else |
| | 774 | nt = gmtime(&time); |
| | 775 | if (nt == NULL) |
| | 776 | return ""; |
| | 777 | #endif |
| | 778 | return format_time_delta(&nt, format); |
| | 779 | } |
| | 780 | inline std::wstring format_filetime_delta(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { |
| | 781 | if (filetime == 0) |
| | 782 | return _T("ZERO"); |
| | 783 | //filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); |
| | 784 | filetime /= SECS_TO_100NS; |
| | 785 | return format_time_delta(static_cast<time_t>(filetime), format); |
| | 786 | } |
| 754 | 787 | |
| 755 | 788 | #ifdef _DEBUG |
-
|
r250
|
r273
|
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | | CheckDisk::CheckDisk() { |
| | 38 | CheckDisk::CheckDisk() : show_errors_(false) { |
| 39 | 39 | } |
| 40 | 40 | CheckDisk::~CheckDisk() { |
| … |
… |
|
| 51 | 51 | NSCModuleHelper::registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); |
| 52 | 52 | NSCModuleHelper::registerCommand(_T("CheckFile"), _T("Check various aspects of a file and/or folder.")); |
| | 53 | |
| | 54 | show_errors_ = NSCModuleHelper::getSettingsInt(CHECK_DISK_SECTION_TITLE, CHECK_DISK_SHOW_ERRORS, CHECK_DISK_SHOW_ERRORS_DEFAULT)==1; |
| 53 | 55 | } catch (NSCModuleHelper::NSCMHExcpetion &e) { |
| 54 | 56 | NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); |
| … |
… |
|
| 73 | 75 | virtual void report_error(std::wstring error) = 0; |
| 74 | 76 | virtual void report_warning(std::wstring error) = 0; |
| | 77 | virtual bool has_error() = 0; |
| | 78 | virtual std::wstring get_error() = 0; |
| 75 | 79 | }; |
| 76 | 80 | |
| … |
… |
|
| 87 | 91 | struct get_size : public baseFinderFunction |
| 88 | 92 | { |
| 89 | | bool error; |
| 90 | | get_size() : size(0), error(false) { } |
| | 93 | get_size() : size(0) { } |
| 91 | 94 | result_type operator()(argument_type ffd) { |
| 92 | 95 | if (!file_helpers::checks::is_directory(ffd.wfd.dwFileAttributes)) { |
| … |
… |
|
| 98 | 101 | return size; |
| 99 | 102 | } |
| 100 | | inline const bool hasError() const { |
| 101 | | return error; |
| 102 | | } |
| 103 | 103 | inline void setError(error_reporter *errors, std::wstring msg) { |
| 104 | 104 | if (errors != NULL) |
| 105 | 105 | errors->report_error(msg); |
| 106 | | error = true; |
| 107 | 106 | } |
| 108 | 107 | private: |
| … |
… |
|
| 354 | 353 | return _T("unknown: ") + strEx::itos(drvType); |
| 355 | 354 | } |
| 356 | | |
| 357 | | class NSC_error : public error_reporter { |
| 358 | | void report_error(std::wstring error) { |
| 359 | | NSC_LOG_ERROR(error); |
| 360 | | } |
| 361 | | void report_warning(std::wstring error) { |
| 362 | | NSC_LOG_MESSAGE(error); |
| 363 | | } |
| 364 | | }; |
| 365 | | typedef std::pair<std::wstring,std::wstring> pattern_type; |
| 366 | | pattern_type split_path_ex(std::wstring path) { |
| 367 | | std::wstring baseDir; |
| 368 | | if (file_helpers::checks::is_directory(path)) { |
| 369 | | return pattern_type(path, _T("")); |
| 370 | | } |
| 371 | | std::wstring::size_type pos = path.find_last_of('\\'); |
| 372 | | if (pos == std::wstring::npos) { |
| 373 | | pattern_type(path, _T("*.*")); |
| 374 | | } |
| 375 | | NSC_DEBUG_MSG_STD(_T("Looking for: path: ") + path.substr(0, pos) + _T(", pattern: ") + path.substr(pos+1)); |
| 376 | | return pattern_type(path.substr(0, pos), path.substr(pos+1)); |
| 377 | | } |
| 378 | | |
| 379 | | typedef std::pair<std::wstring,std::wstring> pattern_type; |
| 380 | | pattern_type split_pattern(std::wstring path) { |
| 381 | | std::wstring baseDir; |
| 382 | | if (file_helpers::checks::exists(path)) { |
| 383 | | return pattern_type(path, _T("")); |
| 384 | | } |
| 385 | | std::wstring::size_type pos = path.find_last_of('\\'); |
| 386 | | if (pos == std::wstring::npos) { |
| 387 | | pattern_type(path, _T("*.*")); |
| 388 | | } |
| 389 | | NSC_DEBUG_MSG_STD(_T("Looking for: pattern: ") + path.substr(0, pos) + _T(", pattern: ") + path.substr(pos+1)); |
| 390 | | return pattern_type(path.substr(0, pos), path.substr(pos+1)); |
| 391 | | } |
| | 355 | 4 |
| 392 | 356 | |
| 393 | 357 | |
| … |
… |
|
| 453 | 417 | |
| 454 | 418 | std::wstring error; |
| | 419 | //bool has_error; |
| | 420 | |
| | 421 | static file_info get(__int64 now, std::wstring path, std::wstring file) { |
| | 422 | return get_2(now, path, file); |
| | 423 | } |
| | 424 | static file_info get(__int64 now, file_finder_data data) { |
| | 425 | return file_info(now, data.wfd, data.path, data.wfd.cFileName); |
| | 426 | } |
| | 427 | |
| | 428 | static file_info get_2(__int64 now, std::wstring path, std::wstring file) { |
| | 429 | WIN32_FILE_ATTRIBUTE_DATA data; |
| | 430 | if (!GetFileAttributesEx((path + _T("\\") + file).c_str(), GetFileExInfoStandard, reinterpret_cast<LPVOID>(&data))) { |
| | 431 | file_info ret; |
| | 432 | ret.error = _T("Could not open file (2) ") + path + _T("\\") + file + _T(": ") + error::lookup::last_error(); |
| | 433 | return ret; |
| | 434 | } |
| | 435 | return file_info(now, data, path, file); |
| | 436 | } |
| | 437 | static file_info get_1(__int64 now, std::wstring path, std::wstring file) { |
| | 438 | HANDLE hFile = CreateFile((path + _T("\\") + file).c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); |
| | 439 | if (hFile == INVALID_HANDLE_VALUE) { |
| | 440 | file_info ret; |
| | 441 | ret.error = _T("Could not open file (1) ") + path + _T("\\") + file + _T(": ") + error::lookup::last_error(); |
| | 442 | return ret; |
| | 443 | } |
| | 444 | BY_HANDLE_FILE_INFORMATION _info; |
| | 445 | GetFileInformationByHandle(hFile, &_info); |
| | 446 | CloseHandle(hFile); |
| | 447 | return file_info(now, _info, path, file); |
| | 448 | } |
| | 449 | |
| | 450 | file_info() |
| | 451 | : ullCreationTime(0) |
| | 452 | , ullLastAccessTime(0) |
| | 453 | , ullLastWriteTime(0) |
| | 454 | , ullSize(0) |
| | 455 | , ullNow(0) |
| | 456 | , cached_version(false, _T("")) |
| | 457 | , cached_count(false, 0) |
| | 458 | {} |
| | 459 | file_info(__int64 now, const WIN32_FILE_ATTRIBUTE_DATA info, std::wstring path_, std::wstring filename_) |
| | 460 | : path(path_) |
| | 461 | , filename(filename_) |
| | 462 | , ullCreationTime(0) |
| | 463 | , ullLastAccessTime(0) |
| | 464 | , ullLastWriteTime(0) |
| | 465 | , ullSize(0) |
| | 466 | , ullNow(now) |
| | 467 | , cached_version(false, _T("")) |
| | 468 | , cached_count(false, 0) |
| | 469 | { |
| | 470 | ullSize = ((info.nFileSizeHigh * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.nFileSizeLow); |
| | 471 | ullCreationTime = ((info.ftCreationTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftCreationTime.dwLowDateTime); |
| | 472 | ullLastAccessTime = ((info.ftLastAccessTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastAccessTime.dwLowDateTime); |
| | 473 | ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime); |
| | 474 | }; |
| | 475 | file_info(__int64 now, const BY_HANDLE_FILE_INFORMATION info, std::wstring path_, std::wstring filename_) |
| | 476 | : path(path_) |
| | 477 | , filename(filename_) |
| | 478 | , ullCreationTime(0) |
| | 479 | , ullLastAccessTime(0) |
| | 480 | , ullLastWriteTime(0) |
| | 481 | , ullSize(0) |
| | 482 | , ullNow(now) |
| | 483 | , cached_version(false, _T("")) |
| | 484 | , cached_count(false, 0) |
| | 485 | { |
| | 486 | ullSize = ((info.nFileSizeHigh * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.nFileSizeLow); |
| | 487 | ullCreationTime = ((info.ftCreationTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftCreationTime.dwLowDateTime); |
| | 488 | ullLastAccessTime = ((info.ftLastAccessTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastAccessTime.dwLowDateTime); |
| | 489 | ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime); |
| | 490 | }; |
| | 491 | file_info(__int64 now, const WIN32_FIND_DATA info, std::wstring path_, std::wstring filename_) |
| | 492 | : path(path_) |
| | 493 | , filename(filename_) |
| | 494 | , ullCreationTime(0) |
| | 495 | , ullLastAccessTime(0) |
| | 496 | , ullLastWriteTime(0) |
| | 497 | , ullSize(0) |
| | 498 | , ullNow(now) |
| | 499 | , cached_version(false, _T("")) |
| | 500 | , cached_count(false, 0) |
| | 501 | { |
| 455 | 502 | bool has_error; |
| 456 | 503 | |
| … |
… |
|
| 537 | 584 | ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime); |
| 538 | 585 | }; |
| | 586 | file_info(__int64 now, std::wstring path_, std::wstring filename_) |
| | 587 | : path(path_) |
| | 588 | , filename(filename_) |
| | 589 | , ullCreationTime(0) |
| | 590 | , ullLastAccessTime(0) |
| | 591 | , ullLastWriteTime(0) |
| | 592 | , ullSize(0) |
| | 593 | , ullNow(now) |
| | 594 | , cached_version(false, _T("")) |
| | 595 | , cached_count(false, 0) |
| | 596 | { |
| | 597 | }; |
| 539 | 598 | file_info(std::wstring path_, std::wstring filename_) |
| 540 | 599 | : path(path_) |
| … |
… |
|
| 576 | 635 | strEx::replace(syntax, _T("%access%"), strEx::format_filetime(ullLastAccessTime, DATE_FORMAT)); |
| 577 | 636 | strEx::replace(syntax, _T("%write%"), strEx::format_filetime(ullLastWriteTime, DATE_FORMAT)); |
| | 637 | strEx::replace(syntax, _T("%creation-raw%"), strEx::itos(ullCreationTime)); |
| | 638 | strEx::replace(syntax, _T("%access-raw%"), strEx::itos(ullLastAccessTime)); |
| | 639 | strEx::replace(syntax, _T("%write-raw%"), strEx::itos(ullLastWriteTime)); |
| | 640 | strEx::replace(syntax, _T("%now-raw%"), strEx::itos(ullNow)); |
| 578 | 641 | /* |
| 579 | 642 | strEx::replace(syntax, _T("%creation-d%"), strEx::format_filetime(ullCreationTime, DATE_FORMAT)); |
| … |
… |
|
| 643 | 706 | }; |
| 644 | 707 | |
| | 708 | struct file_container : public file_info { |
| | 709 | std::wstring error_; |
| | 710 | |
| | 711 | |
| | 712 | static file_container get(std::wstring file) { |
| | 713 | FILETIME now; |
| | 714 | GetSystemTimeAsFileTime(&now); |
| | 715 | unsigned __int64 nowi64 = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); |
| | 716 | return get(file, nowi64); |
| | 717 | } |
| | 718 | |
| | 719 | static file_container get(std::wstring file, unsigned long long now) { |
| | 720 | |
| | 721 | BY_HANDLE_FILE_INFORMATION _info; |
| | 722 | |
| | 723 | HANDLE hFile = CreateFile(file.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, |
| | 724 | 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); |
| | 725 | if (hFile == INVALID_HANDLE_VALUE) { |
| | 726 | return file_container(now, file, _T("Could not open file: ") + file); |
| | 727 | } |
| | 728 | GetFileInformationByHandle(hFile, &_info); |
| | 729 | CloseHandle(hFile); |
| | 730 | file_container info(now, _info, file); |
| | 731 | //info.ullNow = now; |
| | 732 | return info; |
| | 733 | } |
| | 734 | |
| | 735 | |
| | 736 | file_container(__int64 now, const BY_HANDLE_FILE_INFORMATION info, std::wstring file) : file_info(now, info, file_helpers::meta::get_path(file), file_helpers::meta::get_filename(file)) {} |
| | 737 | file_container(__int64 now, std::wstring file, std::wstring error) : error_(error), file_info(now, file_helpers::meta::get_path(file), file_helpers::meta::get_filename(file)) {} |
| | 738 | |
| | 739 | bool has_errors() { |
| | 740 | return !error_.empty(); |
| | 741 | } |
| | 742 | std::wstring get_error() { |
| | 743 | return error_; |
| | 744 | } |
| | 745 | |
| | 746 | }; |
| 645 | 747 | struct file_filter { |
| 646 | 748 | filters::filter_all_numeric<unsigned long long, checkHolders::disk_size_handler<checkHolders::disk_size_type> > size; |
| … |
… |
|
| 693 | 795 | { |
| 694 | 796 | file_info info; |
| 695 | | bool error; |
| | 797 | __int64 now_; |
| 696 | 798 | // std::wstring message; |
| 697 | | find_first_file_info() : error(false) {} |
| | 799 | find_first_file_info() : now_(0) { |
| | 800 | FILETIME now; |
| | 801 | GetSystemTimeAsFileTime(&now); |
| | 802 | now_ = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); |
| | 803 | } |
| 698 | 804 | result_type operator()(argument_type ffd) { |
| 699 | 805 | if (file_helpers::checks::is_directory(ffd.wfd.dwFileAttributes)) |
| 700 | 806 | return true; |
| 701 | 807 | |
| | 808 | file_info info = file_info::get(now_, ffd); |
| 702 | 809 | file_info info = file_info::get(ffd); |
| 703 | 810 | if (!info.error.empty()) { |
| … |
… |
|
| 721 | 828 | */ |
| 722 | 829 | } |
| 723 | | inline const bool hasError() const { |
| 724 | | return error; |
| 725 | | } |
| 726 | 830 | inline void setError(error_reporter *errors, std::wstring msg) { |
| 727 | 831 | if (errors != NULL) |
| 728 | 832 | errors->report_error(msg); |
| 729 | | error = true; |
| 730 | 833 | } |
| 731 | 834 | }; |
| … |
… |
|
| 736 | 839 | bool bFilterAll; |
| 737 | 840 | bool bFilterIn; |
| 738 | | bool error; |
| 739 | 841 | std::wstring message; |
| 740 | 842 | std::wstring syntax; |
| … |
… |
|
| 742 | 844 | unsigned long long now; |
| 743 | 845 | unsigned int hit_count; |
| 744 | | |
| 745 | | file_filter_function() : hit_count(0), error(false), bFilterIn(true), bFilterAll(true) {} |
| | 846 | __int64 now_; |
| | 847 | |
| | 848 | file_filter_function() : now_(0), hit_count(0), bFilterIn(true), bFilterAll(true) { |
| | 849 | FILETIME now; |
| | 850 | GetSystemTimeAsFileTime(&now); |
| | 851 | now_ = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); |
| | 852 | } |
| 746 | 853 | result_type operator()(argument_type ffd) { |
| 747 | 854 | if (file_helpers::checks::is_directory(ffd.wfd.dwFileAttributes)) |
| … |
… |
|
| 793 | 900 | return true; |
| 794 | 901 | } |
| 795 | | inline const bool hasError() const { |
| 796 | | return error; |
| 797 | 902 | } |
| 798 | 903 | inline void setError(error_reporter *errors, std::wstring msg) { |
| … |
… |
|
| 898 | 1003 | last_error = msg; |
| 899 | 1004 | error_count++; |
| 900 | | error = true; |
| 901 | 1005 | } |
| 902 | 1006 | |
| … |
… |
|
| 926 | 1030 | std::wstring path; |
| 927 | 1031 | bool debug = false; |
| 928 | | find_first_file_info finder; |
| 929 | 1032 | MAP_OPTIONS_BEGIN(stl_args) |
| 930 | 1033 | MAP_OPTIONS_STR(_T("path"), path) |
| … |
… |
|
| 991 | 1094 | MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-written"), written, finder.filter_chain) |
| 992 | 1095 | MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-accessed"), accessed, finder.filter_chain) |
| | 1096 | MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) |
| | 1097 | MAP_OPTIONS_END() |
| | 1098 | } catch (filters::parse_exception e) { |
| | 1099 | message = e.getMessage(); |
| | 1100 | return NSCAPI::returnUNKNOWN; |
| | 1101 | } catch (filters::filter_exception e) { |
| | 1102 | message = e.getMessage(); |
| | 1103 | return NSCAPI::returnUNKNOWN; |
| | 1104 | } |
| | 1105 | finder.syntax = syntax; |
| | 1106 | NSC_error errors; |
| | 1107 | for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { |
| | 1108 | pattern_type path = split_pattern(*pit); |
| | 1109 | recursive_scan<file_filter_function>(path.first, path.second, 0, max_dir_depth, finder, &errors, debug); |
| | 1110 | if (errors.has_error()) { |
| | 1111 | if (show_errors_) |
| | 1112 | message = errors.get_error(); |
| | 1113 | else |
| | 1114 | message = _T("Check contains error. Check log for details (or enable show_errors in nsc.ini)"); |
| | 1115 | return NSCAPI::returnUNKNOWN; |
| | 1116 | } |
| | 1117 | } |
| | 1118 | message = finder.message; |
| | 1119 | if (!alias.empty()) |
| | 1120 | query.alias = alias; |
| | 1121 | else |
| | 1122 | query.alias = finder.alias; |
| | 1123 | if (query.alias.empty()) |
| | 1124 | query.alias = _T("no files found"); |
| | 1125 | query.runCheck(finder.hit_count, returnCode, message, perf); |
| | 1126 | if ((truncate > 0) && (message.length() > (truncate-4))) |
| | 1127 | message = message.substr(0, truncate-4) + _T("..."); |
| | 1128 | if (message.empty()) |
| | 1129 | message = _T("CheckFile ok"); |
| | 1130 | return returnCode; |
| | 1131 | } |
| | 1132 | |
| | 1133 | #define MAP_FILTER(value, obj) \ |
| | 1134 | else if (p__.first == _T("filter+"##value)) { file_filter filter; filter.obj = p__.second; \ |
| | 1135 | finder.filter_chain.push_back(filteritem_type(file_filter_function_ex::filter_plus, filter)); } \ |
| | 1136 | else if (p__.first == _T("filter-"##value)) { file_filter filter; filter.obj = p__.second; \ |
| | 1137 | finder.filter_chain.push_back(filteritem_type(file_filter_function_ex::filter_minus, filter)); } \ |
| | 1138 | else if (p__.first == _T("filter."##value)) { file_filter filter; filter.obj = p__.second; \ |
| | 1139 | finder.filter_chain.push_back(filteritem_type(file_filter_function_ex::filter_normal, filter)); } |
| | 1140 | |
| | 1141 | NSCAPI::nagiosReturn CheckDisk::CheckFile2(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { |
| | 1142 | NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; |
| | 1143 | std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); |
| | 1144 | typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer; |
| | 1145 | typedef std::pair<int,file_filter> filteritem_type; |
| | 1146 | typedef std::list<filteritem_type > filterlist_type; |
| | 1147 | if (stl_args.empty()) { |
| | 1148 | message = _T("Missing argument(s)."); |
| | 1149 | return NSCAPI::returnUNKNOWN; |
| | 1150 | } |
| | 1151 | file_filter_function_ex finder; |
| | 1152 | PathContainer tmpObject; |
| | 1153 | std::list<std::wstring> paths; |
| | 1154 | unsigned int truncate = 0; |
| | 1155 | CheckFileContainer query; |
| | 1156 | std::wstring syntax = _T("%filename%"); |
| | 1157 | std::wstring masterSyntax = _T("%list%"); |
| | 1158 | std::wstring alias; |
| | 1159 | std::wstring pattern = _T("*.*"); |
| | 1160 | bool bPerfData = true; |
| | 1161 | int max_dir_depth = -1; |
| | 1162 | bool debug = false; |
| | 1163 | bool ignoreError = false; |
| | 1164 | |
| | 1165 | try { |
| | 1166 | MAP_OPTIONS_BEGIN(stl_args) |
| | 1167 | MAP_OPTIONS_NUMERIC_ALL(query, _T("")) |
| | 1168 | MAP_OPTIONS_STR2INT(_T("truncate"), truncate) |
| | 1169 | MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) |
| | 1170 | MAP_OPTIONS_STR(_T("syntax"), syntax) |
| | 1171 | MAP_OPTIONS_STR(_T("master-syntax"), masterSyntax) |
| | 1172 | MAP_OPTIONS_PUSH(_T("path"), paths) |
| | 1173 | MAP_OPTIONS_STR(_T("pattern"), pattern) |
| | 1174 | MAP_OPTIONS_STR(_T("alias"), alias) |
| | 1175 | MAP_OPTIONS_PUSH(_T("file"), paths) |
| | 1176 | MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) |
| | 1177 | MAP_OPTIONS_BOOL_TRUE(_T("ignore-errors"), ignoreError) |
| | 1178 | MAP_OPTIONS_STR2INT(_T("max-dir-depth"), max_dir_depth) |
| | 1179 | MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterIn, _T("in"), _T("out")) |
| | 1180 | MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterAll, _T("all"), _T("any")) |
| | 1181 | /* |
| 993 | 1182 | MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) |
| 994 | 1183 | MAP_OPTIONS_END() |
-
|
r250
|
r273
|
|
| 27 | 27 | class CheckDisk { |
| 28 | 28 | private: |
| | 29 | bool show_errors_; |
| 29 | 30 | |
| 30 | 31 | public: |
-
|
r250
|
r273
|
|
| 23 | 23 | #include "CheckEventLog.h" |
| 24 | 24 | #include <filter_framework.hpp> |
| | 25 | #include <boost/foreach.hpp> |
| 25 | 26 | |
| 26 | 27 | #include <strEx.h> |
| … |
… |
|
| 29 | 30 | #include <error.hpp> |
| 30 | 31 | #include <map> |
| | 32 | <<<<<<< .working |
| 31 | 33 | #include <vector> |
| 32 | 34 | #include <config.h> |
| | 35 | ======= |
| | 36 | #include <vector> |
| | 37 | >>>>>>> .merge-right.r272 |
| | 38 | |
| | 39 | #include <boost/bind.hpp> |
| | 40 | #include <boost/assign.hpp> |
| | 41 | |
| | 42 | #include <parsers/where.hpp> |
| | 43 | #include <simple_timer.hpp> |
| | 44 | |
| | 45 | #include "simple_registry.hpp" |
| | 46 | #include "eventlog_record.hpp" |
| | 47 | #include "eventlog_filter.hpp" |
| 33 | 48 | |
| 34 | 49 | CheckEventLog gCheckEventLog; |
| | 50 | |
| | 51 | |
| | 52 | |
| 35 | 53 | |
| 36 | 54 | BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) |
| … |
… |
|
| 44 | 62 | CheckEventLog::~CheckEventLog() { |
| 45 | 63 | } |
| 46 | | |
| 47 | | |
| | 64 | struct parse_exception { |
| | 65 | parse_exception(std::wstring) {} |
| | 66 | }; |
| | 67 | |
| | 68 | #include <parsers/where.cpp> |
| | 69 | #include <parsers/grammar.cpp> |
| | 70 | #include <parsers/ast.cpp> |
| | 71 | |
| | 72 | <<<<<<< .working |
| 48 | 73 | bool CheckEventLog::loadModule(NSCAPI::moduleLoadMode mode) { |
| 49 | 74 | try { |
| … |
… |
|
| 62 | 87 | } catch (...) { |
| 63 | 88 | NSC_LOG_ERROR_STD(_T("Failed to register command.")); |
| 64 | | } |
| 65 | | return true; |
| | 89 | ======= |
| | 90 | namespace filter { |
| | 91 | namespace where { |
| | 92 | struct type_obj : public parsers::where::varible_handler<type_obj> { |
| | 93 | typedef parsers::where::varible_handler<type_obj> handler; |
| | 94 | typedef std::list<std::wstring> error_type; |
| | 95 | typedef std::map<std::wstring,parsers::where::value_type> types_type; |
| | 96 | types_type types; |
| | 97 | error_type errors; |
| | 98 | static const parsers::where::value_type type_custom_severity = parsers::where::type_custom_int_1; |
| | 99 | EventLogRecord *record; |
| | 100 | type_obj() : record(NULL) { |
| | 101 | using namespace boost::assign; |
| | 102 | using namespace parsers::where; |
| | 103 | insert(types) |
| | 104 | (_T("id"), (type_int)) |
| | 105 | (_T("source"), (type_string)) |
| | 106 | (_T("type"), (type_int)) |
| | 107 | (_T("severity"), (type_custom_severity)) |
| | 108 | (_T("message"), (type_string)) |
| | 109 | (_T("strings"), (type_string)) |
| | 110 | (_T("written"), (type_date)) |
| | 111 | (_T("generated"), (type_date)); |
| | 112 | } |
| | 113 | type_obj(EventLogRecord *record) : record(record) {} |
| | 114 | bool has_variable(std::wstring key) { |
| | 115 | return types.find(key) != types.end(); |
| | 116 | } |
| | 117 | parsers::where::value_type get_type(std::wstring key) { |
| | 118 | types_type::const_iterator cit = types.find(key); |
| | 119 | if (cit == types.end()) |
| | 120 | return parsers::where::type_invalid; |
| | 121 | return cit->second; |
| | 122 | } |
| | 123 | bool can_convert(parsers::where::value_type from, parsers::where::value_type to) { |
| | 124 | if ((from == parsers::where::type_string)&&(to == type_custom_severity)) |
| | 125 | return true; |
| | 126 | return false; |
| | 127 | } |
| | 128 | void error(std::wstring err) { |
| | 129 | errors.push_back(err); |
| | 130 | } |
| | 131 | bool has_error() { |
| | 132 | return !errors.empty(); |
| | 133 | } |
| | 134 | long long get_id() { |
| | 135 | if (record == NULL) throw _T("Whoops"); return record->eventID(); |
| | 136 | } |
| | 137 | std::wstring get_source() { |
| | 138 | if (record == NULL) throw _T("Whoops"); return record->eventSource(); |
| | 139 | } |
| | 140 | long long get_el_type() { |
| | 141 | if (record == NULL) throw _T("Whoops"); return record->eventType(); |
| | 142 | } |
| | 143 | long long get_severity() { |
| | 144 | if (record == NULL) throw _T("Whoops"); |
| | 145 | //NSC_DEBUG_MSG_STD(_T("Severity: ") + strEx::itos(record->severity())); |
| | 146 | return record->severity(); |
| | 147 | } |
| | 148 | std::wstring get_message() { |
| | 149 | if (record == NULL) throw _T("Whoops"); return record->render_message(); |
| | 150 | } |
| | 151 | std::wstring get_strings() { |
| | 152 | if (record == NULL) throw _T("Whoops"); return record->enumStrings(); |
| | 153 | } |
| | 154 | long long get_written() { |
| | 155 | if (record == NULL) throw _T("Whoops"); return record->written(); |
| | 156 | } |
| | 157 | long long get_generated() { |
| | 158 | if (record == NULL) throw _T("Whoops"); return record->generated(); |
| | 159 | } |
| | 160 | |
| | 161 | handler::bound_string_type bind_string(std::wstring key) { |
| | 162 | handler::bound_string_type ret; |
| | 163 | if (key == _T("source")) |
| | 164 | ret = &type_obj::get_source; |
| | 165 | else if (key == _T("message")) |
| | 166 | ret = &type_obj::get_message; |
| | 167 | else if (key == _T("strings")) |
| | 168 | ret = &type_obj::get_strings; |
| | 169 | else |
| | 170 | NSC_DEBUG_MSG_STD(_T("Failed to bind (string): ") + key); |
| | 171 | return ret; |
| | 172 | } |
| | 173 | handler::bound_int_type bind_int(std::wstring key) { |
| | 174 | handler::bound_int_type ret; |
| | 175 | if (key == _T("id")) |
| | 176 | ret = &type_obj::get_id; |
| | 177 | else if (key == _T("type")) |
| | 178 | ret = &type_obj::get_el_type; |
| | 179 | else if (key == _T("severity")) |
| | 180 | ret = &type_obj::get_severity; |
| | 181 | else if (key == _T("generated")) |
| | 182 | ret = &type_obj::get_generated; |
| | 183 | else if (key == _T("written")) |
| | 184 | ret = &type_obj::get_written; |
| | 185 | else |
| | 186 | NSC_DEBUG_MSG_STD(_T("Failed to bind (int): ") + key); |
| | 187 | return ret; |
| | 188 | } |
| | 189 | |
| | 190 | bool has_function(parsers::where::value_type to, std::wstring name, parsers::where::expression_ast<type_obj> subject) { |
| | 191 | if (to == type_custom_severity) |
| | 192 | return true; |
| | 193 | return false; |
| | 194 | } |
| | 195 | handler::bound_function_type bind_function(parsers::where::value_type to, std::wstring name, parsers::where::expression_ast<type_obj> subject) { |
| | 196 | handler::bound_function_type ret; |
| | 197 | if (to == type_custom_severity) |
| | 198 | ret = &type_obj::fun_convert_severity; |
| | 199 | return ret; |
| | 200 | } |
| | 201 | |
| | 202 | parsers::where::expression_ast<type_obj> fun_convert_severity(parsers::where::value_type target_type, parsers::where::expression_ast<type_obj> const& subject) { |
| | 203 | return parsers::where::expression_ast<type_obj>(parsers::where::int_value(convert_severity(subject.get_string(*this)))); |
| | 204 | } |
| | 205 | int convert_severity(std::wstring str) { |
| | 206 | if (str == _T("success") || str == _T("ok")) |
| | 207 | return 0; |
| | 208 | if (str == _T("informational") || str == _T("info")) |
| | 209 | return 1; |
| | 210 | if (str == _T("warning") || str == _T("warn")) |
| | 211 | return 2; |
| | 212 | if (str == _T("error") || str == _T("err")) |
| | 213 | return 3; |
| | 214 | error(_T("Invalid severity: ") + str); |
| | 215 | return strEx::stoi(str); |
| | 216 | } |
| | 217 | |
| | 218 | |
| | 219 | std::wstring get_error() { |
| | 220 | std::wstring ret; |
| | 221 | BOOST_FOREACH(std::wstring s, errors) { |
| | 222 | if (!ret.empty()) ret += _T(", "); |
| | 223 | ret += s; |
| | 224 | } |
| | 225 | return ret; |
| | 226 | } |
| | 227 | }; |
| | 228 | >>>>>>> .merge-right.r272 |
| | 229 | } |
| 66 | 230 | } |
| 67 | | bool CheckEventLog::unloadModule() { |
| 68 | | return true; |
| 69 | | } |
| 70 | | |
| 71 | | bool CheckEventLog::hasCommandHandler() { |
| 72 | | return true; |
| 73 | | } |
| 74 | | bool CheckEventLog::hasMessageHandler() { |
| 75 | | return false; |
| 76 | | } |
| | 231 | |
| 77 | 232 | |
| 78 | 233 | namespace simple_registry { |
| … |
… |
|
| 145 | 300 | } |
| 146 | 301 | |
| | 302 | <<<<<<< .working |
| 147 | 303 | std::list<std::wstring> get_keys(DWORD buffer_length = 2048) { |
| 148 | 304 | std::list<std::wstring> ret; |
| … |
… |
|
| 209 | 365 | public: |
| 210 | 366 | EventLogRecord(std::wstring file, EVENTLOGRECORD *pevlr, __int64 currentTime) : file_(file), pevlr_(pevlr), currentTime_(currentTime) { |
| 211 | | } |
| 212 | | inline __int64 timeGenerated() const { |
| 213 | | return (currentTime_-pevlr_->TimeGenerated)*1000; |
| 214 | | } |
| 215 | | inline __int64 timeWritten() const { |
| 216 | | return (currentTime_-pevlr_->TimeWritten)*1000; |
| 217 | | } |
| 218 | | inline std::wstring eventSource() const { |
| 219 | | return reinterpret_cast<WCHAR*>(reinterpret_cast<LPBYTE>(pevlr_) + sizeof(EVENTLOGRECORD)); |
| 220 | | } |
| 221 | | inline DWORD eventID() const { |
| 222 | | return (pevlr_->EventID&0xffff); |
| 223 | | } |
| 224 | | inline DWORD severity() const { |
| 225 | | return (pevlr_->EventID>>30); |
| 226 | | } |
| 227 | | |
| 228 | | inline DWORD eventType() const { |
| 229 | | return pevlr_->EventType; |
| 230 | | } |
| | 367 | ======= |
| | 368 | |
| | 369 | struct filter_container { |
| | 370 | enum filter_types { |
| | 371 | filter_plus = 1, |
| | 372 | filter_minus = 2, |
| | 373 | filter_normal = 3 |
| | 374 | }; |
| | 375 | typedef std::pair<int,eventlog_filter> filteritem_type; |
| | 376 | typedef std::list<filteritem_type > filterlist_type; |
| | 377 | |
| | 378 | filterlist_type filters; |
| | 379 | |
| | 380 | bool bFilterAll; |
| | 381 | bool bFilterIn; |
| | 382 | |
| | 383 | bool bDebug; |
| | 384 | int debugThreshold; |
| | 385 | |
| | 386 | bool bShowDescriptions; |
| | 387 | std::wstring syntax; |
| | 388 | |
| | 389 | std::wstring filter; |
| | 390 | |
| | 391 | filter_container(std::wstring syntax, bool debug) : bDebug(debug), debugThreshold(0), bFilterIn(true), bFilterAll(false), bShowDescriptions(false), syntax(syntax) {} |
| | 392 | |
| | 393 | }; |
| | 394 | |
| | 395 | struct any_mode_filter { |
| | 396 | virtual bool boot() = 0; |
| | 397 | virtual bool validate(std::wstring &message) = 0; |
| | 398 | virtual bool match(EventLogRecord &record) = 0; |
| | 399 | virtual std::wstring get_name() = 0; |
| | 400 | virtual std::wstring get_subject() = 0; |
| | 401 | }; |
| | 402 | |
| | 403 | struct first_mode_filter : public any_mode_filter { |
| | 404 | typedef filter_container::filterlist_type::const_iterator filter_iterator; |
| | 405 | filter_container &data; |
| | 406 | first_mode_filter(filter_container &data) : data(data) {} |
| | 407 | bool boot() {return true;} |
| | 408 | bool validate(std::wstring &message) { |
| | 409 | if (data.filters.empty()) { |
| | 410 | message = _T("No filters specified try adding: filter+generated=>2d"); |
| | 411 | return false; |
| | 412 | } |
| | 413 | return true; |
| | 414 | >>>>>>> .merge-right.r272 |
| | 415 | } |
| | 416 | |
| | 417 | virtual bool match(EventLogRecord &record) { |
| | 418 | bool bMatch = !data.bFilterIn; |
| | 419 | for (filter_iterator cit3 = data.filters.begin(); cit3 != data.filters.end(); ++cit3) { |
| | 420 | std::wstring reason; |
| | 421 | int mode = (*cit3).first; |
| | 422 | bool bTmpMatched = (*cit3).second.matchFilter(record); |
| | 423 | if (data.bFilterAll) { |
| | 424 | if (!bTmpMatched) { |
| | 425 | bMatch = false; |
| | 426 | break; |
| | 427 | } |
| | 428 | } else { |
| | 429 | if (bTmpMatched) { |
| | 430 | bMatch = true; |
| | 431 | break; |
| | 432 | } |
| | 433 | } |
| | 434 | } |
| | 435 | if ((data.bFilterIn&&bMatch)||(!data.bFilterIn&&!bMatch)) { |
| | 436 | return true; |
| | 437 | } |
| | 438 | return false; |
| | 439 | |
| | 440 | } |
| | 441 | <<<<<<< .working |
| 231 | 442 | |
| 232 | 443 | std::wstring userSID() const { |
| … |
… |
|
| 255 | 466 | |
| 256 | 467 | return dstr + ustr; |
| 257 | | } |
| 258 | | |
| 259 | | std::wstring enumStrings() const { |
| 260 | | std::wstring ret; |
| 261 | | TCHAR* p = reinterpret_cast<TCHAR*>(reinterpret_cast<LPBYTE>(pevlr_) + pevlr_->StringOffset); |
| 262 | | for (unsigned int i =0;i<pevlr_->NumStrings;i++) { |
| 263 | | std::wstring s = p; |
| 264 | | if (!s.empty()) |
| 265 | | s += _T(", "); |
| 266 | | ret += s; |
| 267 | | p+= wcslen(p)+1; |
| 268 | | } |
| 269 | | return ret; |
| 270 | | } |
| 271 | | |
| 272 | | static DWORD appendType(DWORD dwType, std::wstring sType) { |
| 273 | | return dwType | translateType(sType); |
| 274 | | } |
| 275 | | static DWORD subtractType(DWORD dwType, std::wstring sType) { |
| 276 | | return dwType & (!translateType(sType)); |
| 277 | | } |
| | 468 | ======= |
| | 469 | std::wstring get_name() { |
| | 470 | return _T("deprecated"); |
| | 471 | >>>>>>> .merge-right.r272 |
| | 472 | } |
| | 473 | <<<<<<< .working |
| | 474 | ======= |
| | 475 | std::wstring get_subject() { return _T("TODO"); } |
| | 476 | >>>>>>> .merge-right.r272 |
| | 477 | |
| | 478 | }; |
| | 479 | struct second_mode_filter : public any_mode_filter { |
| | 480 | typedef filter_container::filterlist_type::const_iterator filter_iterator; |
| | 481 | |
| | 482 | filter_container &data; |
| | 483 | second_mode_filter(filter_container &data) : data(data) {} |
| | 484 | bool boot() {return true;} |
| | 485 | bool validate(std::wstring &message) { |
| | 486 | if (data.filters.empty()) { |
| | 487 | message = _T("No filters specified try adding: filter+generated=>2d"); |
| | 488 | return false; |
| | 489 | } |
| | 490 | return true; |
| | 491 | } |
| | 492 | |
| | 493 | virtual bool match(EventLogRecord &record) { |
| | 494 | bool bMatch = !data.bFilterIn; |
| | 495 | int i=0; |
| | 496 | for (filter_iterator cit3 = data.filters.begin(); cit3 != data.filters.end(); ++cit3, i++ ) { |
| | 497 | std::wstring reason; |
| | 498 | int mode = (*cit3).first; |
| | 499 | bool bTmpMatched = (*cit3).second.matchFilter(record); |
| | 500 | if ((mode == filter_container::filter_minus)&&(bTmpMatched)) { |
| | 501 | // a -<filter> hit so thrash item and bail out! |
| | 502 | if (data.bDebug && (i>data.debugThreshold)) |
| | 503 | NSC_DEBUG_MSG_STD(_T("[") + strEx::itos(i) + _T("] Matched: - ") + (*cit3).second.to_string() + _T(" for: ") + record.render(data.bShowDescriptions, data.syntax)); |
| | 504 | return false; |
| | 505 | } else if ((mode == filter_container::filter_plus)&&(!bTmpMatched)) { |
| | 506 | // a +<filter> hit so keep item and bail out! |
| | 507 | if (data.bDebug && (i>data.debugThreshold)) |
| | 508 | NSC_DEBUG_MSG_STD(_T("[") + strEx::itos(i) + _T("] Matched: + ") + (*cit3).second.to_string() + _T(" for: ") + record.render(data.bShowDescriptions, data.syntax)); |
| | 509 | return false; |
| | 510 | } else if (bTmpMatched) { |
| | 511 | if (data.bDebug && (i>data.debugThreshold)) |
| | 512 | NSC_DEBUG_MSG_STD(_T("[") + strEx::itos(i) + _T("] Matched: . ") + (*cit3).second.to_string() + _T(" for: ") + record.render(data.bShowDescriptions, data.syntax)); |
| | 513 | bMatch = true; |
| | 514 | } |
| | 515 | } |
| | 516 | return bMatch; |
| | 517 | } |
| | 518 | std::wstring get_name() { |
| | 519 | return _T("old"); |
| | 520 | } |
| | 521 | <<<<<<< .working |
| 278 | 522 | static DWORD translateType(std::wstring sType) { |
| 279 | 523 | if (sType == _T("error")) |
| … |
… |
|
| 330 | 574 | NSC_LOG_ERROR_STD(_T("Could not extract DLL for eventsource: ") + eventSource() + _T(": ") + e.what()); |
| 331 | 575 | return _T(""); |
| 332 | | } |
| 333 | | } |
| 334 | | |
| | 576 | ======= |
| | 577 | std::wstring get_subject() { return _T("TODO"); } |
| | 578 | }; |
| | 579 | |
| | 580 | struct where_mode_filter : public any_mode_filter { |
| | 581 | filter_container &data; |
| | 582 | std::string message; |
| | 583 | parsers::where::parser<filter::where::type_obj> ast_parser; |
| | 584 | filter::where::type_obj dummy; |
| | 585 | |
| | 586 | where_mode_filter(filter_container &data) : data(data) {} |
| | 587 | bool boot() {return true; } |
| | 588 | |
| | 589 | bool validate(std::wstring &message) { |
| | 590 | if (data.bDebug) |
| | 591 | NSC_DEBUG_MSG_STD(_T("Parsing: ") + data.filter); |
| | 592 | |
| | 593 | if (!ast_parser.parse(data.filter)) { |
| | 594 | NSC_LOG_ERROR_STD(_T("Parsing failed of '") + data.filter + _T("' at: ") + ast_parser.rest); |
| | 595 | message = _T("Parsing failed: ") + ast_parser.rest; |
| | 596 | return false; |
| | 597 | >>>>>>> .merge-right.r272 |
| | 598 | } |
| | 599 | <<<<<<< .working |
| | 600 | } |
| | 601 | ======= |
| | 602 | if (data.bDebug) |
| | 603 | NSC_DEBUG_MSG_STD(_T("Parsing succeeded: ") + ast_parser.result_as_tree()); |
| | 604 | |
| | 605 | if (!ast_parser.derive_types(dummy) || dummy.has_error()) { |
| | 606 | message = _T("Invalid types: ") + dummy.get_error(); |
| | 607 | return false; |
| | 608 | } |
| | 609 | if (data.bDebug) |
| | 610 | NSC_DEBUG_MSG_STD(_T("Type resolution succeeded: ") + ast_parser.result_as_tree()); |
| | 611 | >>>>>>> .merge-right.r272 |
| | 612 | |
| | 613 | <<<<<<< .working |
| 335 | 614 | std::wstring render_message() { |
| 336 | 615 | std::vector<std::wstring> args; |
| … |
… |
|
| 343 | 622 | p = &(p[len+1]); |
| 344 | 623 | //p += len+1; |
| 345 | | } |
| 346 | | |
| | 624 | ======= |
| | 625 | if (!ast_parser.bind(dummy) || dummy.has_error()) { |
| | 626 | message = _T("Variable and function binding failed: ") + dummy.get_error(); |
| | 627 | return false; |
| | 628 | >>>>>>> .merge-right.r272 |
| | 629 | } |
| | 630 | if (data.bDebug) |
| | 631 | NSC_DEBUG_MSG_STD(_T("Binding succeeded: ") + ast_parser.result_as_tree()); |
| | 632 | |
| | 633 | <<<<<<< .working |
| 347 | 634 | std::wstring ret; |
| 348 | 635 | strEx::splitList dlls = strEx::splitEx(get_dll(), _T(";")); |
| … |
… |
|
| 369 | 656 | ret += msg; |
| 370 | 657 | } |
| 371 | | } |
| | 658 | ======= |
| | 659 | if (!ast_parser.static_eval(dummy) || dummy.has_error()) { |
| | 660 | message = _T("Static evaluation failed: ") + dummy.get_error(); |
| | 661 | return false; |
| | 662 | } |
| | 663 | if (data.bDebug) |
| | 664 | NSC_DEBUG_MSG_STD(_T("Static evaluation succeeded: ") + ast_parser.result_as_tree()); |
| | 665 | |
| | 666 | return true; |
| | 667 | } |
| | 668 | virtual bool match(EventLogRecord &record) { |
| | 669 | filter::where::type_obj obj(&record); |
| | 670 | //NSC_DEBUG_MSG_STD(_T("Evaluating: ") + ast_parser.result_as_tree() + _T(": ") + strEx::itos(record.severity()) + _T(" >> ") + strEx::itos(ast_parser.evaluate(obj))); |
| | 671 | bool ret = ast_parser.evaluate(obj); |
| | 672 | if (obj.has_error()) { |
| | 673 | NSC_LOG_ERROR_STD(_T("Error: ") + obj.get_error()); |
| | 674 | >>>>>>> .merge-right.r272 |
| | 675 | } |
| | 676 | <<<<<<< .working |
| 372 | 677 | delete [] pArgs; |
| | 678 | ======= |
| | 679 | >>>>>>> .merge-right.r272 |
| 373 | 680 | return ret; |
| 374 | 681 | } |
| | 682 | <<<<<<< .working |
| 375 | 683 | // SYSTEMTIME |
| 376 | 684 | boost::posix_time::ptime get_time(DWORD time) { |
| … |
… |
|
| 379 | 687 | __int64 lgTemp; |
| 380 | 688 | __int64 SecsTo1970 = 116444736000000000; |
| 381 | | |
| 382 | | lgTemp = Int32x32To64(time,10000000) + SecsTo1970; |
| 383 | | |
| 384 | | FileTime.dwLowDateTime = (DWORD) lgTemp; |
| 385 | | FileTime.dwHighDateTime = (DWORD)(lgTemp >> 32); |
| 386 | | |
| | 689 | ======= |
| | 690 | std::wstring get_name() { |
| | 691 | return _T("where"); |
| | 692 | } |
| | 693 | std::wstring get_subject() { return data.filter; } |
| | 694 | }; |
| | 695 | >>>>>>> .merge-right.r272 |
| | 696 | |
| | 697 | |
| | 698 | |
| | 699 | <<<<<<< .working |
| 387 | 700 | return boost::date_time::time_from_ftime<boost::posix_time::ptime>(FileTime); |
| 388 | 701 | |
| … |
… |
|
| 394 | 707 | */ |
| 395 | 708 | } |
| 396 | | |
| | 709 | ======= |
| | 710 | void CheckEventLog::parse(std::wstring expr) { |
| | 711 | //return false; |
| | 712 | /* |
| | 713 | my_type_obj obj1(123); |
| | 714 | std::wcout << _T("Result (001): ") << ast_parser.evaluate(obj1) << std::endl; |
| | 715 | my_type_obj obj2(321); |
| | 716 | std::wcout << _T("Result (002): ") << ast_parser.evaluate(obj2) << std::endl; |
| | 717 | */ |
| | 718 | } |
| | 719 | >>>>>>> .merge-right.r272 |
| | 720 | |
| | 721 | <<<<<<< .working |
| 397 | 722 | boost::posix_time::ptime get_time_generated() { |
| 398 | 723 | return get_time(pevlr_->TimeGenerated); |
| 399 | | } |
| | 724 | ======= |
| | 725 | bool CheckEventLog::loadModule() { |
| | 726 | try { |
| | 727 | NSCModuleHelper::registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); |
| | 728 | debug_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_DEBUG, EVENTLOG_DEBUG_DEFAULT)==1; |
| | 729 | lookup_names_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_LOOKUP_NAMES, EVENTLOG_LOOKUP_NAMES_DEFAULT)==1; |
| | 730 | syntax_ = NSCModuleHelper::getSettingsString(EVENTLOG_SECTION_TITLE, EVENTLOG_SYNTAX, EVENTLOG_SYNTAX_DEFAULT); |
| | 731 | buffer_length_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_BUFFER, EVENTLOG_BUFFER_DEFAULT); |
| | 732 | } catch (NSCModuleHelper::NSCMHExcpetion &e) { |
| | 733 | NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); |
| | 734 | } catch (...) { |
| | 735 | NSC_LOG_ERROR_STD(_T("Failed to register command.")); |
| | 736 | >>>>>>> .merge-right.r272 |
| | 737 | } |
| | 738 | <<<<<<< .working |
| 400 | 739 | boost::posix_time::ptime get_time_written() { |
| 401 | 740 | return get_time(pevlr_->TimeWritten); |
| 402 | 741 | } |
| 403 | | |
| 404 | | std::wstring render(bool propper, std::wstring syntax, std::wstring date_format = DATE_FORMAT) { |
| 405 | | if (propper) { |
| 406 | | // To obtain the appropriate message string from the message file, load the message file with the LoadLibrary function and use the FormatMessage function |
| 407 | | strEx::replace(syntax, _T("%message%"), render_message()); |
| 408 | | } else { |
| 409 | | strEx::replace(syntax, _T("%message%"), _T("%message% needs the descriptions flag set!")); |
| 410 | | } |
| | 742 | ======= |
| | 743 | /* |
| | 744 | parse(_T("321 = 123")); |
| | 745 | parse(_T("123 = 123")); |
| | 746 | parse(_T("id = 123")); |
| | 747 | parse(_T("id = 321")); |
| | 748 | >>>>>>> .merge-right.r272 |
| | 749 | |
| | 750 | parse(_T("id = '123'")); |
| | 751 | parse(_T("id = '321'")); |
| | 752 | |
| | 753 | parse(_T("id = convert(123)")); |
| | 754 | parse(_T("id = convert(321)")); |
| | 755 | |
| | 756 | parse(_T("id = 123 AND 123 = 123 AND id = 123x")); |
| | 757 | parse(_T("id = 123 AND 123 = 321 OR 123 = 456 OR 123 = 123")); |
| | 758 | |
| | 759 | parse(_T("foo")); |
| | 760 | parse(_T("1")); |
| | 761 | parse(_T("foo = ")); |
| | 762 | parse(_T("foo = 1")); |
| | 763 | parse(_T("'foo' = 1")); |
| | 764 | parse(_T("foo = '1'")); |
| | 765 | parse(_T("'hello'='world'")); |
| | 766 | |
| | 767 | parse(_T("foo = bar")); |
| | 768 | parse(_T("foo = bar AND bar = foo")); |
| | 769 | parse(_T("foo = bar AND bar = 1")); |
| | 770 | parse(_T("foo = bar AND bar = foo OR foo = bar")); |
| | 771 | parse(_T("foo = bar AND bar = 1 OR foo = 1")); |
| | 772 | parse(_T(" foo = bar AND ( test > 120 OR foo < 123) OR ugh IN (123, 456, 789)")); |
| | 773 | |
| | 774 | parse(_T("aaa = 111 OR bbb = 222 OR ccc = 333")); |
| | 775 | parse(_T("(aaa = 111) OR bbb = 222 OR ccc = 333")); |
| | 776 | parse(_T("(aaa = 111 OR bbb = 222) OR ccc = 333")); |
| | 777 | parse(_T("(aaa = 111 OR bbb = 222 OR ccc = 333)")); |
| | 778 | parse(_T("aaa = 111 OR (bbb = 222 OR ccc = 333)")); |
| | 779 | parse(_T("aaa = 111 OR bbb = 222 OR (ccc = 333)")); |
| | 780 | parse(_T("ccc = -333")); |
| | 781 | parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234)")); |
| | 782 | parse(_T("aaa = 111 OR bbb = 222 OR (ccc = -333)")); |
| | 783 | parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234) OR aaa = 123x")); |
| | 784 | parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234) OR aaa = 123x OR 123r = foo123")); |
| | 785 | */ |
| | 786 | return true; |
| | 787 | } |
| | 788 | bool CheckEventLog::unloadModule() { |
| | 789 | return true; |
| | 790 | } |
| | 791 | |
| | 792 | bool CheckEventLog::hasCommandHandler() { |
| | 793 | return true; |
| | 794 | } |
| | 795 | bool CheckEventLog::hasMessageHandler() { |
| | 796 | return false; |
| | 797 | } |
| | 798 | |
| | 799 | |
| | 800 | std::wstring find_eventlog_name(std::wstring name) { |
| | 801 | try { |
| | 802 | simple_registry::registry_key key(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog")); |
| | 803 | std::list<std::wstring> list = key.get_keys(); |
| | 804 | for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { |
| | 805 | try { |
| | 806 | simple_registry::registry_key sub_key(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + *cit); |
| | 807 | std::wstring file = sub_key.get_string(_T("DisplayNameFile")); |
| | 808 | int id = sub_key.get_int(_T("DisplayNameID")); |
| | 809 | std::wstring real_name = error::format::message::from_module(file, id); |
| | 810 | strEx::replace(real_name, _T("\n"), _T("")); |
| | 811 | strEx::replace(real_name, _T("\r"), _T("")); |
| | 812 | NSC_DEBUG_MSG(_T("Attempting to match: ") + real_name + _T(" with ") + name); |
| | 813 | if (real_name == name) |
| | 814 | return *cit; |
| | 815 | } catch (simple_registry::registry_exception &e) { e;} |
| | 816 | } |
| | 817 | <<<<<<< .working |
| 411 | 818 | |
| 412 | 819 | strEx::replace(syntax, _T("%source%"), eventSource()); |
| … |
… |
|
| 419 | 826 | strEx::replace(syntax, _T("%user%"), userSID()); |
| 420 | 827 | return syntax; |
| 421 | | } |
| 422 | | }; |
| 423 | | /* |
| 424 | | return (pevlr_->EventID&0xffff); |
| | 828 | ======= |
| | 829 | return name; |
| | 830 | } catch (simple_registry::registry_exception &e) { |
| | 831 | NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand): ") + e.what()); |
| | 832 | return name; |
| | 833 | } catch (...) { |
| | 834 | NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand)")); |
| | 835 | return name; |
| | 836 | >>>>>>> .merge-right.r272 |
| | 837 | } |
| 425 | 838 | } |
| 426 | | inline DWORD severity() const { |
| 427 | | return (pevlr_->EventID>>30); |
| 428 | | */ |
| | 839 | |
| | 840 | |
| | 841 | |
| 429 | 842 | class uniq_eventlog_record { |
| 430 | 843 | DWORD ID; |
| … |
… |
|
| 444 | 857 | |
| 445 | 858 | |
| 446 | | struct eventlog_filter { |
| 447 | | filters::filter_all_strings eventSource; |
| 448 | | filters::filter_all_numeric<unsigned int, filters::handlers::eventtype_handler> eventType; |
| 449 | | filters::filter_all_numeric<unsigned int, filters::handlers::eventseverity_handler> eventSeverity; |
| 450 | | filters::filter_all_strings message; |
| 451 | | filters::filter_all_times timeWritten; |
| 452 | | filters::filter_all_times timeGenerated; |
| 453 | | filters::filter_all_numeric<DWORD, filters::handlers::eventtype_handler> eventID; |
| 454 | | std::wstring value_; |
| 455 | | |
| 456 | | inline bool hasFilter() { |
| 457 | | return eventSource.hasFilter() || eventType.hasFilter() || eventID.hasFilter() || eventSeverity.hasFilter() || message.hasFilter() || |
| 458 | | timeWritten.hasFilter() || timeGenerated.hasFilter(); |
| 459 | | } |
| 460 | | std::wstring getValue() const { |
| 461 | | if (eventSource.hasFilter()) |
| 462 | | return _T("event-source: ") + eventSource.getValue(); |
| 463 | | if (eventType.hasFilter()) |
| 464 | | return _T("event-type: ") + eventType.getValue(); |
| 465 | | if (eventSeverity.hasFilter()) |
| 466 | | return _T("severity: ") + eventSeverity.getValue(); |
| 467 | | if (eventID.hasFilter()) |
| 468 | | return _T("event-id: ") + eventID.getValue(); |
| 469 | | if (message.hasFilter()) |
| 470 | | return _T("message: ") + message.getValue(); |
| 471 | | if (timeWritten.hasFilter()) |
| 472 | | return _T("time-written: ") + timeWritten.getValue(); |
| 473 | | if (timeGenerated.hasFilter()) |
| 474 | | return _T("time-generated: ") + timeGenerated.getValue(); |
| 475 | | return _T("UNknown..."); |
| 476 | | } |
| 477 | | bool matchFilter(const EventLogRecord &value) const { |
| 478 | | if ((eventSource.hasFilter())&&(eventSource.matchFilter(value.eventSource()))) |
| 479 | | return true; |
| 480 | | else if ((eventType.hasFilter())&&(eventType.matchFilter(value.eventType()))) |
| 481 | | return true; |
| 482 | | else if ((eventSeverity.hasFilter())&&(eventSeverity.matchFilter(value.severity()))) |
| 483 | | return true; |
| 484 | | else if ((eventID.hasFilter())&&(eventID.matchFilter(value.eventID()))) |
| 485 | | return true; |
| 486 | | else if ((message.hasFilter())&&(message.matchFilter(value.enumStrings()))) |
| 487 | | return true; |
| 488 | | else if ((timeWritten.hasFilter())&&(timeWritten.matchFilter(value.timeWritten()))) |
| 489 | | return true; |
| 490 | | else if ((timeGenerated.hasFilter())&&(timeGenerated.matchFilter(value.timeGenerated()))) |
| 491 | | return true; |
| 492 | | return false; |
| 493 | | } |
| 494 | | }; |
| | 859 | |
| 495 | 860 | |
| 496 | 861 | |
| 497 | 862 | #define MAP_FILTER(value, obj, filtermode) \ |
| 498 | | else if (p__.first == value) { eventlog_filter filter; filter.obj = p__.second; filter_chain.push_back(filteritem_type(filtermode, filter)); } |
| | 863 | else if (p__.first == value) { filter.obj = p__.second; if (bPush) { data.filters.push_back(filter_container::filteritem_type(filtermode, filter)); filter = eventlog_filter(); } } |
| | 864 | #define MAP_FILTER_LAST(value, obj) \ |
| | 865 | else if (p__.first == value) { data.filters.front().second.obj = p__.second; } |
| 499 | 866 | |
| 500 | 867 | struct event_log_buffer { |
| … |
… |
|
| 515 | 882 | }; |
| 516 | 883 | |
| | 884 | <<<<<<< .working |
| | 885 | |
| | 886 | #define MAP_FILTER(value, obj, filtermode) \ |
| | 887 | else if (p__.first == value) { eventlog_filter filter; filter.obj = p__.second; filter_chain.push_back(filteritem_type(filtermode, filter)); } |
| | 888 | |
| | 889 | struct event_log_buffer { |
| | 890 | BYTE *bBuffer; |
| | 891 | DWORD bufferSize_; |
| | 892 | event_log_buffer(DWORD bufferSize) : bufferSize_(bufferSize) { |
| | 893 | bBuffer = new BYTE[bufferSize+10]; |
| | 894 | } |
| | 895 | ~event_log_buffer() { |
| | 896 | delete [] bBuffer; |
| | 897 | } |
| | 898 | EVENTLOGRECORD* getBufferUnsafe() { |
| | 899 | return reinterpret_cast<EVENTLOGRECORD*>(bBuffer); |
| | 900 | } |
| | 901 | DWORD getBufferSize() { |
| | 902 | return bufferSize_; |
| | 903 | } |
| | 904 | }; |
| | 905 | |
| | 906 | ======= |
| | 907 | >>>>>>> .merge-right.r272 |
| 517 | 908 | NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { |
| 518 | 909 | if (command != _T("CheckEventLog")) |
| 519 | 910 | return NSCAPI::returnIgnored; |
| | 911 | <<<<<<< .working |
| 520 | 912 | typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container; |
| 521 | 913 | typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container; |
| … |
… |
|
| 523 | 915 | typedef std::pair<int,eventlog_filter> filteritem_type; |
| 524 | 916 | typedef std::list<filteritem_type > filterlist_type; |
| | 917 | ======= |
| | 918 | simple_timer time; |
| | 919 | typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container; |
| | 920 | typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container; |
| | 921 | |
| | 922 | >>>>>>> .merge-right.r272 |
| 525 | 923 | NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; |
| 526 | 924 | std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); |
| 527 | 925 | |
| 528 | 926 | std::list<std::wstring> files; |
| | 927 | <<<<<<< .working |
| 529 | 928 | filterlist_type filter_chain; |
| 530 | 929 | EventLogQuery1Container query1; |
| 531 | 930 | EventLogQuery2Container query2; |
| | 931 | ======= |
| | 932 | EventLogQuery1Container query1; |
| | 933 | EventLogQuery2Container query2; |
| | 934 | >>>>>>> .merge-right.r272 |
| | 935 | |
| | 936 | |
| | 937 | filter_container data(syntax_, debug_); |
| 532 | 938 | |
| 533 | 939 | bool bPerfData = true; |
| | 940 | <<<<<<< .working |
| 534 | 941 | bool bFilterIn = true; |
| 535 | 942 | bool bFilterAll = false; |
| 536 | 943 | bool bFilterNew = true; |
| 537 | 944 | bool bShowDescriptions = false; |
| | 945 | ======= |
| | 946 | bool bFilterNew = true; |
| | 947 | >>>>>>> .merge-right.r272 |
| 538 | 948 | bool unique = false; |
| 539 | 949 | unsigned int truncate = 0; |
| 540 | | std::wstring syntax = syntax_; |
| 541 | | const int filter_plus = 1; |
| 542 | | const int filter_minus = 2; |
| 543 | | const int filter_normal = 3; |
| 544 | | const int filter_compat = 3; |
| | 950 | event_log_buffer buffer(buffer_length_); |
| | 951 | bool bPush = true; |
| | 952 | eventlog_filter filter; |
| | 953 | /* |
| | 954 | try { |
| | 955 | event_log_buffer buffer(buffer_length_); |
| | 956 | } catch (std::exception e) { |
| | 957 | message = std::wstring(_T("Failed to allocate memory: ")) + strEx::string_to_wstring(e.what()); |
| | 958 | return NSCAPI::returnUNKNOWN; |
| | 959 | } |
| | 960 | */ |
| 545 | 961 | event_log_buffer buffer(buffer_length_); |
| 546 | 962 | /* |
| … |
… |
|
| 559 | 975 | MAP_OPTIONS_STR2INT(_T("truncate"), truncate) |
| 560 | 976 | MAP_OPTIONS_BOOL_TRUE(_T("unique"), unique) |
| 561 | | MAP_OPTIONS_BOOL_TRUE(_T("descriptions"), bShowDescriptions) |
| | 977 | MAP_OPTIONS_BOOL_TRUE(_T("descriptions"), data.bShowDescriptions) |
| 562 | 978 | MAP_OPTIONS_PUSH(_T("file"), files) |
| 563 | 979 | MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) |
| 564 | 980 | MAP_OPTIONS_BOOL_EX(_T("filter"), bFilterNew, _T("new"), _T("old")) |
| 565 | | MAP_OPTIONS_BOOL_EX(_T("filter"), bFilterIn, _T("in"), _T("out")) |
| 566 | | MAP_OPTIONS_BOOL_EX(_T("filter"), bFilterAll, _T("all"), _T("any")) |
| 567 | | MAP_OPTIONS_STR(_T("syntax"), syntax) |
| | 981 | MAP_OPTIONS_BOOL_EX(_T("filter"), data.bFilterIn, _T("in"), _T("out")) |
| | 982 | MAP_OPTIONS_BOOL_EX(_T("filter"), data.bFilterAll, _T("all"), _T("any")) |
| | 983 | MAP_OPTIONS_BOOL_EX(_T("debug"), data.bDebug, _T("true"), _T("false")) |
| | 984 | MAP_OPTIONS_STR2INT(_T("debug-threshold"), data.debugThreshold) |
| | 985 | MAP_OPTIONS_STR(_T("syntax"), data.syntax) |
| 568 | 986 | /* |
| 569 | 987 | MAP_FILTER_OLD("filter-eventType", eventType) |
| … |
… |
|
| 575 | 993 | MAP_FILTER_OLD("filter-message", message) |
| 576 | 994 | */ |
| 577 | | MAP_FILTER(_T("filter+eventType"), eventType, filter_plus) |
| 578 | | MAP_FILTER(_T("filter+severity"), eventSeverity, filter_plus) |
| 579 | | MAP_FILTER(_T("filter+eventID"), eventID, filter_plus) |
| 580 | | MAP_FILTER(_T("filter+eventSource"), eventSource, filter_plus) |
| 581 | | MAP_FILTER(_T("filter+generated"), timeGenerated, filter_plus) |
| 582 | | MAP_FILTER(_T("filter+written"), timeWritten, filter_plus) |
| 583 | | MAP_FILTER(_T("filter+message"), message, filter_plus) |
| 584 | | |
| 585 | | MAP_FILTER(_T("filter.eventType"), eventType, filter_normal) |
| 586 | | MAP_FILTER(_T("filter.severity"), eventSeverity, filter_normal) |
| 587 | | MAP_FILTER(_T("filter.eventID"), eventID, filter_normal) |
| 588 | | MAP_FILTER(_T("filter.eventSource"), eventSource, filter_normal) |
| 589 | | MAP_FILTER(_T("filter.generated"), timeGenerated, filter_normal) |
| 590 | | MAP_FILTER(_T("filter.written"), timeWritten, filter_normal) |
| 591 | | MAP_FILTER(_T("filter.message"), message, filter_normal) |
| 592 | | |
| 593 | | MAP_FILTER(_T("filter-eventType"), eventType, filter_minus) |
| 594 | | MAP_FILTER(_T("filter-severity"), eventSeverity, filter_minus) |
| 595 | | MAP_FILTER(_T("filter-eventID"), eventID, filter_minus) |
| 596 | | MAP_FILTER(_T("filter-eventSource"), eventSource, filter_minus) |
| 597 | | MAP_FILTER(_T("filter-generated"), timeGenerated, filter_minus) |
| 598 | | MAP_FILTER(_T("filter-written"), timeWritten, filter_minus) |
| 599 | | MAP_FILTER(_T("filter-message"), message, filter_minus) |
| | 995 | MAP_FILTER(_T("filter+eventType"), eventType, filter_container::filter_plus) |
| | 996 | MAP_FILTER(_T("filter+severity"), eventSeverity, filter_container::filter_plus) |
| | 997 | MAP_FILTER(_T("filter+eventID"), eventID, filter_container::filter_plus) |
| | 998 | MAP_FILTER(_T("filter+eventSource"), eventSource, filter_container::filter_plus) |
| | 999 | MAP_FILTER(_T("filter+generated"), timeGenerated, filter_container::filter_plus) |
| | 1000 | MAP_FILTER(_T("filter+written"), timeWritten, filter_container::filter_plus) |
| | 1001 | MAP_FILTER(_T("filter+message"), message, filter_container::filter_plus) |
| | 1002 | |
| | 1003 | MAP_FILTER(_T("filter.eventType"), eventType, filter_container::filter_normal) |
| | 1004 | MAP_FILTER(_T("filter.severity"), eventSeverity, filter_container::filter_normal) |
| | 1005 | MAP_FILTER(_T("filter.eventID"), eventID, filter_container::filter_normal) |
| | 1006 | MAP_FILTER(_T("filter.eventSource"), eventSource, filter_container::filter_normal) |
| | 1007 | MAP_FILTER(_T("filter.generated"), timeGenerated, filter_container::filter_normal) |
| | 1008 | MAP_FILTER(_T("filter.written"), timeWritten, filter_container::filter_normal) |
| | 1009 | MAP_FILTER(_T("filter.message"), message, filter_container::filter_normal) |
| | 1010 | |
| | 1011 | MAP_FILTER(_T("filter-eventType"), eventType, filter_container::filter_minus) |
| | 1012 | MAP_FILTER(_T("filter-severity"), eventSeverity, filter_container::filter_minus) |
| | 1013 | MAP_FILTER(_T("filter-eventID"), eventID, filter_container::filter_minus) |
| | 1014 | MAP_FILTER(_T("filter-eventSource"), eventSource, filter_container::filter_minus) |
| | 1015 | MAP_FILTER(_T("filter-generated"), timeGenerated, filter_container::filter_minus) |
| | 1016 | MAP_FILTER(_T("filter-written"), timeWritten, filter_container::filter_minus) |
| | 1017 | MAP_FILTER(_T("filter-message"), message, filter_container::filter_minus) |
| | 1018 | |
| | 1019 | MAP_FILTER_LAST(_T("append-filter-eventType"), eventType) |
| | 1020 | MAP_FILTER_LAST(_T("append-filter-severity"), eventSeverity) |
| | 1021 | MAP_FILTER_LAST(_T("append-filter-eventID"), eventID) |
| | 1022 | MAP_FILTER_LAST(_T("append-filter-eventSource"), eventSource) |
| | 1023 | MAP_FILTER_LAST(_T("append-filter-generated"), timeGenerated) |
| | 1024 | MAP_FILTER_LAST(_T("append-filter-written"), timeWritten) |
| | 1025 | MAP_FILTER_LAST(_T("append-filter-message"), message) |
| | 1026 | |
| | 1027 | MAP_OPTIONS_STR(_T("filter"), data.filter) |
| 600 | 1028 | |
| 601 | 1029 | MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) |
| … |
… |
|
| 622 | 1050 | bool buffer_error_reported = false; |
| 623 | 1051 | |
| | 1052 | if (data.bDebug) { |
| | 1053 | std::wstring str; |
| | 1054 | BOOST_FOREACH(filter_container::filteritem_type item, data.filters) { |
| | 1055 | if (item.first == filter_container::filter_normal) |
| | 1056 | str += _T(". {"); |
| | 1057 | else if (item.first == filter_container::filter_plus) |
| | 1058 | str += _T("+ {"); |
| | 1059 | else if (item.first == filter_container::filter_minus) |
| | 1060 | str += _T("- {"); |
| | 1061 | else |
| | 1062 | str += _T("? {"); |
| | 1063 | |
| | 1064 | str += item.second.to_string() + _T(" }"); |
| | 1065 | } |
| | 1066 | NSC_DEBUG_MSG_STD(_T("Filter: ") + str); |
| | 1067 | } |
| | 1068 | |
| | 1069 | boost::shared_ptr<any_mode_filter> filter_impl; |
| | 1070 | if (bFilterNew) { |
| | 1071 | filter_impl = boost::shared_ptr<any_mode_filter>(new second_mode_filter(data)); |
| | 1072 | } else { |
| | 1073 | filter_impl = boost::shared_ptr<any_mode_filter>(new second_mode_filter(data)); |
| | 1074 | } if (!data.filter.empty()) { |
| | 1075 | filter_impl = boost::shared_ptr<any_mode_filter>(new where_mode_filter(data)); |
| | 1076 | } |
| | 1077 | |
| | 1078 | if (!filter_impl) { |
| | 1079 | message = _T("Failed to initialize filter subsystem."); |
| | 1080 | return NSCAPI::returnUNKNOWN; |
| | 1081 | } |
| | 1082 | |
| | 1083 | filter_impl->boot(); |
| | 1084 | |
| | 1085 | __time64_t ltime; |
| | 1086 | _time64(<ime); |
| | 1087 | |
| | 1088 | NSC_DEBUG_MSG_STD(_T("Using: ") + filter_impl->get_name() + _T(" ") + filter_impl->get_subject()); |
| | 1089 | |
| | 1090 | if (!filter_impl->validate(message)) { |
| | 1091 | return NSCAPI::returnUNKNOWN; |
| | 1092 | } |
| | 1093 | |
| | 1094 | |
| | 1095 | NSC_DEBUG_MSG_STD(_T("Boot time: ") + strEx::itos(time.stop())); |
| | 1096 | |
| 624 | 1097 | for (std::list<std::wstring>::const_iterator cit2 = files.begin(); cit2 != files.end(); ++cit2) { |
| 625 | 1098 | std::wstring name = *cit2; |
| … |
… |
|
| 641 | 1114 | |
| 642 | 1115 | |
| 643 | | __time64_t ltime; |
| 644 | | _time64(<ime); |
| 645 | | |
| 646 | 1116 | //GetOldestEventLogRecord(hLog, &dwThisRecord); |
| 647 | 1117 | |
| | 1118 | <<<<<<< .working |
| 648 | 1119 | while (true) { |
| 649 | 1120 | BOOL bStatus = ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, |
| … |
… |
|
| 673 | 1144 | if (filter_chain.empty()) { |
| 674 | 1145 | message = _T("No filters specified try adding: filter+generated=>2d"); |
| | 1146 | ======= |
| | 1147 | while (true) { |
| | 1148 | BOOL bStatus = ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, |
| | 1149 | 0, buffer.getBufferUnsafe(), buffer.getBufferSize(), &dwRead, &dwNeeded); |
| | 1150 | if (bStatus == FALSE) { |
| | 1151 | DWORD err = GetLastError(); |
| | 1152 | if (err == ERROR_INSUFFICIENT_BUFFER) { |
| | 1153 | if (!buffer_error_reported) { |
| | 1154 | NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small change the value of ") + EVENTLOG_BUFFER + _T("=") + strEx::itos(dwNeeded+1) + _T(" under [EventLog] in nsc.ini : ") + error::lookup::last_error(err)); |
| | 1155 | buffer_error_reported = true; |
| | 1156 | } |
| | 1157 | } else if (err == ERROR_HANDLE_EOF) { |
| | 1158 | break; |
| | 1159 | } else { |
| | 1160 | NSC_LOG_ERROR_STD(_T("Failed to read from eventlog: ") + error::lookup::last_error(err)); |
| | 1161 | message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err); |
| | 1162 | CloseEventLog(hLog); |
| | 1163 | >>>>>>> .merge-right.r272 |
| 675 | 1164 | return NSCAPI::returnUNKNOWN; |
| 676 | 1165 | } |
| 677 | | |
| 678 | | |
| 679 | | for (filterlist_type::const_iterator cit3 = filter_chain.begin(); cit3 != filter_chain.end(); ++cit3 ) { |
| 680 | | std::wstring reason; |
| 681 | | int mode = (*cit3).first; |
| 682 | | bool bTmpMatched = (*cit3).second.matchFilter(record); |
| 683 | | if (!bFilterNew) { |
| 684 | | if (bFilterAll) { |
| 685 | | if (!bTmpMatched) { |
| 686 | | bMatch = false; |
| 687 | | break; |
| 688 | | } |
| 689 | | } else { |
| 690 | | if (bTmpMatched) { |
| 691 | | bMatch = true; |
| 692 | | break; |
| 693 | | } |
| 694 | | } |
| 695 | | } else { |
| 696 | | if ((mode == filter_minus)&&(bTmpMatched)) { |
| 697 | | // a -<filter> hit so thrash item and bail out! |
| 698 | | if (debug_) |
| 699 | | NSC_DEBUG_MSG_STD(_T("Matched: - ") + (*cit3).second.getValue() + _T(" for: ") + record.render(bShowDescriptions, syntax)); |
| 700 | | bMatch = false; |
| 701 | | break; |
| 702 | | } else if ((mode == filter_plus)&&(!bTmpMatched)) { |
| 703 | | // a +<filter> missed hit so thrash item and bail out! |
| 704 | | if (debug_) |
| 705 | | NSC_DEBUG_MSG_STD(_T("Matched: + ") + (*cit3).second.getValue() + _T(" for: ") + record.render(bShowDescriptions, syntax)); |
| 706 | | bMatch = false; |
| 707 | | break; |
| 708 | | } else if (bTmpMatched) { |
| 709 | | if (debug_) |
| 710 | | NSC_DEBUG_MSG_STD(_T("Matched: . (contiunue): ") + (*cit3).second.getValue() + _T(" for: ") + record.render(bShowDescriptions, syntax)); |
| 711 | | bMatch = true; |
| 712 | | } |
| 713 | | } |
| 714 | | } |
| 715 | | bool match = false; |
| 716 | | if ((!bFilterNew)&&((bFilterIn&&bMatch)||(!bFilterIn&&!bMatch))) { |
| 717 | | match = true; |
| 718 | | } else if (bFilterNew&&bMatch) { |
| 719 | | match = true; |
| 720 | | } |
| | 1166 | } |
| | 1167 | EVENTLOGRECORD *pevlr = buffer.getBufferUnsafe(); |
| | 1168 | while (dwRead > 0) { |
| | 1169 | EventLogRecord record((*cit2), pevlr, ltime); |
| | 1170 | bool match = filter_impl->match(record); |
| 721 | 1171 | if (match&&unique) { |
| 722 | 1172 | match = false; |
| … |
… |
|
| 728 | 1178 | } |
| 729 | 1179 | else { |
| 730 | | if (!syntax.empty()) { |
| 731 | | uniq_record.message = record.render(bShowDescriptions, syntax); |
| 732 | | } else if (!bShowDescriptions) { |
| | 1180 | if (!data.syntax.empty()) { |
| | 1181 | uniq_record.message = record.render(data.bShowDescriptions, data.syntax); |
| | 1182 | } else if (!data.bShowDescriptions) { |
| 733 | 1183 | uniq_record.message = record.eventSource(); |
| 734 | 1184 | } else { |
| … |
… |
|
| 743 | 1193 | hit_count++; |
| 744 | 1194 | } else if (match) { |
| 745 | | if (!syntax.empty()) { |
| 746 | | strEx::append_list(message, record.render(bShowDescriptions, syntax)); |
| 747 | | } else if (!bShowDescriptions) { |
| | 1195 | if (!data.syntax.empty()) { |
| | 1196 | strEx::append_list(message, record.render(data.bShowDescriptions, data.syntax)); |
| | 1197 | } else if (!data.bShowDescriptions) { |
| 748 | 1198 | strEx::append_list(message, record.eventSource()); |
| 749 | 1199 | } else { |
| … |
… |
|
| 758 | 1208 | pevlr = reinterpret_cast<EVENTLOGRECORD*>((LPBYTE)pevlr + pevlr->Length); |
| 759 | 1209 | } |
| | 1210 | <<<<<<< .working |
| 760 | 1211 | } |
| | 1212 | ======= |
| | 1213 | } |
| | 1214 | >>>>>>> .merge-right.r272 |
| 761 | 1215 | DWORD err = GetLastError(); |
| 762 | 1216 | if (err == ERROR_INSUFFICIENT_BUFFER) { |
| … |
… |
|
| 776 | 1230 | } |
| 777 | 1231 | } |
| | 1232 | NSC_DEBUG_MSG_STD(_T("Evaluation time: ") + strEx::itos(time.stop())); |
| 778 | 1233 | |
| 779 | 1234 | if (!bPerfData) { |
-
|
r205
|
r273
|
|
| 52 | 52 | } |
| 53 | 53 | |
| | 54 | void parse(std::wstring expr); |
| 54 | 55 | |
| 55 | 56 | bool hasCommandHandler(); |
-
|
r257
|
r273
|
|
| 56 | 56 | } |
| 57 | 57 | } |
| | 58 | } |
| | 59 | |
| | 60 | |
| | 61 | std::wstring CheckExternalScripts::getWrapping(std::wstring val) { |
| | 62 | strEx::token tok = strEx::getToken(val, ' ', true); |
| | 63 | std::wstring::size_type pos = tok.first.find_last_of(_T(".")); |
| | 64 | if (pos == std::wstring::npos) |
| | 65 | return _T(""); |
| | 66 | return tok.first.substr(pos+1); |
| | 67 | } |
| | 68 | |
| | 69 | void CheckExternalScripts::addWrappedCommand(std::wstring key, std::wstring tpl, std::wstring command ) { |
| | 70 | strEx::token tok = strEx::getToken(command, ' ', true); |
| | 71 | strEx::replace(tpl, _T("%SCRIPT%"), tok.first); |
| | 72 | strEx::replace(tpl, _T("%ARGS%"), tok.second); |
| | 73 | tok = strEx::getToken(tpl, ' ', true); |
| | 74 | addCommand(key.c_str(),tok.first, tok.second); |
| 58 | 75 | } |
| 59 | 76 | |
| … |
… |
|
| 99 | 116 | } |
| 100 | 117 | |
| | 118 | std::map<std::wstring,std::wstring> wrappers; |
| | 119 | std::list<std::wstring> wrappings = GET_CORE()->getSettingsSection(setting_keys::external_scripts::WRAPPINGS_SECTION_PATH); |
| | 120 | for (it = wrappings.begin(); it != wrappings.end(); ++it) { |
| | 121 | std::wstring val = GET_CORE()->getSettingsString(setting_keys::external_scripts::WRAPPINGS_SECTION_PATH, *it, _T("")); |
| | 122 | if (!(*it).empty() && !val.empty()) { |
| | 123 | wrappers[(*it)] = val; |
| | 124 | } |
| | 125 | } |
| | 126 | std::list<std::wstring> wscript = GET_CORE()->getSettingsSection(setting_keys::external_scripts::WRAPPED_SCRIPT_PATH); |
| | 127 | for (it = wscript.begin(); it != wscript.end(); ++it) { |
| | 128 | std::wstring val = GET_CORE()->getSettingsString(setting_keys::external_scripts::WRAPPED_SCRIPT_PATH, *it, _T("")); |
| | 129 | if (!(*it).empty() && !val.empty()) { |
| | 130 | std::wstring type = getWrapping(val); |
| | 131 | std::map<std::wstring,std::wstring>::const_iterator cit = wrappers.find(type); |
| | 132 | if (cit == wrappers.end()) { |
| | 133 | NSC_LOG_ERROR_STD(_T("Failed to find wrappings for: ") + type + _T(" (" + (*it) + _T(")"))); |
| | 134 | } else { |
| | 135 | addWrappedCommand((*it), (*cit).second, val); |
| | 136 | } |
| | 137 | } |
| | 138 | } |
| | 139 | |
| 101 | 140 | if (!scriptDirectory_.empty()) { |
| 102 | 141 | addAllScriptsFrom(scriptDirectory_); |
-
|
r257
|
r273
|
|
| 96 | 96 | GET_CORE()->registerCommand(key, _T("Alias for: ") + cd.to_string()); |
| 97 | 97 | } |
| | 98 | std::wstring getWrapping( std::wstring val ); |
| | 99 | void addWrappedCommand( std::wstring key, std::wstring tpl, std::wstring command ); |
| 98 | 100 | }; |
| 99 | 101 | |
-
|
r260
|
r273
|
|
| 86 | 86 | GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); |
| 87 | 87 | return NSCAPI::returnOK; |
| 88 | | } else if (command == _T("checkalwayscritical")) { |
| 89 | | if (arguments.size() < 1) { |
| | 88 | } else if (command == _T("CheckOK")) { |
| | 89 | return checkSimpleStatus(NSCAPI::returnOK, argLen, char_args, msg, perf); |
| | 90 | } else if (command == _T("CheckWARNING")) { |
| | 91 | return checkSimpleStatus(NSCAPI::returnWARN, argLen, char_args, msg, perf); |
| | 92 | } else if (command == _T("CheckCRITICAL")) { |
| | 93 | return checkSimpleStatus(NSCAPI::returnCRIT, argLen, char_args, msg, perf); |
| | 94 | } else if (command == _T("CheckAlwaysCRITICAL")) { |
| | 95 | if (arguments.size() < 2) { |
| 90 | 96 | message = _T("ERROR: Missing arguments."); |
| 91 | 97 | return NSCAPI::returnUNKNOWN; |
-
|
r250
|
r273
|
|
| 30 | 30 | #include <set> |
| 31 | 31 | #include <sysinfo.h> |
| | 32 | #include <filter_framework.hpp> |
| | 33 | #include <simple_registry.hpp> |
| | 34 | |
| 32 | 35 | #ifdef USE_BOOST |
| 33 | 36 | #include <boost/regex.hpp> |
| … |
… |
|
| 77 | 80 | NSCModuleHelper::registerCommand(_T("checkCounter"), _T("Check a PDH counter.")); |
| 78 | 81 | NSCModuleHelper::registerCommand(_T("listCounterInstances"), _T("List all instances for a counter.")); |
| | 82 | NSCModuleHelper::registerCommand(_T("checkSingleRegEntry"), _T("Check registry key")); |
| | 83 | |
| | 84 | |
| 79 | 85 | } catch (NSCModuleHelper::NSCMHExcpetion &e) { |
| 80 | 86 | NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); |
| … |
… |
|
| 208 | 214 | } |
| 209 | 215 | } else { |
| | 216 | if ((*it).counters.size() == 0) { |
| | 217 | std::wcout << _T("empty counter: ") << (*it).name << std::endl; |
| | 218 | } |
| 210 | 219 | for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { |
| 211 | 220 | std::wstring counter = _T("\\") + (*it).name + _T("\\") + (*it2).name; |
| … |
… |
|
| 232 | 241 | } |
| 233 | 242 | std::wcout << _T(" open "); |
| 234 | | std::wcout << std::endl;; |
| | 243 | std::wcout << std::endl; |
| 235 | 244 | } |
| 236 | 245 | } |
| … |
… |
|
| 264 | 273 | return 0; |
| 265 | 274 | } |
| 266 | | DWORD dw = PDH::PDHQuery::lookupIndex(name); |
| | 275 | DWORD dw = PDH::PDHResolver::lookupIndex(name); |
| 267 | 276 | NSC_LOG_MESSAGE_STD(_T("--+--[ Lookup Result ]----------------------------------------")); |
| 268 | 277 | NSC_LOG_MESSAGE_STD(_T(" | Index for '") + name + _T("' is ") + strEx::itos(dw)); |
| … |
… |
|
| 341 | 350 | } else if (command == _T("listCounterInstances")) { |
| 342 | 351 | return listCounterInstances(argLen, char_args, msg, perf); |
| | 352 | } else if (command == _T("checkSingleRegEntry")) { |
| | 353 | return checkSingleRegEntry(argLen, char_args, msg, perf); |
| 343 | 354 | } |
| 344 | 355 | return NSCAPI::returnIgnored; |
| … |
… |
|
| 1164 | 1175 | } |
| 1165 | 1176 | |
| | 1177 | ////////////////////////////////////////////////////////////////////////// |
| | 1178 | ////////////////////////////////////////////////////////////////////////// |
| | 1179 | |
| | 1180 | struct regkey_info { |
| | 1181 | |
| | 1182 | std::wstring error; |
| | 1183 | |
| | 1184 | static regkey_info get(__int64 now, std::wstring path) { |
| | 1185 | return regkey_info(now, path); |
| | 1186 | } |
| | 1187 | |
| | 1188 | regkey_info() |
| | 1189 | : ullLastWriteTime(0) |
| | 1190 | , iType(0) |
| | 1191 | , ullNow(0) |
| | 1192 | , uiExists(0) |
| | 1193 | , ullChildCount(0) |
| | 1194 | {} |
| | 1195 | regkey_info(__int64 now, std::wstring path) |
| | 1196 | : path(path) |
| | 1197 | , ullLastWriteTime(0) |
| | 1198 | , iType(0) |
| | 1199 | , ullNow(now) |
| | 1200 | , uiExists(0) |
| | 1201 | , ullChildCount(0) |
| | 1202 | { |
| | 1203 | std::wstring key; |
| | 1204 | try { |
| | 1205 | std::wcout << _T("opening: ") << path << std::endl; |
| | 1206 | std::wstring::size_type pos = path.find_first_of(L'\\'); |
| | 1207 | if (pos != std::wstring::npos) { |
| | 1208 | key = path.substr(0, pos); |
| | 1209 | path = path.substr(pos+1); |
| | 1210 | std::wcout << key << _T(":") << path << std::endl; |
| | 1211 | simple_registry::registry_key rkey(simple_registry::parseHKEY(key), path); |
| | 1212 | info = rkey.get_info(); |
| | 1213 | uiExists = 1; |
| | 1214 | } else { |
| | 1215 | error = _T("Failed to parse key"); |
| | 1216 | } |
| | 1217 | } catch (simple_registry::registry_exception &e) { |
| | 1218 | try { |
| | 1219 | std::wstring::size_type pos = path.find_last_of(L'\\'); |
| | 1220 | if (pos != std::wstring::npos) { |
| | 1221 | std::wstring item = path.substr(pos+1); |
| | 1222 | path = path.substr(0, pos); |
| | 1223 | std::wcout << key << _T(":") << path << _T(".") << item << std::endl; |
| | 1224 | simple_registry::registry_key rkey(simple_registry::parseHKEY(key), path); |
| | 1225 | info = rkey.get_info(item); |
| | 1226 | uiExists = 1; |
| | 1227 | } else { |
| | 1228 | error = _T("Failed to parse key"); |
| | 1229 | } |
| | 1230 | } catch (simple_registry::registry_exception &e) { |
| | 1231 | //error = e.what(); |
| | 1232 | } |
| | 1233 | } catch (...) { |
| | 1234 | error = _T("Unknown exception"); |
| | 1235 | } |
| | 1236 | |
| | 1237 | //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize |
| | 1238 | |
| | 1239 | // TODO get key info here! |
| | 1240 | //ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime); |
| | 1241 | }; |
| | 1242 | |
| | 1243 | unsigned long long ullSize; |
| | 1244 | __int64 ullLastWriteTime; |
| | 1245 | __int64 ullNow; |
| | 1246 | std::wstring filename; |
| | 1247 | std::wstring path; |
| | 1248 | unsigned long ullChildCount; |
| | 1249 | unsigned long uiExists; |
| | 1250 | unsigned int iType; |
| | 1251 | simple_registry::registry_key::reg_info info; |
| | 1252 | |
| | 1253 | static const __int64 MSECS_TO_100NS = 10000; |
| | 1254 | |
| | 1255 | __int64 get_written() { |
| | 1256 | return (ullNow-ullLastWriteTime)/MSECS_TO_100NS; |
| | 1257 | } |
| | 1258 | std::wstring render(std::wstring syntax) { |
| | 1259 | strEx::replace(syntax, _T("%path%"), path); |
| | 1260 | strEx::replace(syntax, _T("%key%"), filename); |
| | 1261 | strEx::replace(syntax, _T("%write%"), strEx::format_filetime(ullLastWriteTime, DATE_FORMAT)); |
| | 1262 | strEx::replace(syntax, _T("%write-raw%"), strEx::itos(ullLastWriteTime)); |
| | 1263 | strEx::replace(syntax, _T("%now-raw%"), strEx::itos(ullNow)); |
| | 1264 | strEx::replace(syntax, _T("%type%"), strEx::itos_as_BKMG(iType)); |
| | 1265 | strEx::replace(syntax, _T("%child-count%"), strEx::itos(ullChildCount)); |
| | 1266 | strEx::replace(syntax, _T("%exists%"), strEx::itos(uiExists)); |
| | 1267 | strEx::replace(syntax, _T("%int%"), strEx::itos(info.iValue)); |
| | 1268 | strEx::replace(syntax, _T("%int-value%"), strEx::itos(info.iValue)); |
| | 1269 | strEx::replace(syntax, _T("%string%"), info.sValue); |
| | 1270 | strEx::replace(syntax, _T("%string-value%"), info.sValue); |
| | 1271 | return syntax; |
| | 1272 | } |
| | 1273 | }; |
| | 1274 | |
| | 1275 | |
| | 1276 | struct regkey_filter { |
| | 1277 | filters::filter_all_times written; |
| | 1278 | filters::filter_all_num_ul type; |
| | 1279 | filters::filter_all_num_ul exists; |
| | 1280 | filters::filter_all_num_ul child_count; |
| | 1281 | filters::filter_all_num_ll value_int; |
| | 1282 | filters::filter_all_strings value_string; |
| | 1283 | |
| | 1284 | inline bool hasFilter() { |
| | 1285 | return type.hasFilter() || exists.hasFilter() || written.hasFilter() || child_count.hasFilter() || value_int.hasFilter() || value_string.hasFilter(); |
| | 1286 | } |
| | 1287 | bool matchFilter(regkey_info &value) const { |
| | 1288 | if ((written.hasFilter())&&(written.matchFilter(value.get_written()))) |
| | 1289 | return true; |
| | 1290 | else if (type.hasFilter()&&type.matchFilter(value.iType)) |
| | 1291 | return true; |
| | 1292 | else if (exists.hasFilter()&&exists.matchFilter(value.uiExists)) |
| | 1293 | return true; |
| | 1294 | else if ((child_count.hasFilter())&&(child_count.matchFilter(value.ullChildCount))) |
| | 1295 | return true; |
| | 1296 | else if ((value_int.hasFilter())&&(value_int.matchFilter(value.info.iValue))) |
| | 1297 | return true; |
| | 1298 | else if ((value_string.hasFilter())&&(value_string.matchFilter(value.info.sValue))) |
| | 1299 | return true; |
| | 1300 | return false; |
| | 1301 | } |
| | 1302 | |
| | 1303 | std::wstring getValue() const { |
| | 1304 | if (written.hasFilter()) |
| | 1305 | return _T("written: ") + written.getValue(); |
| | 1306 | if (type.hasFilter()) |
| | 1307 | return _T("type: ") + type.getValue(); |
| | 1308 | if (exists.hasFilter()) |
| | 1309 | return _T("exists: ") + exists.getValue(); |
| | 1310 | if (child_count.hasFilter()) |
| | 1311 | return _T("child_count: ") + child_count.getValue(); |
| | 1312 | if (value_int.hasFilter()) |
| | 1313 | return _T("value(i): ") + value_int.getValue(); |
| | 1314 | if (value_string.hasFilter()) |
| | 1315 | return _T("value(s): ") + value_string.getValue(); |
| | 1316 | return _T("UNknown..."); |
| | 1317 | } |
| | 1318 | |
| | 1319 | }; |
| | 1320 | |
| | 1321 | |
| | 1322 | struct regkey_container : public regkey_info { |
| | 1323 | |
| | 1324 | static regkey_container get(std::wstring path, unsigned long long now) { |
| | 1325 | return regkey_container(now, path); |
| | 1326 | } |
| | 1327 | |
| | 1328 | |
| | 1329 | regkey_container(__int64 now, std::wstring path) : regkey_info(now, path) {} |
| | 1330 | |
| | 1331 | bool has_errors() { |
| | 1332 | return !error.empty(); |
| | 1333 | } |
| | 1334 | std::wstring get_error() { |
| | 1335 | return error; |
| | 1336 | } |
| | 1337 | |
| | 1338 | }; |
| | 1339 | |
| | 1340 | |
| | 1341 | class regkey_type_handler { |
| | 1342 | public: |
| | 1343 | static int parse(std::wstring s) { |
| | 1344 | return 1; |
| | 1345 | } |
| | 1346 | static std::wstring print(int value) { |
| | 1347 | return _T("unknown"); |
| | 1348 | } |
| | 1349 | static std::wstring print_unformated(int value) { |
| | 1350 | return strEx::itos(value); |
| | 1351 | } |
| | 1352 | static std::wstring key_prefix() { |
| | 1353 | return _T(""); |
| | 1354 | } |
| | 1355 | static std::wstring key_postfix() { |
| | 1356 | return _T(""); |
| | 1357 | } |
| | 1358 | static std::wstring get_perf_unit(int value) { |
| | 1359 | return _T(""); |
| | 1360 | } |
| | 1361 | static std::wstring print_perf(int value, std::wstring unit) { |
| | 1362 | return strEx::itos(value); |
| | 1363 | } |
| | 1364 | }; |
| | 1365 | class regkey_exists_handler { |
| | 1366 | public: |
| | 1367 | static int parse(std::wstring s) { |
| | 1368 | if (s == _T("true")) |
| | 1369 | return 1; |
| | 1370 | return 0; |
| | 1371 | } |
| | 1372 | static std::wstring print(int value) { |
| | 1373 | return value==1?_T("true"):_T("false"); |
| | 1374 | } |
| | 1375 | static std::wstring print_unformated(int value) { |
| | 1376 | return strEx::itos(value); |
| | 1377 | } |
| | 1378 | static std::wstring key_prefix() { |
| | 1379 | return _T(""); |
| | 1380 | } |
| | 1381 | static std::wstring key_postfix() { |
| | 1382 | return _T(""); |
| | 1383 | } |
| | 1384 | static std::wstring get_perf_unit(int value) { |
| | 1385 | return _T(""); |
| | 1386 | } |
| | 1387 | static std::wstring print_perf(int value, std::wstring unit) { |
| | 1388 | return strEx::itos(value); |
| | 1389 | } |
| | 1390 | }; |
| | 1391 | |
| | 1392 | typedef checkHolders::CheckContainer<checkHolders::ExactBounds<checkHolders::NumericBounds<int, regkey_type_handler> > > RegTypeContainer; |
| | 1393 | typedef checkHolders::CheckContainer<checkHolders::ExactBounds<checkHolders::NumericBounds<int, regkey_exists_handler> > > RegExistsContainer; |
| | 1394 | |
| | 1395 | typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULong> ExactULongContainer; |
| | 1396 | typedef checkHolders::CheckContainer<checkHolders::ExactBoundsLongLong> ExactLongLongContainer; |
| | 1397 | typedef checkHolders::CheckContainer<checkHolders::ExactBoundsTime> DateTimeContainer; |
| | 1398 | typedef checkHolders::CheckContainer<checkHolders::FilterBounds<filters::filter_all_strings> > StringContainer; |
| | 1399 | |
| | 1400 | struct check_regkey_child_count : public checkHolders::check_proxy_container<regkey_container, ExactULongContainer> { |
| | 1401 | check_regkey_child_count() { set_alias(_T("child-count")); } |
| | 1402 | unsigned long get_value(regkey_container &value) { |
| | 1403 | return value.ullChildCount; |
| | 1404 | } |
| | 1405 | }; |
| | 1406 | struct check_regkey_int_value : public checkHolders::check_proxy_container<regkey_container, ExactLongLongContainer> { |
| | 1407 | check_regkey_int_value() { set_alias(_T("value")); } |
| | 1408 | long long get_value(regkey_container &value) { |
| | 1409 | return value.info.iValue; |
| | 1410 | } |
| | 1411 | }; |
| | 1412 | struct check_regkey_string_value : public checkHolders::check_proxy_container<regkey_container, StringContainer> { |
| | 1413 | check_regkey_string_value() { set_alias(_T("value")); } |
| | 1414 | std::wstring get_value(regkey_container &value) { |
| | 1415 | return value.info.sValue; |
| | 1416 | } |
| | 1417 | }; |
| | 1418 | struct check_regkey_written : public checkHolders::check_proxy_container<regkey_container, DateTimeContainer> { |
| | 1419 | check_regkey_written() { set_alias(_T("written")); } |
| | 1420 | unsigned long long get_value(regkey_container &value) { |
| | 1421 | return value.ullLastWriteTime; |
| | 1422 | } |
| | 1423 | }; |
| | 1424 | struct check_regkey_type : public checkHolders::check_proxy_container<regkey_container, RegTypeContainer> { |
| | 1425 | check_regkey_type() { set_alias(_T("type")); } |
| | 1426 | int get_value(regkey_container &value) { |
| | 1427 | return value.iType; |
| | 1428 | } |
| | 1429 | }; |
| | 1430 | struct check_regkey_exists : public checkHolders::check_proxy_container<regkey_container, RegExistsContainer> { |
| | 1431 | check_regkey_exists() { set_alias(_T("exists")); } |
| | 1432 | int get_value(regkey_container &value) { |
| | 1433 | return value.uiExists; |
| | 1434 | } |
| | 1435 | }; |
| | 1436 | |
| | 1437 | |
| | 1438 | typedef checkHolders::check_multi_container<regkey_container> check_file_multi; |
| | 1439 | struct check_regkey_factories { |
| | 1440 | static checkHolders::check_proxy_interface<regkey_container>* type() { |
| | 1441 | return new check_regkey_type(); |
| | 1442 | } |
| | 1443 | static checkHolders::check_proxy_interface<regkey_container>* exists() { |
| | 1444 | return new check_regkey_exists(); |
| | 1445 | } |
| | 1446 | static checkHolders::check_proxy_interface<regkey_container>* child_count() { |
| | 1447 | return new check_regkey_child_count(); |
| | 1448 | } |
| | 1449 | static checkHolders::check_proxy_interface<regkey_container>* written() { |
| | 1450 | return new check_regkey_written(); |
| | 1451 | } |
| | 1452 | static checkHolders::check_proxy_interface<regkey_container>* value_string() { |
| | 1453 | return new check_regkey_string_value(); |
| | 1454 | } |
| | 1455 | static checkHolders::check_proxy_interface<regkey_container>* value_int() { |
| | 1456 | return new check_regkey_int_value(); |
| | 1457 | } |
| | 1458 | }; |
| | 1459 | |
| | 1460 | #define MAP_FACTORY_PB(value, obj) \ |
| | 1461 | else if ((p__.first == _T("check")) && (p__.second == ##value)) { checker.add_check(check_regkey_factories::obj()); } |
| | 1462 | |
| | 1463 | |
| | 1464 | NSCAPI::nagiosReturn CheckSystem::checkSingleRegEntry(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { |
| | 1465 | NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; |
| | 1466 | std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); |
| | 1467 | check_file_multi checker; |
| | 1468 | typedef std::pair<int,regkey_filter> filteritem_type; |
| | 1469 | typedef std::list<filteritem_type > filterlist_type; |
| | 1470 | if (stl_args.empty()) { |
| | 1471 | message = _T("Missing argument(s)."); |
| | 1472 | return NSCAPI::returnUNKNOWN; |
| | 1473 | } |
| | 1474 | std::list<std::wstring> files; |
| | 1475 | unsigned int truncate = 0; |
| | 1476 | std::wstring syntax = _T("%filename%"); |
| | 1477 | std::wstring alias; |
| | 1478 | bool bPerfData = true; |
| | 1479 | |
| | 1480 | try { |
| | 1481 | MAP_OPTIONS_BEGIN(stl_args) |
| | 1482 | MAP_OPTIONS_STR2INT(_T("truncate"), truncate) |
| | 1483 | MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) |
| | 1484 | MAP_OPTIONS_STR(_T("syntax"), syntax) |
| | 1485 | MAP_OPTIONS_STR(_T("alias"), alias) |
| | 1486 | MAP_OPTIONS_PUSH(_T("path"), files) |
| | 1487 | MAP_OPTIONS_SHOWALL(checker) |
| | 1488 | MAP_OPTIONS_EXACT_NUMERIC_ALL_MULTI(checker, _T("")) |
| | 1489 | MAP_FACTORY_PB(_T("type"), type) |
| | 1490 | MAP_FACTORY_PB(_T("child-count"), child_count) |
| | 1491 | MAP_FACTORY_PB(_T("written"), written) |
| | 1492 | MAP_FACTORY_PB(_T("int"), value_int) |
| | 1493 | MAP_FACTORY_PB(_T("string"), value_string) |
| | 1494 | MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) |
| | 1495 | MAP_OPTIONS_END() |
| | 1496 | } catch (filters::parse_exception e) { |
| | 1497 | message = e.getMessage(); |
| | 1498 | return NSCAPI::returnUNKNOWN; |
| | 1499 | } catch (filters::filter_exception e) { |
| | 1500 | message = e.getMessage(); |
| | 1501 | return NSCAPI::returnUNKNOWN; |
| | 1502 | } |
| | 1503 | FILETIME now; |
| | 1504 | GetSystemTimeAsFileTime(&now); |
| | 1505 | unsigned __int64 nowi64 = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); |
| | 1506 | for (std::list<std::wstring>::const_iterator pit = files.begin(); pit != files.end(); ++pit) { |
| | 1507 | regkey_container info = regkey_container::get(*pit, nowi64); |
| | 1508 | if (info.has_errors()) { |
| | 1509 | message = info.error; |
| | 1510 | return NSCAPI::returnUNKNOWN; |
| | 1511 | } |
| | 1512 | checker.alias = info.render(syntax); |
| | 1513 | checker.runCheck(info, returnCode, message, perf); |
| | 1514 | } |
| | 1515 | if ((truncate > 0) && (message.length() > (truncate-4))) { |
| | 1516 | message = message.substr(0, truncate-4) + _T("..."); |
| | 1517 | perf = _T(""); |
| | 1518 | } |
| | 1519 | if (message.empty()) |
| | 1520 | message = _T("CheckSingleRegkey ok"); |
| | 1521 | return returnCode; |
| | 1522 | } |
| 1166 | 1523 | |
| 1167 | 1524 | NSC_WRAPPERS_MAIN_DEF(gCheckSystem); |
-
|
r250
|
r273
|
|
| 82 | 82 | NSCAPI::nagiosReturn checkCounter(const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf); |
| 83 | 83 | NSCAPI::nagiosReturn listCounterInstances(const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf); |
| | 84 | NSCAPI::nagiosReturn checkSingleRegEntry(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); |
| 84 | 85 | |
| 85 | 86 | |
-
|
r257
|
r273
|
|
| 133 | 133 | return hFile; |
| 134 | 134 | } |
| | 135 | if (hFile == INVALID_HANDLE_VALUE) { |
| | 136 | hFile = ::CreateFile(file.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| | 137 | if (hFile != INVALID_HANDLE_VALUE) { |
| | 138 | WORD wBOM = 0xFEFF; |
| | 139 | ::WriteFile(hFile, &wBOM, sizeof(WORD), &numberOfBytesWritten, NULL); |
| | 140 | } |
| | 141 | return hFile; |
| | 142 | } |
| 135 | 143 | */ |
| 136 | 144 | |
-
|
r202
|
r273
|
|
| 25 | 25 | #include <filter_framework.hpp> |
| 26 | 26 | #include <error.hpp> |
| | 27 | #include <file_helpers.hpp> |
| 27 | 28 | |
| 28 | 29 | |
| … |
… |
|
| 66 | 67 | bool LUAScript::loadScript(const std::wstring file) { |
| 67 | 68 | try { |
| 68 | | script_wrapper::lua_script *script = new script_wrapper::lua_script(file); |
| | 69 | std::wstring file_ = file; |
| | 70 | |
| | 71 | if (!file_helpers::checks::exists(file_)) { |
| | 72 | file_ = NSCModuleHelper::getBasePath() + file; |
| | 73 | if (!file_helpers::checks::exists(file_)) { |
| | 74 | NSC_LOG_ERROR(_T("Script not found: ") + file + _T(" (") + file_ + _T(")")); |
| | 75 | return false; |
| | 76 | } |
| | 77 | } |
| | 78 | NSC_DEBUG_MSG_STD(_T("Loading script: ") + file + _T(" (") + file_ + _T(")")); |
| | 79 | script_wrapper::lua_script *script = new script_wrapper::lua_script(file_); |
| 69 | 80 | script->pre_load(this); |
| 70 | 81 | scripts_.push_back(script); |
-
|
r257
|
r273
|
|
| 110 | 110 | std::wstring getModuleDescription() { |
| 111 | 111 | return _T("A simple client for checking remote NRPE servers (think proxy).\n") |
| | 112 | #ifndef USE_BOOST |
| | 113 | _T("BOOST support is missing (this is probably very bad)!\n") |
| | 114 | #endif |
| 112 | 115 | #ifndef USE_SSL |
| 113 | 116 | _T("SSL support is missing (so you cant use encryption)!") |
-
|
r258
|
r273
|
|
| 73 | 73 | NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); |
| 74 | 74 | |
| 75 | | |
| 76 | 75 | }; |
-
|
r254
|
r273
|
|
| 66 | 66 | |
| 67 | 67 | NSCAThread::NSCAThread() : hStopEvent_(NULL) { |
| | 68 | std::wstring tmpstr = NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_TIME_DELTA, NSCA_TIME_DELTA_DEFAULT); |
| 68 | 69 | std::wstring tmpstr = SETTINGS_GET_STRING(nsca::TIME_DELTA_DEFAULT); |
| 69 | 70 | if (tmpstr[0] == '-' && tmpstr.size() > 2) |
| … |
… |
|
| 75 | 76 | timeDelta_ = timeDelta_ / 1000; |
| 76 | 77 | NSC_DEBUG_MSG_STD(_T("Time difference for NSCA server is: ") + strEx::itos(timeDelta_)); |
| 77 | | checkIntervall_ = SETTINGS_GET_INT(nsca::INTERVAL); |
| 78 | | hostname_ = SETTINGS_GET_STRING(nsca::HOSTNAME); |
| 79 | | nscahost_ = SETTINGS_GET_STRING(nsca::SERVER_HOST); |
| 80 | | nscaport_ = SETTINGS_GET_INT(nsca::SERVER_PORT); |
| 81 | | payload_length_ = SETTINGS_GET_INT(nsca::PAYLOAD_LENGTH); |
| 82 | | read_timeout_ = SETTINGS_GET_INT(nsca::READ_TIMEOUT); |
| 83 | | std::wstring report = SETTINGS_GET_STRING(nsca::REPORT_MODE); |
| 84 | 78 | report_ = parse_report_string(report); |
| 85 | 79 | NSC_DEBUG_MSG_STD(_T("Only reporting: ") + generate_report_string(report_)); |
| 86 | 80 | |
| | 81 | encryption_method_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_ENCRYPTION, NSCA_ENCRYPTION_DEFAULT); |
| | 82 | std::wstring password = NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, MAIN_OBFUSCATED_PASWD, MAIN_OBFUSCATED_PASWD_DEFAULT); |
| | 83 | if (!password.empty()) |
| | 84 | password = NSCModuleHelper::Decrypt(password); |
| | 85 | if (password.empty()) |
| | 86 | password = NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_PASSWORD, NSCA_PASSWORD_DEFAULT); |
| | 87 | if (password.empty()) { |
| | 88 | // read main password if no NSCA one is found |
| | 89 | password = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_OBFUSCATED_PASWD, MAIN_OBFUSCATED_PASWD_DEFAULT); |
| | 90 | if (!password.empty()) |
| | 91 | password = NSCModuleHelper::Decrypt(password); |
| | 92 | if (password.empty()) |
| | 93 | password = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_SETTINGS_PWD, MAIN_SETTINGS_PWD_DEFAULT); |
| | 94 | } |
| | 95 | password_ = strEx::wstring_to_string(password); |
| 87 | 96 | encryption_method_ = SETTINGS_GET_INT(nsca::ENCRYPTION); |
| 88 | 97 | password_ = strEx::wstring_to_string(SETTINGS_GET_STRING(nsca::PASSWORD)); |
Download in other formats:
|
|