Changeset d1029bd in nscp


Ignore:
Timestamp:
04/22/10 16:17:46 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
9661f81
Parents:
edf0848
Message:

2010-04-21 MickeM - 0.3.8 RC1

+ Added support for strings and int (values) to CheckSingleRegEntry?

Use like so (int):

CheckSingleRegEntry? path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet?\services\eventlog\Application\MaxSize? "syntax=%path%: %int%" warn==20971520 crit==20971520 check=int ShowAll=long
CheckSingleRegEntry? path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet?\services\eventlog\Application\MaxSize? "syntax=%path%: %int%" warn==30971520 crit==30971520 check=int ShowAll=long

Use like so (string):

CheckSingleRegEntry? path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet?\services\eventlog\Application\MaxSize? "syntax=%path%: %string%" warn==20971520 crit==20971520 check=string ShowAll=long
CheckSingleRegEntry? path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet?\services\eventlog\Application\MaxSize? "syntax=%path%: %string%" warn==30971520 crit==30971520 check=string ShowAll=long

This can ofcourse be combined and all valid operators (like regexp, substr, lt, gt, ne etc etc are supported.


2010-04-16 MickeM

+ Added new Check to CheckSystem: CheckSingleRegEntry?

Similar to the previous CheckSIngleFile but can be used to check aspects of registry entries.

CheckSingleRegEntry? path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet?\services\eventlog\Application\MaxSize? "syntax=%path%: %exists%" warn==true crit==true check=exists ShowAll=long

CheckSingleRegEntry? path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet?\services\eventlog\Application\MaxSizeYY "syntax=%path%: %exists%" warn==true crit==true check=exists ShowAll=long

Currently only supports checking existanse of keys but more checks will be added soon.

Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    redf0848 rd1029bd  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,8,41 
    6 #define PRODUCTVER     0,3,8,41 
    7 #define STRFILEVER     _T("0.3.8.41") 
    8 #define STRPRODUCTVER  _T("0.3.8.41") 
    9 #define STRPRODUCTDATE  _T("2010-04-13") 
     5#define FILEVER        0,3,8,46 
     6#define PRODUCTVER     0,3,8,46 
     7#define STRFILEVER     _T("0.3.8.46") 
     8#define STRPRODUCTVER  _T("0.3.8.46") 
     9#define STRPRODUCTDATE  _T("2010-04-21") 
    1010#endif // AUTOBUILD_H 
  • changelog

    redf0848 rd1029bd  
    77 * Fix RtlStringFromGUID problem on NT4 
    88 
    9 2010-04-09 MickeM 
     92010-04-21 MickeM - 0.3.8 RC1 
     10 + Added support for strings and int (values) to CheckSingleRegEntry 
     11   Use like so (int): 
     12    CheckSingleRegEntry path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize "syntax=%path%: %int%"  warn==20971520 crit==20971520 check=int ShowAll=long 
     13    CheckSingleRegEntry path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize "syntax=%path%: %int%"  warn==30971520 crit==30971520 check=int ShowAll=long 
     14   Use like so (string): 
     15    CheckSingleRegEntry path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize "syntax=%path%: %string%"  warn==20971520 crit==20971520 check=string ShowAll=long 
     16    CheckSingleRegEntry path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize "syntax=%path%: %string%"  warn==30971520 crit==30971520 check=string ShowAll=long 
     17   This can ofcourse be combined and all valid operators (like regexp, substr, lt, gt, ne etc etc are supported. 
     18    
     192010-04-16 MickeM 
     20 + Added new Check to CheckSystem: CheckSingleRegEntry 
     21   Similar to the previous CheckSIngleFile but can be used to check aspects of registry entries. 
     22     CheckSingleRegEntry path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize "syntax=%path%: %exists%"  warn==true crit==true check=exists ShowAll=long 
     23   CheckSingleRegEntry path=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSizeYY "syntax=%path%: %exists%"  warn==true crit==true check=exists ShowAll=long 
     24   Currently only supports checking existanse of keys but more checks will be added soon. 
     25 
     262010-04-14 MickeM 
     27 ! Fixed erroneous error message "Failed to peek buffer" 
     28  
     292010-04-13 MickeM 
    1030 + Added support for dates in the new CheckEventLog so the following are equvivalent: 
    11     CheckEventLog debug=true file=application file=system MaxWarn=1 MaxCrit=1 "filter=generated lt -2d AND severity = 'error'" truncate=800 unique descriptions "syntax=%severity%: %source%: %strings% (%count%)" 
     31    CheckEventLog debug=true file=application file=system MaxWarn=1 MaxCrit=1 "filter=generated gt -2d AND severity = 'error'" truncate=800 unique descriptions "syntax=%severity%: %source%: %strings% (%count%)" 
    1232    CheckEventLog debug=true file=application file=system filter=new filter=in MaxWarn=1 MaxCrit=1 filter+generated=gt:2d filter+severity==error truncate=800 unique descriptions "syntax=%severity%: %source%: %strings% (%count%)" debug-threshold=100 
    1333 
  • include/checkHelpers.hpp

    r5b10435 rd1029bd  
    177177    virtual void set_warn_bound(std::wstring value) = 0; 
    178178    virtual void set_crit_bound(std::wstring value) = 0; 
     179    virtual void set_showall(showType show_) = 0; 
     180 
    179181    //virtual std::wstring get_default_alias() = 0; 
    180182 
     
    215217      return impl_.showAll(); 
    216218    } 
     219    void set_showall(showType show_) { 
     220      impl_.show = show_; 
     221    } 
    217222    std::wstring gatherPerfData(container_value_type &value) { 
    218223      typename impl_type::TPayloadValueType real_value = get_value(value); 
     
    309314    void runCheck(value_type &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 
    310315      for (check_list_type::const_iterator cit=checks_.begin(); cit != checks_.end(); ++cit) { 
     316        (*cit)->set_showall(show); 
    311317        (*cit)->runCheck(value, returnCode, message, perf); 
    312318      } 
     
    871877 
    872878  }; 
     879 
     880  template <class TFilterType> 
     881  class FilterBounds { 
     882  public: 
     883    TFilterType filter; 
     884    typedef typename TFilterType::TValueType TValueType; 
     885    typedef FilterBounds<TFilterType> TMyType; 
     886 
     887    FilterBounds() {} 
     888    FilterBounds(const FilterBounds &other) { 
     889      filter = other.filter; 
     890    } 
     891    bool hasBounds() { 
     892      return filter.hasFilter(); 
     893    } 
     894 
     895    static std::wstring toStringLong(typename TValueType &value) { 
     896      //return filter.to_string() + _T(" matches ") + value; 
     897      // TODO FIx this; 
     898      return value; 
     899      //return TNumericHolder::toStringLong(value.count) + _T(", ") + TStateHolder::toStringLong(value.state); 
     900    } 
     901    static std::wstring toStringShort(typename TValueType &value) { 
     902      // TODO FIx this; 
     903      return value; 
     904      //return TNumericHolder::toStringShort(value.count); 
     905    } 
     906    std::wstring gatherPerfData(std::wstring alias, typename TValueType &value, TMyType &warn, TMyType &crit) { 
     907      return _T(""); 
     908    } 
     909    bool check(typename TValueType &value, std::wstring lable, std::wstring &message, ResultType type) { 
     910      if (filter.hasFilter()) { 
     911        if (!filter.matchFilter(value)) 
     912          return false; 
     913        message = lable + _T(": ") + filter.to_string() + _T(" matches ") + value; 
     914        return true; 
     915      } else { 
     916        NSC_LOG_MESSAGE_STD(_T("Missing bounds for filter check: ") + lable); 
     917      } 
     918      return false; 
     919    } 
     920    const TMyType & operator=(std::wstring value) { 
     921      filter = value; 
     922      return *this; 
     923    } 
     924 
     925  }; 
     926 
    873927 
    874928  template <class TStateHolder = StateBounds<state_type, state_handler> > 
     
    10641118  typedef ExactBounds<NumericBounds<unsigned int, int_handler> > ExactBoundsUInteger; 
    10651119  typedef ExactBounds<NumericBounds<unsigned long, int_handler> > ExactBoundsULong; 
     1120  typedef ExactBounds<NumericBounds<long long, int_handler> > ExactBoundsLongLong; 
    10661121  typedef ExactBounds<NumericBounds<time_type, time_handler<__int64> > > ExactBoundsTime; 
    10671122 
  • include/execute_process.hpp

    r3692371 rd1029bd  
    111111 
    112112      dwAvail = 0; 
    113       if (!::PeekNamedPipe(hChildOutR, NULL, 0, NULL, &dwAvail, NULL)) 
    114         NSC_LOG_ERROR_STD(_T("Failed to peek buffer: ") + error::lookup::last_error()); 
    115       if (dwAvail > 0) 
     113      if ((::PeekNamedPipe(hChildOutR, NULL, 0, NULL, &dwAvail, NULL)) && (dwAvail > 0)) 
    116114        str += readFromFile(buffer, hChildOutR); 
    117115      msg = strEx::string_to_wstring(str); 
  • include/filter_framework.hpp

    r9bb220f rd1029bd  
    241241    not_string_filter not; 
    242242    std::wstring value_; 
     243    typedef std::wstring TValueType; 
    243244#ifdef USE_BOOST 
    244245    regexp_string_filter regexp; 
     
    386387  typedef filter_all_numeric<__int64, checkHolders::time_handler<__int64> > filter_all_times; 
    387388  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; 
    388390 
    389391  template <typename TFilterType, typename TValueType> 
  • include/strEx.h

    r5b10435 rd1029bd  
    206206  static const __int64 SECS_TO_100NS = 10000000; 
    207207  inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
     208    if (filetime == 0) 
     209      return _T("ZERO"); 
    208210    filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); 
    209211    filetime /= SECS_TO_100NS; 
  • modules/CheckSystem/CheckSystem-2005.vcproj

    r42ff14d rd1029bd  
    24722472      </File> 
    24732473      <File 
     2474        RelativePath="..\..\include\simple_registry.hpp" 
     2475        > 
     2476      </File> 
     2477      <File 
    24742478        RelativePath=".\stdafx.h" 
    24752479        > 
  • modules/CheckSystem/CheckSystem.cpp

    r42ff14d rd1029bd  
    3030#include <set> 
    3131#include <sysinfo.h> 
     32#include <filter_framework.hpp> 
     33#include <simple_registry.hpp> 
     34 
    3235#ifdef USE_BOOST 
    3336#include <boost/regex.hpp> 
     
    7477    NSCModuleHelper::registerCommand(_T("checkCounter"), _T("Check a PDH counter.")); 
    7578    NSCModuleHelper::registerCommand(_T("listCounterInstances"), _T("List all instances for a counter.")); 
     79    NSCModuleHelper::registerCommand(_T("checkSingleRegEntry"), _T("Check registry key")); 
     80     
    7681     
    7782  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     
    339344  } else if (command == _T("listCounterInstances")) { 
    340345    return listCounterInstances(argLen, char_args, msg, perf); 
     346  } else if (command == _T("checkSingleRegEntry")) { 
     347    return checkSingleRegEntry(argLen, char_args, msg, perf); 
    341348  } 
    342349  return NSCAPI::returnIgnored; 
     
    11621169} 
    11631170 
     1171////////////////////////////////////////////////////////////////////////// 
     1172////////////////////////////////////////////////////////////////////////// 
     1173 
     1174struct regkey_info { 
     1175 
     1176  std::wstring error; 
     1177 
     1178  static regkey_info get(__int64 now, std::wstring path) { 
     1179    return regkey_info(now, path); 
     1180  } 
     1181 
     1182  regkey_info()  
     1183    : ullLastWriteTime(0) 
     1184    , iType(0) 
     1185    , ullNow(0) 
     1186    , uiExists(0) 
     1187    , ullChildCount(0) 
     1188  {} 
     1189  regkey_info(__int64 now, std::wstring path)  
     1190    : path(path) 
     1191    , ullLastWriteTime(0) 
     1192    , iType(0) 
     1193    , ullNow(now) 
     1194    , uiExists(0) 
     1195    , ullChildCount(0) 
     1196  { 
     1197    std::wstring key; 
     1198    try { 
     1199      std::wcout << _T("opening: ") << path << std::endl; 
     1200      std::wstring::size_type pos = path.find_first_of(L'\\'); 
     1201      if (pos != std::wstring::npos)  { 
     1202        key = path.substr(0, pos); 
     1203        path = path.substr(pos+1); 
     1204        std::wcout << key << _T(":") << path << std::endl; 
     1205        simple_registry::registry_key rkey(simple_registry::parseHKEY(key), path); 
     1206        info = rkey.get_info(); 
     1207        uiExists = 1; 
     1208      } else { 
     1209        error = _T("Failed to parse key"); 
     1210      } 
     1211    } catch (simple_registry::registry_exception &e) { 
     1212      try { 
     1213        std::wstring::size_type pos = path.find_last_of(L'\\'); 
     1214        if (pos != std::wstring::npos)  { 
     1215          std::wstring item = path.substr(pos+1); 
     1216          path = path.substr(0, pos); 
     1217          std::wcout << key << _T(":") << path << _T(".") << item << std::endl; 
     1218          simple_registry::registry_key rkey(simple_registry::parseHKEY(key), path); 
     1219          info = rkey.get_info(item); 
     1220          uiExists = 1; 
     1221        } else { 
     1222          error = _T("Failed to parse key"); 
     1223        } 
     1224      } catch (simple_registry::registry_exception &e) { 
     1225        //error = e.what(); 
     1226      } 
     1227    } catch (...) { 
     1228      error = _T("Unknown exception"); 
     1229    } 
     1230 
     1231    //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MaxSize 
     1232 
     1233    // TODO get key info here! 
     1234    //ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime); 
     1235  }; 
     1236 
     1237  unsigned long long ullSize; 
     1238  __int64 ullLastWriteTime; 
     1239  __int64 ullNow; 
     1240  std::wstring filename; 
     1241  std::wstring path; 
     1242  unsigned long ullChildCount; 
     1243  unsigned long uiExists; 
     1244  unsigned int iType; 
     1245  simple_registry::registry_key::reg_info info; 
     1246 
     1247  static const __int64 MSECS_TO_100NS = 10000; 
     1248 
     1249  __int64 get_written() { 
     1250    return (ullNow-ullLastWriteTime)/MSECS_TO_100NS; 
     1251  } 
     1252  std::wstring render(std::wstring syntax) { 
     1253    strEx::replace(syntax, _T("%path%"), path); 
     1254    strEx::replace(syntax, _T("%key%"), filename); 
     1255    strEx::replace(syntax, _T("%write%"), strEx::format_filetime(ullLastWriteTime, DATE_FORMAT)); 
     1256    strEx::replace(syntax, _T("%write-raw%"), strEx::itos(ullLastWriteTime)); 
     1257    strEx::replace(syntax, _T("%now-raw%"), strEx::itos(ullNow)); 
     1258    strEx::replace(syntax, _T("%type%"), strEx::itos_as_BKMG(iType)); 
     1259    strEx::replace(syntax, _T("%child-count%"), strEx::itos(ullChildCount)); 
     1260    strEx::replace(syntax, _T("%exists%"), strEx::itos(uiExists)); 
     1261    strEx::replace(syntax, _T("%int%"), strEx::itos(info.iValue)); 
     1262    strEx::replace(syntax, _T("%int-value%"), strEx::itos(info.iValue)); 
     1263    strEx::replace(syntax, _T("%string%"), info.sValue); 
     1264    strEx::replace(syntax, _T("%string-value%"), info.sValue); 
     1265    return syntax; 
     1266  } 
     1267}; 
     1268 
     1269 
     1270struct regkey_filter { 
     1271  filters::filter_all_times written; 
     1272  filters::filter_all_num_ul type; 
     1273  filters::filter_all_num_ul exists; 
     1274  filters::filter_all_num_ul child_count; 
     1275  filters::filter_all_num_ll value_int; 
     1276  filters::filter_all_strings value_string; 
     1277 
     1278  inline bool hasFilter() { 
     1279    return type.hasFilter() || exists.hasFilter() || written.hasFilter() || child_count.hasFilter() || value_int.hasFilter() || value_string.hasFilter(); 
     1280  } 
     1281  bool matchFilter(regkey_info &value) const { 
     1282    if ((written.hasFilter())&&(written.matchFilter(value.get_written()))) 
     1283      return true; 
     1284    else if (type.hasFilter()&&type.matchFilter(value.iType)) 
     1285      return true; 
     1286    else if (exists.hasFilter()&&exists.matchFilter(value.uiExists)) 
     1287      return true; 
     1288    else if ((child_count.hasFilter())&&(child_count.matchFilter(value.ullChildCount))) 
     1289      return true; 
     1290    else if ((value_int.hasFilter())&&(value_int.matchFilter(value.info.iValue))) 
     1291      return true; 
     1292    else if ((value_string.hasFilter())&&(value_string.matchFilter(value.info.sValue))) 
     1293      return true; 
     1294    return false; 
     1295  } 
     1296 
     1297  std::wstring getValue() const { 
     1298    if (written.hasFilter()) 
     1299      return _T("written: ") + written.getValue(); 
     1300    if (type.hasFilter()) 
     1301      return _T("type: ") + type.getValue(); 
     1302    if (exists.hasFilter()) 
     1303      return _T("exists: ") + exists.getValue(); 
     1304    if (child_count.hasFilter()) 
     1305      return _T("child_count: ") + child_count.getValue(); 
     1306    if (value_int.hasFilter()) 
     1307      return _T("value(i): ") + value_int.getValue(); 
     1308    if (value_string.hasFilter()) 
     1309      return _T("value(s): ") + value_string.getValue(); 
     1310    return _T("UNknown..."); 
     1311  } 
     1312 
     1313}; 
     1314 
     1315 
     1316struct regkey_container : public regkey_info { 
     1317 
     1318  static regkey_container get(std::wstring path, unsigned long long now) { 
     1319    return regkey_container(now, path); 
     1320  } 
     1321 
     1322 
     1323  regkey_container(__int64 now, std::wstring path) : regkey_info(now, path) {} 
     1324 
     1325  bool has_errors() { 
     1326    return !error.empty(); 
     1327  } 
     1328  std::wstring get_error() { 
     1329    return error; 
     1330  } 
     1331 
     1332}; 
     1333 
     1334 
     1335class regkey_type_handler { 
     1336public: 
     1337  static int parse(std::wstring s) { 
     1338    return 1; 
     1339  } 
     1340  static std::wstring print(int value) { 
     1341    return _T("unknown"); 
     1342  } 
     1343  static std::wstring print_unformated(int value) { 
     1344    return strEx::itos(value); 
     1345  } 
     1346  static std::wstring key_prefix() { 
     1347    return _T(""); 
     1348  } 
     1349  static std::wstring key_postfix() { 
     1350    return _T(""); 
     1351  } 
     1352  static std::wstring get_perf_unit(int  value) { 
     1353    return _T(""); 
     1354  } 
     1355  static std::wstring print_perf(int  value, std::wstring unit) { 
     1356    return strEx::itos(value); 
     1357  } 
     1358}; 
     1359class regkey_exists_handler { 
     1360public: 
     1361  static int parse(std::wstring s) { 
     1362    if (s  == _T("true")) 
     1363      return 1; 
     1364    return 0; 
     1365  } 
     1366  static std::wstring print(int value) { 
     1367    return value==1?_T("true"):_T("false"); 
     1368  } 
     1369  static std::wstring print_unformated(int value) { 
     1370    return strEx::itos(value); 
     1371  } 
     1372  static std::wstring key_prefix() { 
     1373    return _T(""); 
     1374  } 
     1375  static std::wstring key_postfix() { 
     1376    return _T(""); 
     1377  } 
     1378  static std::wstring get_perf_unit(int value) { 
     1379    return _T(""); 
     1380  } 
     1381  static std::wstring print_perf(int  value, std::wstring unit) { 
     1382    return strEx::itos(value); 
     1383  } 
     1384}; 
     1385 
     1386typedef checkHolders::CheckContainer<checkHolders::ExactBounds<checkHolders::NumericBounds<int, regkey_type_handler> > > RegTypeContainer; 
     1387typedef checkHolders::CheckContainer<checkHolders::ExactBounds<checkHolders::NumericBounds<int, regkey_exists_handler> > > RegExistsContainer; 
     1388 
     1389typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULong> ExactULongContainer; 
     1390typedef checkHolders::CheckContainer<checkHolders::ExactBoundsLongLong> ExactLongLongContainer; 
     1391typedef checkHolders::CheckContainer<checkHolders::ExactBoundsTime> DateTimeContainer; 
     1392typedef checkHolders::CheckContainer<checkHolders::FilterBounds<filters::filter_all_strings> > StringContainer; 
     1393 
     1394struct check_regkey_child_count : public checkHolders::check_proxy_container<regkey_container, ExactULongContainer> { 
     1395  check_regkey_child_count() { set_alias(_T("child-count")); } 
     1396  unsigned long get_value(regkey_container &value) { 
     1397    return value.ullChildCount; 
     1398  } 
     1399}; 
     1400struct check_regkey_int_value : public checkHolders::check_proxy_container<regkey_container, ExactLongLongContainer> { 
     1401  check_regkey_int_value() { set_alias(_T("value")); } 
     1402  long long get_value(regkey_container &value) { 
     1403    return value.info.iValue; 
     1404  } 
     1405}; 
     1406struct check_regkey_string_value : public checkHolders::check_proxy_container<regkey_container, StringContainer> { 
     1407  check_regkey_string_value() { set_alias(_T("value")); } 
     1408  std::wstring get_value(regkey_container &value) { 
     1409    return value.info.sValue; 
     1410  } 
     1411}; 
     1412struct check_regkey_written : public checkHolders::check_proxy_container<regkey_container, DateTimeContainer> { 
     1413  check_regkey_written() { set_alias(_T("written")); } 
     1414  unsigned long long get_value(regkey_container &value) { 
     1415    return value.ullLastWriteTime; 
     1416  } 
     1417}; 
     1418struct check_regkey_type : public checkHolders::check_proxy_container<regkey_container, RegTypeContainer> { 
     1419  check_regkey_type() { set_alias(_T("type")); } 
     1420  int get_value(regkey_container &value) { 
     1421    return value.iType; 
     1422  } 
     1423}; 
     1424struct check_regkey_exists : public checkHolders::check_proxy_container<regkey_container, RegExistsContainer> { 
     1425  check_regkey_exists() { set_alias(_T("exists")); } 
     1426  int get_value(regkey_container &value) { 
     1427    return value.uiExists; 
     1428  } 
     1429}; 
     1430 
     1431 
     1432typedef checkHolders::check_multi_container<regkey_container> check_file_multi; 
     1433struct check_regkey_factories { 
     1434  static checkHolders::check_proxy_interface<regkey_container>* type() { 
     1435    return new check_regkey_type(); 
     1436  } 
     1437  static checkHolders::check_proxy_interface<regkey_container>* exists() { 
     1438    return new check_regkey_exists(); 
     1439  } 
     1440  static checkHolders::check_proxy_interface<regkey_container>* child_count() { 
     1441    return new check_regkey_child_count(); 
     1442  } 
     1443  static checkHolders::check_proxy_interface<regkey_container>* written() { 
     1444    return new check_regkey_written(); 
     1445  } 
     1446  static checkHolders::check_proxy_interface<regkey_container>* value_string() { 
     1447    return new check_regkey_string_value(); 
     1448  } 
     1449  static checkHolders::check_proxy_interface<regkey_container>* value_int() { 
     1450    return new check_regkey_int_value(); 
     1451  } 
     1452}; 
     1453 
     1454#define MAP_FACTORY_PB(value, obj) \ 
     1455    else if ((p__.first == _T("check")) && (p__.second == ##value)) { checker.add_check(check_regkey_factories::obj()); } 
     1456 
     1457 
     1458NSCAPI::nagiosReturn CheckSystem::checkSingleRegEntry(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     1459  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
     1460  std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
     1461  check_file_multi checker; 
     1462  typedef std::pair<int,regkey_filter> filteritem_type; 
     1463  typedef std::list<filteritem_type > filterlist_type; 
     1464  if (stl_args.empty()) { 
     1465    message = _T("Missing argument(s)."); 
     1466    return NSCAPI::returnUNKNOWN; 
     1467  } 
     1468  std::list<std::wstring> files; 
     1469  unsigned int truncate = 0; 
     1470  std::wstring syntax = _T("%filename%"); 
     1471  std::wstring alias; 
     1472  bool bPerfData = true; 
     1473 
     1474  try { 
     1475    MAP_OPTIONS_BEGIN(stl_args) 
     1476      MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
     1477      MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 
     1478      MAP_OPTIONS_STR(_T("syntax"), syntax) 
     1479      MAP_OPTIONS_STR(_T("alias"), alias) 
     1480      MAP_OPTIONS_PUSH(_T("path"), files) 
     1481      MAP_OPTIONS_SHOWALL(checker) 
     1482      MAP_OPTIONS_EXACT_NUMERIC_ALL_MULTI(checker, _T("")) 
     1483      MAP_FACTORY_PB(_T("type"), type) 
     1484      MAP_FACTORY_PB(_T("child-count"), child_count) 
     1485      MAP_FACTORY_PB(_T("written"), written) 
     1486      MAP_FACTORY_PB(_T("int"), value_int) 
     1487      MAP_FACTORY_PB(_T("string"), value_string) 
     1488      MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) 
     1489      MAP_OPTIONS_END() 
     1490  } catch (filters::parse_exception e) { 
     1491    message = e.getMessage(); 
     1492    return NSCAPI::returnUNKNOWN; 
     1493  } catch (filters::filter_exception e) { 
     1494    message = e.getMessage(); 
     1495    return NSCAPI::returnUNKNOWN; 
     1496  } 
     1497  FILETIME now; 
     1498  GetSystemTimeAsFileTime(&now); 
     1499  unsigned __int64 nowi64 = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 
     1500  for (std::list<std::wstring>::const_iterator pit = files.begin(); pit != files.end(); ++pit) { 
     1501    regkey_container info = regkey_container::get(*pit, nowi64); 
     1502    if (info.has_errors()) { 
     1503      message = info.error; 
     1504      return NSCAPI::returnUNKNOWN; 
     1505    } 
     1506    checker.alias = info.render(syntax); 
     1507    checker.runCheck(info, returnCode, message, perf); 
     1508  } 
     1509  if ((truncate > 0) && (message.length() > (truncate-4))) { 
     1510    message = message.substr(0, truncate-4) + _T("..."); 
     1511    perf = _T(""); 
     1512  } 
     1513  if (message.empty()) 
     1514    message = _T("CheckSingleRegkey ok"); 
     1515  return returnCode; 
     1516} 
    11641517 
    11651518NSC_WRAPPERS_MAIN_DEF(gCheckSystem); 
  • modules/CheckSystem/CheckSystem.h

    r42ff14d rd1029bd  
    8282  NSCAPI::nagiosReturn checkCounter(const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf); 
    8383  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); 
    8485 
    8586 
Note: See TracChangeset for help on using the changeset viewer.