Changeset 04f2743 in nscp


Ignore:
Timestamp:
01/25/09 14:30:22 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
1d53fe0
Parents:
3692371
Message:

2009-01-25 MickeM

  • Fixed issue with checkVersion ( #242 )
  • Fixed spelling error ( #244 )
  • Fixed crash in CheckFile when a file was locked in exclusive mode ( #254 ) + Improved error handling in all CheckDIsk/CheckFile checks. Should report errors better now.
  • Updated the config file a bit: remving "beta" from a bunch of modules no longer in beta. ( #270 ) + Added more filter operatos to all numeric filters so they accept eq:, ne:, gt:, lt: in addition to =, >, <, <>, !, !=, in: ( #269 )
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    r3692371 r04f2743  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,6,168 
    6 #define PRODUCTVER     0,3,6,168 
    7 #define STRFILEVER     _T("0.3.6.168") 
    8 #define STRPRODUCTVER  _T("0.3.6.168") 
    9 #define STRPRODUCTDATE  _T("2009-01-20") 
     5#define FILEVER        0,3,6,249 
     6#define PRODUCTVER     0,3,6,249 
     7#define STRFILEVER     _T("0.3.6.249") 
     8#define STRPRODUCTVER  _T("0.3.6.249") 
     9#define STRPRODUCTDATE  _T("2009-01-25") 
    1010#endif // AUTOBUILD_H 
  • NSC.dist

    rbb8b6d1 r04f2743  
    1818;CheckWMI.dll 
    1919; 
     20; Script to check external scripts and/or internal aliases. 
     21;CheckExternalScripts.dll 
     22; 
     23; NSCA Agent if you enable this NSClient++ will talk to NSCA hosts repeatedly (so dont enable unless you want to use NSCA) 
     24;NSCAAgent.dll 
     25; 
     26; LUA script module used to write your own "check deamon". 
     27;LUAScript.dll 
     28; 
    2029; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! 
    2130;RemoteConfiguration.dll 
    22 ; NSCA Agent is a new beta module use with care! 
    23 ;NSCAAgent.dll 
    24 ; LUA script module used to write your own "check deamon" (sort of) early beta. 
    25 ;LUAScript.dll 
    26 ; Script to check external scripts and/or internal aliases, early beta. 
    27 ;CheckExternalScripts.dll 
    2831; Check other hosts through NRPE extreme beta and probably a bit dangerous! :) 
    2932;NRPEClient.dll 
  • NSClient++-2005.sln

    r3692371 r04f2743  
    55    Debug.AspNetCompiler.Debug = "True" 
    66    Release.AspNetCompiler.Debug = "False" 
     7  EndProjectSection 
     8  ProjectSection(ProjectDependencies) = postProject 
     9    {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B} 
     10    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 
     11    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} 
     12    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} 
     13    {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} = {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} 
     14    {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A} = {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A} 
     15    {6F55C9BF-57F6-4A15-A058-C83A52F539EE} = {6F55C9BF-57F6-4A15-A058-C83A52F539EE} 
     16    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} = {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} 
     17    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} 
     18    {26B84883-BE52-40E6-9BEE-55AD056D5751} = {26B84883-BE52-40E6-9BEE-55AD056D5751} 
     19    {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {F3401E75-60FB-4A0E-A18C-6505587D5B1A} 
     20    {53FB9872-5E74-4E62-892D-AD82C2ED67CE} = {53FB9872-5E74-4E62-892D-AD82C2ED67CE} 
     21    {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8} 
     22    {BBFF8362-C626-4838-B0A2-F695D638AD24} = {BBFF8362-C626-4838-B0A2-F695D638AD24} 
     23    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} = {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} 
     24    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} = {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} 
     25    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} = {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} 
     26    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} = {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} 
    727  EndProjectSection 
    828EndProject 
     
    11701190    {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|Mixed Platforms.Build.0 = Debug 
    11711191    {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|Win32.ActiveCfg = Debug 
    1172     {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|Win32.Build.0 = Debug 
    11731192    {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|x64.ActiveCfg = Debug 
    11741193    {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|x64.Build.0 = Debug 
     
    12251244    {6206F046-3D36-4258-BB03-3291A7070117}.Debug|Mixed Platforms.Build.0 = Debug|Win32 
    12261245    {6206F046-3D36-4258-BB03-3291A7070117}.Debug|Win32.ActiveCfg = Debug|Win32 
    1227     {6206F046-3D36-4258-BB03-3291A7070117}.Debug|Win32.Build.0 = Debug|Win32 
    12281246    {6206F046-3D36-4258-BB03-3291A7070117}.Debug|x64.ActiveCfg = Debug|Win32 
    12291247    {6206F046-3D36-4258-BB03-3291A7070117}.Debug-MemCheck|Any CPU.ActiveCfg = Debug|Win32 
     
    12661284    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    12671285    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Win32.ActiveCfg = Debug|Win32 
    1268     {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Win32.Build.0 = Debug|Win32 
    12691286    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|x64.ActiveCfg = Debug|x64 
    12701287    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|x64.Build.0 = Debug|x64 
     
    15231540    {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|Mixed Platforms.Build.0 = Debug 
    15241541    {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|Win32.ActiveCfg = Debug 
    1525     {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|Win32.Build.0 = Debug 
    15261542    {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|x64.ActiveCfg = Debug 
    15271543    {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|x64.Build.0 = Debug 
  • changelog

    r3692371 r04f2743  
    55 * Improved socket performance (would be nice if we could be used as a "hub") 
    66 
     72009-01-25 MickeM  
     8 * Fixed issue with checkVersion (#242) 
     9 * Fixed spelling error (#244) 
     10 * Fixed crash in CheckFile when a file was locked in exclusive mode (#254) 
     11 + Improved error handling in all CheckDIsk/CheckFile checks. Should report errors better now. 
     12 * Updated the config file a bit: remving "beta" from a bunch of modules no longer in beta.  (#270) 
     13 + Added more filter operatos to all numeric filters so they accept eq:, ne:, gt:, lt: in addition to =, >, <, <>, !, !=, in: (#269) 
     14 
     152009-01-23 MickeM  
     16 + Added better support for numerical hit matching in the eventlog module. You can now use exact and detailed matching. 
     17    You can now use the following syntax: 
     18    CheckEventLog ... warn=ne:1 crit=eq:0 ... 
     19    To generate a warning if the number of hits are != 1 and a critical if the number of hits are = 0. 
     20    Other operators avalible are: =, >, <, <>, !, !=, eq:, ne:, gt:, lt: 
     21 
     222009-01-23 MickeM  
     23 * Cleaned up the checkProcState code and it is not a lot better. 
     24   - Removed race conditions (crashes?) as well as improved perfoamnce and better error handling. 
     25 + Added new option 16bit to checkProcState. When set checkProcState will enumerate all 16 bit processes found running under NTVDM. 
     26 * Fixed NRPE version reported "incorrectly". (Version is now takedn from NSClient++) 
     27 
     282009-01-21 MickeM  
     29 + Added experimental 16 bit process support to checkProcState 
     30 
    7312009-01-20 MickeM  
    832 * Fixed issue with CheckWMI when no filter was specified. 
     
    1337 * Fixed so PDH Collectors use the same exception as the rest of the PDH stuff (might give better errors when PDH breaks, but I doubt it) 
    1438 * removed debug output from -noboot 
    15  + Added new command line option pdhmatch to use pattern matching on PDH queries 
     39 + Added new command line pdhmatch option to use pattern matching on PDH queries 
    1640   Usage: nsclient++ -noboot CheckSystem pdhmatch \Process(*)\Antal trådar 
    1741 * Improved error reporting in the PDH subsystem. 
  • helpers/installer/Product.wxs

    r3692371 r04f2743  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi"> 
    3   <?ifdef "$(var.boost)" ?> 
     3  <?if "$(var.boost)" = "true" ?> 
    44    <?define PlatForm = "$(var.arch)" ?> 
    55    <?define Mode = "Nightly" ?> 
     
    1919    <?define Mode = "Nightly" ?> 
    2020  <?else?> 
    21     <?define PlatForm = "Unknown: $(var.SysTray.ConfigurationName)" ?> 
     21    <?define PlatForm = "Unknown: $(var.boost)" ?> 
    2222  <?endif?> 
    2323  <?endif?> 
     
    9090              </File> 
    9191              <File Id="NSClientINI" Name="NSC.ini" LongName="NSC.ini" DiskId="1" Source="$(var.Path.ini)/NSC.ini" Vital="no"/> 
    92               <?ifdef "$(var.boost)" ?> 
     92              <?if "$(var.boost)" = "true" ?> 
    9393                <File Id="Changelog" Name="change.log" LongName="changelog.txt" DiskId="1" Source="$(var.Source)/changelog.txt" Vital="no"/> 
    9494              <?else?> 
  • include/EnumProcess.cpp

    r846bbe4 r04f2743  
    3131 
    3232 
    33 CEnumProcess::CEnumProcess() : m_pProcesses(NULL), m_pModules(NULL), m_pCurrentP(NULL), m_pCurrentM(NULL), lpString(NULL), PSAPI(NULL) 
    34 { 
    35   lpString = new TCHAR[MAX_FILENAME+1]; 
    36  
     33CEnumProcess::CEnumProcess() : PSAPI(NULL), VDMDBG(NULL), FVDMEnumTaskWOWEx(NULL) 
     34{ 
    3735  PSAPI = ::LoadLibrary(_TEXT("PSAPI")); 
    3836  if (PSAPI)   
    3937  { 
    40     // Setup variables 
    41     m_MAX_COUNT = 256; 
    42     m_cProcesses = 0; 
    43     m_cModules   = 0; 
    44  
    4538    // Find PSAPI functions 
    4639    FEnumProcesses = (PFEnumProcesses)::GetProcAddress(PSAPI, "EnumProcesses"); 
     
    5346  } 
    5447 
    55   // Find the preferred method of enumeration 
    56   m_method = ENUM_METHOD::NONE; 
    57   int method = GetAvailableMethods(); 
    58   if (method == (method|ENUM_METHOD::PSAPI))    m_method = ENUM_METHOD::PSAPI; 
    59  
     48  VDMDBG = ::LoadLibrary(_TEXT("VDMDBG")); 
     49  if (VDMDBG) 
     50  { 
     51    // Find VDMdbg functions 
     52    FVDMEnumTaskWOWEx = (PFVDMEnumTaskWOWEx)::GetProcAddress(VDMDBG, "VDMEnumTaskWOWEx"); 
     53  } 
    6054} 
    6155 
    6256CEnumProcess::~CEnumProcess() 
    6357{ 
    64   delete [] lpString; 
    65   if (m_pProcesses) {delete[] m_pProcesses;} 
    66   if (m_pModules)   {delete[] m_pModules;} 
    6758  if (PSAPI) FreeLibrary(PSAPI); 
    68 } 
    69  
    70  
    71  
    72 int CEnumProcess::GetAvailableMethods() { 
    73   int res = 0; 
    74   // Does all psapi functions exist? 
    75   if (PSAPI&&FEnumProcesses&&FEnumProcessModules&&FGetModuleFileNameEx)  
    76     res += ENUM_METHOD::PSAPI; 
    77   return res; 
    78 } 
    79  
    80 int CEnumProcess::SetMethod(int method) { 
    81   int avail = GetAvailableMethods(); 
    82   if (avail == (method|avail))  
    83     m_method = method; 
    84   return m_method; 
    85 } 
    86  
    87 int CEnumProcess::GetSuggestedMethod() 
    88 { 
    89   return m_method; 
    90 } 
    91 // Retrieves the first process in the enumeration. Should obviously be called before 
    92 // GetProcessNext 
    93 //////////////////////////////////////////////////////////////////////////////////// 
    94 BOOL CEnumProcess::GetProcessFirst(CEnumProcess::CProcessEntry *pEntry) 
    95 { 
    96   if (ENUM_METHOD::NONE == m_method) { 
    97     return FALSE;  
    98   } else if ((ENUM_METHOD::PSAPI|m_method) == m_method) { 
    99     // Use PSAPI functions 
    100     // ---------------------- 
    101     if (m_pProcesses) {delete[] m_pProcesses;} 
    102     m_pProcesses = new DWORD[m_MAX_COUNT]; 
    103     m_pCurrentP = m_pProcesses; 
    104     DWORD cbNeeded = 0; 
    105     BOOL OK = FEnumProcesses(m_pProcesses, m_MAX_COUNT*sizeof(DWORD), &cbNeeded); 
    106  
    107     // We might need more memory here.. 
    108     if (cbNeeded >= m_MAX_COUNT*sizeof(DWORD))  
    109     { 
    110       m_MAX_COUNT += 256; 
    111       return GetProcessFirst(pEntry); // Try again. 
     59  if (VDMDBG) FreeLibrary(VDMDBG); 
     60} 
     61 
     62struct find_16bit_container { 
     63  std::list<CEnumProcess::CProcessEntry> *target; 
     64  DWORD pid; 
     65}; 
     66BOOL CALLBACK Enum16Proc( DWORD dwThreadId, WORD hMod16, WORD hTask16, PSZ pszModName, PSZ pszFileName, LPARAM lpUserDefined ) 
     67{ 
     68  find_16bit_container *container = reinterpret_cast<find_16bit_container*>(lpUserDefined); 
     69  CEnumProcess::CProcessEntry pEntry; 
     70  pEntry.dwPID = container->pid; 
     71  pEntry.command_line = strEx::string_to_wstring(pszFileName); 
     72  std::wstring::size_type pos = pEntry.command_line.find_last_of(_T("\\")); 
     73  if (pos != std::wstring::npos) 
     74    pEntry.filename = pEntry.command_line.substr(++pos); 
     75  else 
     76    pEntry.filename = pEntry.command_line; 
     77  container->target->push_back(pEntry); 
     78  return FALSE; 
     79} 
     80 
     81 
     82CEnumProcess::process_list CEnumProcess::enumerate_processes(bool expand_command_line, bool find_16bit, CEnumProcess::error_reporter *error_interface, unsigned int buffer_size) { 
     83  std::list<CProcessEntry> ret; 
     84  DWORD *dwPIDs = new DWORD[buffer_size+1]; 
     85  DWORD cbNeeded = 0; 
     86  BOOL OK = FEnumProcesses(dwPIDs, buffer_size*sizeof(DWORD), &cbNeeded); 
     87  if (cbNeeded >= DEFAULT_BUFFER_SIZE*sizeof(DWORD)) { 
     88    delete [] dwPIDs; 
     89    return enumerate_processes(expand_command_line, find_16bit, error_interface, buffer_size + 1024);  
     90  } 
     91  if (!OK) { 
     92    delete [] dwPIDs; 
     93    throw process_enumeration_exception(_T("Failed to enumerate process: ") + error::lookup::last_error()); 
     94  } 
     95  unsigned int process_count = cbNeeded/sizeof(DWORD); 
     96  for (unsigned int i = 0;i <process_count; ++i) { 
     97    if (dwPIDs[i] == 0) 
     98      continue; 
     99    CProcessEntry entry; 
     100    try { 
     101      try { 
     102        entry = describe_pid(dwPIDs[i], expand_command_line); 
     103      } catch (process_enumeration_exception &e) { 
     104        if (error_interface!=NULL) 
     105          error_interface->report_warning(e.what()); 
     106        entry = describe_pid(dwPIDs[i], false); 
     107      } 
     108      if (VDMDBG!=NULL&&find_16bit) { 
     109        if( _wcsicmp(entry.filename.substr(0,9).c_str(), _T("NTVDM.EXE")) == 0) { 
     110          find_16bit_container container; 
     111          container.target = &ret; 
     112          container.pid = entry.dwPID; 
     113          FVDMEnumTaskWOWEx(entry.dwPID, (TASKENUMPROCEX)&Enum16Proc, (LPARAM) &container); 
     114        } 
     115      } 
     116      ret.push_back(entry); 
     117    } catch (process_enumeration_exception &e) { 
     118      if (error_interface!=NULL) 
     119        error_interface->report_error(_T("Unhandled exception describing PID: ") + strEx::itos(dwPIDs[i]) + _T(": ") + e.what()); 
     120    } catch (...) { 
     121      if (error_interface!=NULL) 
     122        error_interface->report_error(_T("Unknown exception describing PID: ") + strEx::itos(dwPIDs[i])); 
    112123    } 
    113  
    114     if (!OK) return FALSE; 
    115     m_cProcesses = cbNeeded/sizeof(DWORD);  
    116     return FillPStructPSAPI(*m_pProcesses, pEntry); 
    117   } else { 
    118     return FALSE; 
    119   } 
    120   return TRUE; 
    121 } 
    122  
    123 // Returns the following process 
    124 //////////////////////////////////////////////////////////////// 
    125 BOOL CEnumProcess::GetProcessNext(CEnumProcess::CProcessEntry *pEntry) 
    126 { 
    127   if (ENUM_METHOD::NONE == m_method) return FALSE;  
    128  
    129   // Use ToolHelp functions 
    130   // ---------------------- 
    131   if ((ENUM_METHOD::PSAPI|m_method) == m_method) { 
    132     // Use PSAPI functions 
    133     // ---------------------- 
    134     if (--m_cProcesses <= 0) return FALSE; 
    135     FillPStructPSAPI(*++m_pCurrentP, pEntry); 
    136   } else { 
    137     return FALSE; 
    138   } 
    139   return TRUE; 
    140 } 
    141  
    142  
    143 BOOL CEnumProcess::GetModuleFirst(DWORD dwPID, CEnumProcess::CModuleEntry *pEntry) 
    144 { 
    145   if (ENUM_METHOD::NONE == m_method) return FALSE;  
    146   if ((ENUM_METHOD::PSAPI|m_method) == m_method) { 
    147     // Use PSAPI functions 
    148     // ---------------------- 
    149     if (m_pModules) {delete[] m_pModules;} 
    150     m_pModules = new HMODULE[m_MAX_COUNT]; 
    151     m_pCurrentM = m_pModules; 
    152     DWORD cbNeeded = 0; 
    153     HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwPID); 
    154     if (hProc) 
    155     { 
    156       BOOL OK = FEnumProcessModules(hProc, m_pModules, m_MAX_COUNT*sizeof(HMODULE), &cbNeeded); 
    157       CloseHandle(hProc); 
    158  
    159       // We might need more memory here.. 
    160       if (cbNeeded >= m_MAX_COUNT*sizeof(HMODULE))  
    161       { 
    162         m_MAX_COUNT += 256; 
    163         return GetModuleFirst(dwPID, pEntry); // Try again. 
     124  } 
     125  delete [] dwPIDs; 
     126  return ret; 
     127} 
     128 
     129CEnumProcess::CProcessEntry CEnumProcess::describe_pid(DWORD pid, bool expand_command_line) { 
     130  CProcessEntry entry; 
     131  entry.dwPID = pid; 
     132  // Open process to get filename 
     133  DWORD openArgs = PROCESS_QUERY_INFORMATION|PROCESS_VM_READ; 
     134  if (expand_command_line) 
     135    openArgs |= PROCESS_VM_OPERATION; 
     136  HANDLE hProc = OpenProcess(openArgs, FALSE, pid); 
     137  if (!hProc) { 
     138    throw process_enumeration_exception(_T("Failed to open process: ") + strEx::itos(pid) + _T(": ") + error::lookup::last_error()); 
     139  } 
     140  if (expand_command_line) { 
     141    entry.command_line = GetCommandLine(hProc); 
     142  } 
     143  HMODULE hMod; 
     144  DWORD size; 
     145  // Get the first module (the process itself) 
     146  if( FEnumProcessModules(hProc, &hMod, sizeof(hMod), &size) ) { 
     147    TCHAR buffer[MAX_FILENAME+1]; 
     148    if( !FGetModuleFileNameEx( hProc, hMod, reinterpret_cast<LPTSTR>(&buffer), MAX_FILENAME) ) {  
     149      throw process_enumeration_exception(_T("Failed to find name for: ") + strEx::itos(pid) + _T(": ") + error::lookup::last_error()); 
     150    } else { 
     151      std::wstring path = buffer; 
     152      std::wstring::size_type pos = path.find_last_of(_T("\\")); 
     153      if (pos != std::wstring::npos) { 
     154        path = path.substr(++pos); 
    164155      } 
    165  
    166       if (!OK) return FALSE; 
    167  
    168       m_cModules = cbNeeded/sizeof(HMODULE);  
    169       return FillMStructPSAPI(dwPID, *m_pCurrentM, pEntry); 
     156      entry.filename = path; 
    170157    } 
    171     return FALSE; 
    172   } else { 
    173     return FALSE; 
    174   } 
    175 } 
    176  
    177  
    178 BOOL CEnumProcess::GetModuleNext(DWORD dwPID, CEnumProcess::CModuleEntry *pEntry) 
    179 { 
    180   if (ENUM_METHOD::NONE == m_method) return FALSE;  
    181   if ((ENUM_METHOD::PSAPI|m_method) == m_method) { 
    182     // Use PSAPI functions 
    183     // ---------------------- 
    184     if (--m_cModules <= 0) return FALSE; 
    185     return FillMStructPSAPI(dwPID, *++m_pCurrentM, pEntry); 
    186   } else { 
    187     return FALSE; 
    188   } 
    189  
    190 } 
    191  
    192  
    193 BOOL CEnumProcess::EnableTokenPrivilege (LPTSTR privilege) 
    194 { 
    195   HANDLE hToken;                         
    196   TOKEN_PRIVILEGES token_privileges;                   
    197   DWORD dwSize;                         
    198   ZeroMemory (&token_privileges, sizeof (token_privileges)); 
    199   token_privileges.PrivilegeCount = 1; 
    200   if ( !OpenProcessToken (GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken)) 
    201     return FALSE; 
    202   if (!LookupPrivilegeValue ( NULL, privilege, &token_privileges.Privileges[0].Luid)) 
    203   {  
    204     CloseHandle (hToken); 
    205     return FALSE; 
    206   } 
    207  
    208   token_privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
    209   if (!AdjustTokenPrivileges ( hToken, FALSE, &token_privileges, 0, NULL, &dwSize)) 
    210   {  
    211     CloseHandle (hToken); 
    212     return FALSE; 
    213   } 
    214   CloseHandle (hToken); 
    215   return TRUE; 
     158  } 
     159  CloseHandle(hProc); 
     160  return entry; 
    216161} 
    217162 
     
    233178  MEMORY_BASIC_INFORMATION mbi; 
    234179  if (VirtualQueryEx (hProcess, PROCESS_DATA_BLOCK_ADDRESS, &mbi, sizeof(mbi) ) == 0) 
    235     throw EnumProcException(_T("VirtualQueryEx failed"), GetLastError()); 
     180    throw process_enumeration_exception(_T("VirtualQueryEx failed: ") + error::lookup::last_error()); 
    236181  LPBYTE lpBuffer = (LPBYTE)malloc (sysinfo.dwPageSize); 
    237182  if (lpBuffer == NULL) 
    238     throw EnumProcException(_T("Failed to allocate buffer")); 
     183    throw process_enumeration_exception(_T("Failed to allocate buffer")); 
    239184  SIZE_T dwBytesRead; 
    240185  if (!ReadProcessMemory( hProcess, mbi.BaseAddress, (LPVOID)lpBuffer, sysinfo.dwPageSize, &dwBytesRead)) { 
    241186    free(lpBuffer); 
    242     throw EnumProcException(_T("ReadProcessMemory failed"), GetLastError()); 
     187    throw process_enumeration_exception(_T("ReadProcessMemory failed: ") + error::lookup::last_error()); 
    243188  } 
    244189  LPBYTE lpPos = lpPos = lpBuffer + ((DWORD)PROCESS_DATA_BLOCK_ADDRESS - (DWORD)mbi.BaseAddress); 
     
    271216} 
    272217 
    273  
    274 BOOL CEnumProcess::FillPStructPSAPI(DWORD dwPID, CEnumProcess::CProcessEntry* pEntry) 
    275 { 
    276   pEntry->dwPID = dwPID; 
    277   // Open process to get filename 
    278   bool bCmdLine = pEntry->getCommandLine(); 
    279   DWORD openArgs = PROCESS_QUERY_INFORMATION|PROCESS_VM_READ; 
    280   if (bCmdLine) 
    281     openArgs |= PROCESS_VM_OPERATION; 
    282   HANDLE hProc = OpenProcess(openArgs, FALSE, dwPID); 
    283   if (!hProc) { 
    284     pEntry->filename = _T("N/A (security restriction)"); 
    285     return TRUE; 
    286   } 
    287   if (bCmdLine) { 
    288     try { 
    289       pEntry->command_line = GetCommandLine(hProc); 
    290     } catch (EnumProcException &e) { 
    291       pEntry->command_line = _T("ERROR: " + e.getMessage();); 
    292     } catch (...) { 
    293       pEntry->command_line = _T("ERROR: Failed to get CommandLine."); 
    294     } 
    295   } 
    296   HMODULE hMod; 
    297   DWORD size; 
    298   // Get the first module (the process itself) 
    299   if( FEnumProcessModules(hProc, &hMod, sizeof(hMod), &size) ) { 
    300     //Get filename 
    301     //GetModuleFileNameEx 
    302  
    303     if( !FGetModuleFileNameEx( hProc, hMod, lpString, MAX_FILENAME) ) {  
    304       pEntry->filename = _T("N/A (error)"); 
    305     } else { 
    306       std::wstring path = lpString; 
    307       std::wstring::size_type pos = path.find_last_of(_T("\\")); 
    308       if (pos != std::wstring::npos) { 
    309         path = path.substr(++pos); 
    310       } 
    311       pEntry->filename = path; 
    312     } 
    313   } 
    314   CloseHandle(hProc); 
    315   return TRUE; 
    316 } 
    317  
    318  
    319 BOOL CEnumProcess::FillMStructPSAPI(DWORD dwPID, HMODULE mMod, CEnumProcess::CModuleEntry *pEntry) 
    320 { 
    321   HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwPID); 
    322   if (hProc) 
    323   { 
    324     if( !FGetModuleFileNameEx( hProc, mMod, lpString, MAX_FILENAME) ) 
    325     { 
    326       pEntry->sFilename = _T("N/A (error)"); 
    327     } else { 
    328       pEntry->sFilename = lpString; 
    329     } 
    330     pEntry->pLoadBase = (PVOID) mMod; 
    331     pEntry->pPreferredBase = GetModulePreferredBase(dwPID, (PVOID)mMod); 
    332     CloseHandle(hProc); 
    333     return TRUE; 
    334   } 
    335   return FALSE; 
    336 } 
    337  
    338  
    339  
    340 PVOID CEnumProcess::GetModulePreferredBase(DWORD dwPID, PVOID pModBase) 
    341 { 
    342   if (ENUM_METHOD::NONE == m_method) return NULL;  
    343   HANDLE hProc = OpenProcess(PROCESS_VM_READ, FALSE, dwPID); 
    344   if (hProc) 
    345   { 
    346     IMAGE_DOS_HEADER idh; 
    347     IMAGE_NT_HEADERS inh; 
    348     //Read DOS header 
    349     ReadProcessMemory(hProc, pModBase, &idh, sizeof(idh), NULL); 
    350  
    351     if (IMAGE_DOS_SIGNATURE == idh.e_magic) // DOS header OK? 
    352       // Read NT headers at offset e_lfanew  
    353       ReadProcessMemory(hProc, (PBYTE)pModBase + idh.e_lfanew, &inh, sizeof(inh), NULL); 
    354  
    355     CloseHandle(hProc);  
    356  
    357     if (IMAGE_NT_SIGNATURE == inh.Signature) //NT signature OK? 
    358       // Get the preferred base... 
    359       return (PVOID) inh.OptionalHeader.ImageBase;  
    360  
    361   } 
    362  
    363   return NULL; //didn't find anything useful.. 
    364 } 
    365  
    366  
  • include/EnumProcess.h

    r846bbe4 r04f2743  
    3939typedef BOOL (WINAPI *PFEnumProcessModules)(HANDLE hProcess, HMODULE * lphModule, DWORD cb, LPDWORD lpcbNeeded); 
    4040typedef DWORD (WINAPI *PFGetModuleFileNameEx)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); 
     41//typedef BOOL ( WINAPI *PROCESSENUMPROC )(DWORD dwProcessId, DWORD dwAttributes, LPARAM lpUserDefined  ); 
     42typedef BOOL ( WINAPI *TASKENUMPROCEX )(DWORD dwThreadId, WORD hMod16, WORD hTask16, PSZ pszModName, PSZ pszFileName, LPARAM lpUserDefined ); 
     43typedef INT (WINAPI *PFVDMEnumTaskWOWEx)(DWORD dwProcessId, TASKENUMPROCEX fp, LPARAM lparam);  
    4144#else 
    4245// Functions loaded from PSAPI 
     
    4447typedef BOOL (WINAPI *PFEnumProcessModules)(HANDLE hProcess, HMODULE * lphModule, DWORD cb, LPDWORD lpcbNeeded); 
    4548typedef DWORD (WINAPI *PFGetModuleFileNameEx)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); 
     49typedef BOOL ( WINAPI *TASKENUMPROCEX )(DWORD dwThreadId, WORD hMod16, WORD hTask16, PSZ pszModName, PSZ pszFileName, LPARAM lpUserDefined ); 
     50typedef INT (WINAPI *PFVDMEnumTaskWOWEx)(DWORD dwProcessId, TASKENUMPROCEX fp, LPARAM lparam);  
    4651#endif 
     52 
     53#define DEFAULT_BUFFER_SIZE 1024 
    4754 
    4855class CEnumProcess   
     
    5057public: 
    5158 
    52   class EnumProcException { 
    53     std::wstring error_; 
     59  class error_reporter { 
    5460  public: 
    55     EnumProcException(std::wstring error) : error_(error) {} 
    56     EnumProcException(std::wstring error, DWORD code) : error_(error) { 
    57       error_ += _T(":" ) + error::format::from_system(code); 
    58     } 
    59     std::wstring getMessage() const { 
    60       return error_; 
     61    virtual void report_error(std::wstring error) = 0; 
     62    virtual void report_warning(std::wstring error) = 0; 
     63  }; 
     64  class process_enumeration_exception { 
     65    std::wstring what_; 
     66  public: 
     67    process_enumeration_exception(std::wstring what) : what_(what) {} 
     68    std::wstring what() { 
     69      return what_; 
    6170    } 
    6271  }; 
    6372 
    64   struct CProcessEntry 
    65   { 
    66     static const int fill_filename = 0x1; 
    67     static const int fill_command_line = 0x2; 
    68     DWORD fill; 
     73  struct CProcessEntry { 
    6974    std::wstring filename; 
    7075    std::wstring command_line; 
    7176    DWORD  dwPID; 
    72     // Constructors/Destructor 
    73     CProcessEntry() : dwPID(0), fill(0) {} 
    74     CProcessEntry(DWORD toFill) : dwPID(0), fill(toFill) {} 
    75     CProcessEntry(const CProcessEntry &e) : dwPID(e.dwPID), fill(e.fill), filename(e.filename), command_line(e.command_line) {} 
    76     virtual ~CProcessEntry() {} 
    77     bool getCommandLine() const { return (fill&fill_command_line)!=0; } 
    78     bool getFilename() const { return (fill&fill_filename)!=0; } 
    7977  }; 
     78 
     79  typedef std::list<CProcessEntry> process_list; 
     80  process_list enumerate_processes(bool expand_command_line, bool find_16bit = false, CEnumProcess::error_reporter *error_interface = NULL, unsigned int buffer_size = DEFAULT_BUFFER_SIZE); 
     81  CProcessEntry describe_pid(DWORD pid, bool expand_command_line); 
    8082 
    8183  struct CModuleEntry 
     
    9395  virtual ~CEnumProcess(); 
    9496 
    95   BOOL GetModuleNext(DWORD dwPID, CModuleEntry* pEntry); 
    96   BOOL GetModuleFirst(DWORD dwPID, CModuleEntry* pEntry); 
    97   BOOL GetProcessNext(CProcessEntry *pEntry);     
    98   BOOL GetProcessFirst(CProcessEntry* pEntry); 
    99   BOOL EnableTokenPrivilege(LPTSTR privilege); 
    10097  std::wstring GetCommandLine(HANDLE hProcess); 
     98  bool has_PSAPI() { 
     99    return PSAPI != NULL; 
     100  } 
    101101 
    102   int GetAvailableMethods(); 
    103   int GetSuggestedMethod(); 
    104   int SetMethod(int method); 
    105  
    106  
    107  
    108 protected: 
    109  
    110   PVOID GetModulePreferredBase(DWORD dwPID, PVOID pModBase); 
    111   // General members 
    112   int m_method; 
     102private: 
    113103 
    114104  // PSAPI related members 
    115105  HMODULE PSAPI;   //Handle to the module 
    116   int m_MAX_COUNT;  
    117   DWORD* m_pProcesses, *m_pCurrentP; // Process identifiers 
    118   long m_cProcesses, m_cModules;     // Number of Processes/Modules found 
    119   HMODULE* m_pModules, *m_pCurrentM; // Handles to Modules  
     106  HMODULE VDMDBG; 
    120107  // PSAPI related functions 
    121108  PFEnumProcesses       FEnumProcesses;           // Pointer to EnumProcess 
    122109  PFEnumProcessModules  FEnumProcessModules; // Pointer to EnumProcessModules 
    123110  PFGetModuleFileNameEx FGetModuleFileNameEx;// Pointer to GetModuleFileNameEx 
    124   BOOL FillPStructPSAPI(DWORD pid, CProcessEntry* pEntry); 
    125   BOOL FillMStructPSAPI(DWORD dwPID, HMODULE mMod, CModuleEntry* pEntry); 
    126   LPTSTR lpString; 
     111  PFVDMEnumTaskWOWEx FVDMEnumTaskWOWEx; 
    127112}; 
    128113 
  • include/checkHelpers.hpp

    r3692371 r04f2743  
    3131  typedef enum { warning, critical} ResultType; 
    3232  typedef enum { above = 1, below = -1, same = 0 } checkResultType; 
    33  
    34  
     33  class check_exception { 
     34    std::wstring error_; 
     35  public: 
     36    check_exception(std::wstring error) : error_(error) {} 
     37    std::wstring getMessage() { 
     38      return error_; 
     39    } 
     40  }; 
     41 
     42  struct parse_exception : public check_exception { 
     43    parse_exception(std::wstring error) : check_exception(error) {} 
     44  }; 
    3545 
    3646  static std::wstring formatAbove(std::wstring str, ResultType what) { 
     
    4858      return str + _T(" < critical"); 
    4959    return str + _T(" < unknown"); 
     60  } 
     61  static std::wstring formatSame(std::wstring str, ResultType what) { 
     62    if (what == warning) 
     63      return str + _T(" = warning"); 
     64    else if (what == critical) 
     65      return str + _T(" = critical"); 
     66    return str + _T(" = unknown"); 
     67  } 
     68  static std::wstring formatNotSame(std::wstring str, ResultType what) { 
     69    if (what == warning) 
     70      return str + _T(" != warning"); 
     71    else if (what == critical) 
     72      return str + _T(" != critical"); 
     73    return str + _T(" != unknown"); 
    5074  } 
    5175  static std::wstring formatState(std::wstring str, ResultType what) { 
     
    107131      return crit.gatherPerfData(getAlias(), value, warn, crit); 
    108132    } 
     133    bool hasBounds() { 
     134      return warn.hasBounds() || crit.hasBounds(); 
     135    } 
    109136    void runCheck(typename TContents::TValueType &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 
    110137      std::wstring tstr; 
    111138      if (crit.check(value, getAlias(), tstr, critical)) { 
     139        std::wcout << _T("crit") << std::endl; 
    112140        NSCHelper::escalteReturnCodeToCRIT(returnCode); 
    113141      } else if (warn.check(value, getAlias(), tstr, warning)) { 
     142        std::wcout << _T("warn") << std::endl; 
    114143        NSCHelper::escalteReturnCodeToWARN(returnCode); 
    115144      }else if (show == showLong) { 
     145        std::wcout << _T("long") << std::endl; 
    116146        tstr = getAlias() + _T(": ") + TContents::toStringLong(value); 
    117147      }else if (show == showShort) { 
     148        std::wcout << _T("short") << std::endl; 
    118149        tstr = getAlias() + _T(": ") + TContents::toStringShort(value); 
    119150      } 
     151      std::wcout << _T("result: ") << tstr << _T("--") << std::endl; 
    120152      if (perfData) 
    121153        perf += gatherPerfData(value); 
     
    124156      if (!tstr.empty()) 
    125157        message += tstr; 
     158      std::wcout << _T("result: ") << tstr << _T("--") << std::endl; 
    126159    } 
    127160  }; 
     
    750783 
    751784 
     785  template <class THolder = NumericBounds<int, int_handler> > 
     786  class ExactBounds { 
     787  public: 
     788    THolder max; 
     789    THolder min; 
     790    THolder eq; 
     791    THolder neq; 
     792    typedef ExactBounds<THolder > TMyType; 
     793    typedef typename THolder::TValueType TValueType; 
     794 
     795    ExactBounds() {} 
     796    ExactBounds(const ExactBounds &other) { 
     797      max = other.max; 
     798      min = other.min; 
     799      eq = other.eq; 
     800      neq = other.neq; 
     801    } 
     802 
     803    const TMyType& operator=(std::wstring value) { 
     804      //value_ = value; 
     805      if (value.substr(0,1) == _T(">")) { 
     806        max = value.substr(1); 
     807      } else if (value.substr(0,2) == _T("<>")) { 
     808        neq = value.substr(2); 
     809      } else if (value.substr(0,1) == _T("<")) { 
     810        min = value.substr(1); 
     811      } else if (value.substr(0,1) == _T("=")) { 
     812        eq = value.substr(1); 
     813      } else if (value.substr(0,2) == _T("!=")) { 
     814        neq = value.substr(2); 
     815      } else if (value.substr(0,1) == _T("!")) { 
     816        neq = value.substr(1); 
     817        /* 
     818        TODO add support for lists 
     819      } else if (value.substr(0,3) == _T("in:")) { 
     820        inList = value.substr(3); 
     821        */ 
     822      } else if (value.substr(0,3) == _T("gt:")) { 
     823        max = value.substr(3); 
     824      } else if (value.substr(0,3) == _T("lt:")) { 
     825        min = value.substr(3); 
     826      } else if (value.substr(0,3) == _T("ne:")) { 
     827        neq = value.substr(3); 
     828      } else if (value.substr(0,3) == _T("eq:")) { 
     829        eq = value.substr(3); 
     830      } else { 
     831        throw parse_exception(_T("Unknown filter key: ") + value + _T(" (numeric filters have to have an operator as well ie. foo=>5 or bar==5 foo=gt:6)")); 
     832      } 
     833      return *this; 
     834    } 
     835 
     836    bool hasBounds() { 
     837      return max.hasBounds() || min.hasBounds() || eq.hasBounds() || neq.hasBounds(); 
     838    } 
     839    static std::wstring toStringLong(typename THolder::TValueType &value) { 
     840      return THolder::toStringLong(value); 
     841    } 
     842    static std::wstring toStringShort(typename THolder::TValueType &value) { 
     843      return THolder::toStringShort(value); 
     844    } 
     845    std::wstring gatherPerfData(std::wstring alias, typename THolder::TValueType &value, TMyType &warn, TMyType &crit) { 
     846      if (max.hasBounds()) { 
     847        return max.gatherPerfData(alias, value, warn.max.getPerfBound(value), crit.max.getPerfBound(value)); 
     848      } else if (min.hasBounds()) { 
     849        return min.gatherPerfData(alias, value, warn.min.getPerfBound(value), crit.min.getPerfBound(value)); 
     850      } else if (neq.hasBounds()) { 
     851        return neq.gatherPerfData(alias, value, warn.neq.getPerfBound(value), crit.neq.getPerfBound(value)); 
     852      } else if (eq.hasBounds()) { 
     853        return eq.gatherPerfData(alias, value, warn.eq.getPerfBound(value), crit.eq.getPerfBound(value)); 
     854      } else { 
     855        NSC_DEBUG_MSG_STD(_T("Missing bounds for: ") + alias); 
     856      } 
     857    } 
     858    bool check(typename THolder::TValueType &value, std::wstring lable, std::wstring &message, ResultType type) { 
     859      if ((max.hasBounds())&&(max.check(value) == above)) { 
     860        message = lable + _T(": ") + formatAbove(THolder::toStringLong(value), type); 
     861        return true; 
     862      } else if ((min.hasBounds())&&(min.check(value) == below)) { 
     863        message = lable + _T(": ") + formatBelow(THolder::toStringLong(value), type); 
     864        return true; 
     865      } else if ((eq.hasBounds())&&(eq.check(value) == same)) { 
     866        message = lable + _T(": ") + formatSame(THolder::toStringLong(value), type); 
     867        return true; 
     868      } else if ((neq.hasBounds())&&(neq.check(value) != same)) { 
     869        message = lable + _T(": ") + formatNotSame(THolder::toStringLong(value), type); 
     870        return true; 
     871      } else { 
     872        //std::cout << "No bounds specified..." << std::endl; 
     873      } 
     874      return false; 
     875    } 
     876 
     877  }; 
     878  typedef ExactBounds<NumericBounds<unsigned long int, int_handler> > ExactBoundsULongInteger; 
     879 
    752880  //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<int ,int>, int_handler> > MaxMinPercentageBoundsInteger; 
    753881  //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<__int64, __int64>, int64_handler> > MaxMinPercentageBoundsInt64; 
  • include/filter_framework.hpp

    r3692371 r04f2743  
    338338      } else if (value.substr(0,3) == _T("in:")) { 
    339339        inList = value.substr(3); 
     340      } else if (value.substr(0,3) == _T("gt:")) { 
     341        max = value.substr(3); 
     342      } else if (value.substr(0,3) == _T("lt:")) { 
     343        min = value.substr(3); 
     344      } else if (value.substr(0,3) == _T("ne:")) { 
     345        neq = value.substr(3); 
     346      } else if (value.substr(0,3) == _T("eq:")) { 
     347        eq = value.substr(3); 
    340348      } else { 
    341349        throw parse_exception(_T("Unknown filter key: ") + value + _T(" (numeric filters have to have an operator as well ie. foo=>5 or bar==5)")); 
  • include/utils.h

    rce57b1b r04f2743  
    5757      else if (p__.first == (_T("MinCrit") postfix)) { obj.crit.min = p__.second; } 
    5858 
     59#define MAP_OPTIONS_EXACT_NUMERIC_ALL(obj, postfix) \ 
     60      else if (p__.first == (_T("warn") postfix)) { obj.warn = p__.second; } \ 
     61      else if (p__.first == (_T("crit") postfix)) { obj.crit = p__.second; } \ 
     62 
    5963#define MAP_OPTIONS_PUSH_WTYPE(type, value, obj, list) \ 
    6064      else if (p__.first == value) { type o; o.obj = p__.second; list.push_back(o); } 
  • modules/CheckDisk/CheckDisk.cpp

    rc09c225 r04f2743  
    6363} 
    6464 
     65class error_reporter { 
     66public: 
     67  virtual void report_error(std::wstring error) = 0; 
     68  virtual void report_warning(std::wstring error) = 0; 
     69}; 
     70 
     71 
    6572struct file_finder_data { 
    66   file_finder_data(const WIN32_FIND_DATA wfd_, const std::wstring path_) : wfd(wfd_), path(path_) {} 
     73  file_finder_data(const WIN32_FIND_DATA wfd_, const std::wstring path_, error_reporter *errors_) : wfd(wfd_), path(path_), errors(errors_) {} 
    6774  const WIN32_FIND_DATA wfd; 
    6875  const std::wstring path; 
     76  error_reporter *errors; 
    6977}; 
    7078typedef std::unary_function<const file_finder_data&, bool> baseFinderFunction; 
     
    8694    return error; 
    8795  } 
    88   inline void setError(std::wstring) { 
     96  inline void setError(error_reporter *errors, std::wstring msg) { 
     97    if (errors != NULL) 
     98      errors->report_error(msg); 
    8999    error = true; 
    90100  } 
     
    95105 
    96106template <class finder_function> 
    97 void recursive_scan(std::wstring dir, finder_function & f) { 
     107void recursive_scan(std::wstring dir, finder_function & f, error_reporter * errors) { 
    98108  std::wstring baseDir; 
    99109  std::wstring::size_type pos = dir.find_last_of('\\'); 
     
    106116  if (hFind != INVALID_HANDLE_VALUE) { 
    107117    do { 
    108       if (!f(file_finder_data(wfd, baseDir))) 
     118      if (!f(file_finder_data(wfd, baseDir, errors))) 
    109119        break; 
    110120      if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) { 
    111121        if ( (wcscmp(wfd.cFileName, _T(".")) != 0) && (wcscmp(wfd.cFileName, _T("..")) != 0) ) 
    112           recursive_scan<finder_function>(baseDir + _T("\\") + wfd.cFileName + _T("\\*.*"), f); 
     122          recursive_scan<finder_function>(baseDir + _T("\\") + wfd.cFileName + _T("\\*.*"), f, errors); 
    113123      } 
    114124    } while (FindNextFile(hFind, &wfd)); 
    115125  } else { 
    116     f.setError(_T("File not found")); 
     126    f.setError(errors, _T("File not found")); 
    117127  } 
    118128  FindClose(hFind); 
     
    281291} 
    282292 
     293class NSC_error : public error_reporter { 
     294  void report_error(std::wstring error) { 
     295    NSC_LOG_ERROR(error); 
     296  } 
     297  void report_warning(std::wstring error) { 
     298    NSC_LOG_MESSAGE(error); 
     299  } 
     300}; 
    283301 
    284302 
     
    318336    std::wstring sName = path.getAlias(); 
    319337    get_size sizeFinder; 
    320     recursive_scan<get_size>(path.data, sizeFinder); 
     338    NSC_error errors; 
     339    recursive_scan<get_size>(path.data, sizeFinder, &errors); 
    321340    if (sizeFinder.hasError()) { 
    322       message = _T("File not found"); 
     341      message = _T("File not found check log for details"); 
    323342      return NSCAPI::returnUNKNOWN; 
    324343    } 
     
    416435      0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 
    417436    if (hFile == INVALID_HANDLE_VALUE) { 
    418       setError(_T("Could not open file: ") + ffd.path + _T("\\") + ffd.wfd.cFileName + _T(": ") + error::lookup::last_error()); 
     437      setError(ffd.errors, _T("Could not open file: ") + ffd.path + _T("\\") + ffd.wfd.cFileName + _T(": ") + error::lookup::last_error()); 
    419438      return false; 
    420439    } 
     
    427446    return error; 
    428447  } 
    429   inline void setError(std::wstring) { 
     448  inline void setError(error_reporter *errors, std::wstring msg) { 
     449    if (errors != NULL) 
     450      errors->report_error(msg); 
    430451    error = true; 
    431452  } 
     
    453474      0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 
    454475    if (hFile == INVALID_HANDLE_VALUE) { 
    455       setError(_T("Could not open file: ") + ffd.path + _T("\\") + ffd.wfd.cFileName + _T(": ") + error::lookup::last_error()); 
     476      setError(ffd.errors, _T("Could not open file: ") + ffd.path + _T("\\") + ffd.wfd.cFileName + _T(": ") + error::lookup::last_error()); 
     477      return true; 
    456478    } 
    457479    GetFileInformationByHandle(hFile, &_info); 
     
    488510    return error; 
    489511  } 
    490   inline void setError(std::wstring) { 
     512  inline void setError(error_reporter *errors, std::wstring msg) { 
     513    if (errors != NULL) 
     514      errors->report_error(msg); 
    491515    error = true; 
    492516  } 
     
    523547      0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 
    524548    if (hFile == INVALID_HANDLE_VALUE) { 
    525       setError(_T("Could not open file: ") + ffd.path + _T("\\") + ffd.wfd.cFileName + _T(": ") + error::lookup::last_error()); 
     549      setError(ffd.errors, _T("Could not open file: ") + ffd.path + _T("\\") + ffd.wfd.cFileName + _T(": ") + error::lookup::last_error()); 
     550      return true; 
    526551    } 
    527552    GetFileInformationByHandle(hFile, &_info); 
     
    568593    return error; 
    569594  } 
    570   inline void setError(std::wstring) { 
     595  inline void setError(error_reporter *errors, std::wstring msg) { 
     596    if (errors != NULL) 
     597      errors->report_error(msg); 
    571598    error = true; 
    572599  } 
     
    596623  } 
    597624 
    598   recursive_scan<find_first_file_info>(path, finder); 
     625  NSC_error errors; 
     626  recursive_scan<find_first_file_info>(path, finder, &errors); 
    599627  if (finder.hasError()) { 
    600     message = _T("File not found"); 
     628    message = _T("File not found (check log for details)"); 
    601629    return NSCAPI::returnUNKNOWN; 
    602630  } 
     
    655683  finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 
    656684  finder.syntax = syntax; 
     685  NSC_error errors; 
    657686  for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 
    658     recursive_scan<file_filter_function>((*pit), finder); 
     687    recursive_scan<file_filter_function>((*pit), finder, &errors); 
    659688    if (finder.hasError()) { 
    660       message = _T("File not found: ") + (*pit); 
     689      message = _T("File not found: ") + (*pit) + _T(" check log for details."); 
    661690      return NSCAPI::returnUNKNOWN; 
    662691    } 
     
    747776    finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 
    748777    finder.syntax = syntax; 
     778    NSC_error errors; 
    749779    for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 
    750       recursive_scan<file_filter_function_ex>((*pit), finder); 
     780      recursive_scan<file_filter_function_ex>((*pit), finder, &errors); 
    751781      if (finder.hasError()) { 
    752         message = _T("Error when scanning: ") + (*pit); 
     782        message = _T("Error when scanning: ") + (*pit) + _T(" check log for details."); 
    753783        return NSCAPI::returnUNKNOWN; 
    754784      } 
  • modules/CheckEventLog/CheckEventLog.cpp

    r3692371 r04f2743  
    495495  if (command != _T("CheckEventLog")) 
    496496    return NSCAPI::returnIgnored; 
    497   typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQueryContainer; 
     497  typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container; 
     498  typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container; 
     499   
    498500  typedef std::pair<int,eventlog_filter> filteritem_type; 
    499501  typedef std::list<filteritem_type > filterlist_type; 
     
    503505  std::list<std::wstring> files; 
    504506  filterlist_type filter_chain; 
    505   EventLogQueryContainer query; 
     507  EventLogQuery1Container query1; 
     508  EventLogQuery2Container query2; 
    506509 
    507510  bool bPerfData = true; 
     
    529532  try { 
    530533    MAP_OPTIONS_BEGIN(stl_args) 
    531       MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 
     534      MAP_OPTIONS_NUMERIC_ALL(query1, _T("")) 
     535      MAP_OPTIONS_EXACT_NUMERIC_ALL(query2, _T("")) 
    532536      MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
    533537      MAP_OPTIONS_BOOL_TRUE(_T("unique"), unique) 
     
    579583  } catch (filters::filter_exception e) { 
    580584    message = e.getMessage(); 
     585    return NSCAPI::returnUNKNOWN; 
     586    } catch (checkHolders::parse_exception e) { 
     587    message = e.getMessage(); 
     588    return NSCAPI::returnUNKNOWN; 
     589  } catch (...) { 
     590    message = _T("Invalid command line!"); 
    581591    return NSCAPI::returnUNKNOWN; 
    582592  } 
     
    727737  } 
    728738 
    729   if (!bPerfData) 
    730     query.perfData = false; 
    731   if (query.alias.empty()) 
    732     query.alias = _T("eventlog"); 
    733   query.runCheck(hit_count, returnCode, message, perf); 
     739  if (!bPerfData) { 
     740    query1.perfData = false; 
     741    query2.perfData = false; 
     742  } 
     743  if (query1.alias.empty()) 
     744    query1.alias = _T("eventlog"); 
     745  if (query2.alias.empty()) 
     746    query2.alias = _T("eventlog"); 
     747  if (query1.hasBounds()) 
     748    query1.runCheck(hit_count, returnCode, message, perf); 
     749  else if (query2.hasBounds()) 
     750    query2.runCheck(hit_count, returnCode, message, perf); 
     751  else { 
     752    message = _T("No bounds specified!"); 
     753    return NSCAPI::returnUNKNOWN; 
     754  } 
    734755  if ((truncate > 0) && (message.length() > (truncate-4))) 
    735756    message = message.substr(0, truncate-4) + _T("..."); 
    736757  if (message.empty()) 
    737758    message = _T("Eventlog check ok"); 
    738   NSC_DEBUG_MSG_STD(_T("Result: ") + message) ; 
    739759  return returnCode; 
    740760} 
  • modules/CheckHelpers/CheckHelpers.cpp

    rc165d1d r04f2743  
    8989    return NSCAPI::returnOK; 
    9090  } else if (command == _T("CheckVersion")) { 
    91     msg = SZVERSION; 
     91    msg = NSCModuleHelper::getApplicationVersionString(); 
    9292    return NSCAPI::returnOK; 
    9393  } else if (command == _T("CheckOK")) { 
  • modules/CheckSystem/CheckSystem.cpp

    r3692371 r04f2743  
    5353 * @return  
    5454 */ 
    55 CheckSystem::CheckSystem() : processMethod_(0), pdhThread(_T("pdhThread")) {} 
     55CheckSystem::CheckSystem() : pdhThread(_T("pdhThread")) {} 
    5656/** 
    5757 * Default d-tor 
     
    6666bool CheckSystem::loadModule() { 
    6767  pdhThread.createThread(); 
    68   std::wstring wantedMethod = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_ENUMPROC_METHOD, C_SYSTEM_ENUMPROC_METHOD_DEFAULT); 
    69   CEnumProcess tmp; 
    70   int method = tmp.GetAvailableMethods(); 
    71   if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_AUTO) { 
    72     OSVERSIONINFO osVer = systemInfo::getOSVersion(); 
    73     /* 
    74     if (systemInfo::isBelowNT4(osVer)) { 
    75       NSC_DEBUG_MSG_STD(_T("Autodetected NT4<, using PSAPI process enumeration.")); 
    76       if (method == (method|ENUM_METHOD::PSAPI)) { 
    77         processMethod_ = ENUM_METHOD::PSAPI; 
    78       } else { 
    79         NSC_LOG_ERROR_STD(_T("PSAPI method not available, since you are on NT4 you need to install \"Platform SDK Redistributable: PSAPI for Windows NT\" from Microsoft.")); 
    80         NSC_LOG_ERROR_STD(_T("Try this URL: http://www.microsoft.com/downloads/details.aspx?FamilyID=3d1fbaed-d122-45cf-9d46-1cae384097ac")); 
    81       } 
    82     } else if (systemInfo::isAboveW2K(osVer)) { 
    83       NSC_DEBUG_MSG_STD(_T("Autodetected W2K>, using TOOLHELP process enumeration.")); 
    84       if (method == (method|ENUM_METHOD::TOOLHELP)) { 
    85         processMethod_ = ENUM_METHOD::TOOLHELP; 
    86       } else { 
    87         NSC_LOG_ERROR_STD(_T("TOOLHELP was not available, since you are on > W2K you need top manually override the ") C_SYSTEM_ENUMPROC_METHOD _T("option in NSC:ini.")); 
    88       } 
    89     } else { 
    90     */ 
    91       //NSC_DEBUG_MSG_STD(_T("Autodetected failed, using PSAPI process enumeration.")); 
    92       processMethod_ = ENUM_METHOD::PSAPI; 
    93       if (method == (method|ENUM_METHOD::PSAPI)) { 
    94         processMethod_ = ENUM_METHOD::PSAPI; 
    95       } else { 
    96         NSC_LOG_ERROR_STD(_T("PSAPI method not availabletry installing \"Platform SDK Redistributable: PSAPI for Windows NT\" from Microsoft.")); 
    97         NSC_LOG_ERROR_STD(_T("Try this URL: http://www.microsoft.com/downloads/details.aspx?FamilyID=3d1fbaed-d122-45cf-9d46-1cae384097ac")); 
    98       } 
    99     //} 
    100   } else if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 
    101     NSC_DEBUG_MSG_STD(_T("Using PSAPI method.")); 
    102     if (method == (method|ENUM_METHOD::PSAPI)) { 
    103       processMethod_ = ENUM_METHOD::PSAPI; 
    104     } else { 
    105       NSC_LOG_ERROR_STD(_T("PSAPI method not available, check ") C_SYSTEM_ENUMPROC_METHOD _T(" option.")); 
    106     } 
    107   } else { 
    108     NSC_LOG_ERROR_STD(_T("TOOLHELP method has been removed sine we dont really want to support w9x ") C_SYSTEM_ENUMPROC_METHOD _T(".")); 
    109   } 
    11068  try { 
    11169    NSCModuleHelper::registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer.")); 
     
    691649    msg = msg.substr(0, truncate-4) + _T("..."); 
    692650  if (msg.empty() && returnCode == NSCAPI::returnOK) 
    693     msg = _T("OK: All services are in their apropriate state."); 
     651    msg = _T("OK: All services are in their appropriate state."); 
    694652  else if (msg.empty()) 
    695653    msg = NSCHelper::translateReturn(returnCode) + _T(": Whooha this is odd."); 
     
    828786} NSPROCDATA; 
    829787typedef std::map<std::wstring,NSPROCDATA,strEx::case_blind_string_compare> NSPROCLST; 
     788 
     789class NSC_error : public CEnumProcess::error_reporter { 
     790  void report_error(std::wstring error) { 
     791    NSC_LOG_ERROR(error); 
     792  } 
     793  void report_warning(std::wstring error) { 
     794    NSC_LOG_MESSAGE(error); 
     795  } 
     796}; 
     797 
    830798/** 
    831799* Get a hash_map with all running processes. 
    832800* @return a hash_map with all running processes 
    833801*/ 
    834 NSPROCLST GetProcessList(int processMethod, bool getCmdLines) 
     802NSPROCLST GetProcessList(bool getCmdLines, bool use16Bit) 
    835803{ 
    836804  NSPROCLST ret; 
    837   if (processMethod == 0) { 
    838     NSC_LOG_ERROR_STD(_T("ProcessMethod not defined or not available.")); 
    839     return ret; 
    840   } 
    841805  CEnumProcess enumeration; 
    842   if (enumeration.SetMethod(processMethod) != processMethod) { 
    843     NSC_LOG_ERROR_STD(_T("Failed to set process enumeration method")); 
    844     return ret; 
    845   } 
    846   int toFill = CEnumProcess::CProcessEntry::fill_filename; 
    847   if (getCmdLines) 
    848     toFill |= CEnumProcess::CProcessEntry::fill_command_line; 
    849   CEnumProcess::CProcessEntry entry(toFill); 
    850   for (BOOL OK = enumeration.GetProcessFirst(&entry); OK; OK = enumeration.GetProcessNext(&entry) ) { 
     806  if (!enumeration.has_PSAPI()) { 
     807    NSC_LOG_ERROR_STD(_T("Failed to enumerat processes")); 
     808    NSC_LOG_ERROR_STD(_T("PSAPI method not availabletry installing \"Platform SDK Redistributable: PSAPI for Windows NT\" from Microsoft.")); 
     809    NSC_LOG_ERROR_STD(_T("Try this URL: http://www.microsoft.com/downloads/details.aspx?FamilyID=3d1fbaed-d122-45cf-9d46-1cae384097ac")); 
     810    throw CEnumProcess::process_enumeration_exception(_T("PSAPI not avalible, please see eror log for details.")); 
     811  } 
     812  NSC_error err; 
     813  CEnumProcess::process_list list = enumeration.enumerate_processes(getCmdLines, use16Bit, &err); 
     814  for (CEnumProcess::process_list::const_iterator entry = list.begin(); entry != list.end(); ++entry) { 
    851815    std::wstring key; 
    852     if (getCmdLines) 
    853       key = entry.command_line; 
     816    if (getCmdLines && !(*entry).command_line.empty()) 
     817      key = (*entry).command_line; 
    854818    else 
    855       key = entry.filename; 
     819      key = (*entry).filename; 
    856820    NSPROCLST::iterator it = ret.find(key); 
    857821    if (it == ret.end()) { 
    858       ret[key].entry = entry; 
     822      ret[key].entry = (*entry); 
    859823      ret[key].count = 1; 
    860824      ret[key].key = key; 
     
    888852  StateContainer tmpObject; 
    889853  bool bPerfData = true; 
     854  bool use16bit = false; 
    890855  bool useCmdLine = false; 
    891856  typedef enum { 
     
    906871    MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 
    907872    MAP_OPTIONS_BOOL_TRUE(_T("cmdLine"), useCmdLine) 
     873    MAP_OPTIONS_BOOL_TRUE(_T("16bit"), use16bit) 
    908874    MAP_OPTIONS_MODE(_T("match"), _T("string"), match,  match_string) 
    909875    MAP_OPTIONS_MODE(_T("match"), _T("regexp"), match,  match_regexp) 
     
    930896  NSPROCLST runningProcs; 
    931897  try { 
    932     runningProcs = GetProcessList(processMethod_, useCmdLine); 
    933   } catch (CEnumProcess::EnumProcException e) { 
    934     NSC_LOG_ERROR_STD(_T("ERROR: ") + e.getMessage()); 
    935     msg = static_cast<std::wstring>(_T("ERROR: ")) + e.getMessage(); 
     898    runningProcs = GetProcessList(useCmdLine, use16bit); 
     899  } catch (CEnumProcess::process_enumeration_exception &e) { 
     900    NSC_LOG_ERROR_STD(_T("ERROR: ") + e.what()); 
     901    msg = static_cast<std::wstring>(_T("ERROR: ")) + e.what(); 
    936902    return NSCAPI::returnUNKNOWN; 
    937903  } catch (...) { 
  • modules/CheckSystem/CheckSystem.h

    r99e4d8f r04f2743  
    3030private: 
    3131  CheckMemory memoryChecker; 
    32   int processMethod_; 
    3332  PDHCollectorThread pdhThread; 
    3433 
  • modules/DebugLogMetrics/DebugLogMetrics.cpp

    r3692371 r04f2743  
    6060  return false; 
    6161} 
    62  
     62/* 
    6363void getMetricsForPid(DWORD pid) { 
    6464  HANDLE hProcModule = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid ); 
     
    8282 
    8383} 
     84*/ 
    8485 
    8586NSCAPI::nagiosReturn DebugLogMetrics::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
  • modules/NRPEListener/NRPEListener.cpp

    r3692371 r04f2743  
    374374  strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 
    375375  if (cmd.first == _T("_NRPE_CHECK")) { 
    376     return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnOK, _T("I (") SZVERSION _T(") seem to be doing fine..."), buffer_length_); 
     376    return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnOK, _T("I (") + NSCModuleHelper::getApplicationVersionString() + _T(") seem to be doing fine..."), buffer_length_); 
    377377  } 
    378378  std::wstring msg, perf; 
Note: See TracChangeset for help on using the changeset viewer.