Changeset 04f2743 in nscp
- Timestamp:
- 01/25/09 14:30:22 (4 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 1d53fe0
- Parents:
- 3692371
- Files:
-
- 17 edited
-
AutoBuild.h (modified) (1 diff)
-
NSC.dist (modified) (1 diff)
-
NSClient++-2005.sln (modified) (5 diffs)
-
changelog (modified) (2 diffs)
-
helpers/installer/Product.wxs (modified) (3 diffs)
-
include/EnumProcess.cpp (modified) (4 diffs)
-
include/EnumProcess.h (modified) (4 diffs)
-
include/checkHelpers.hpp (modified) (5 diffs)
-
include/filter_framework.hpp (modified) (1 diff)
-
include/utils.h (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.cpp (modified) (15 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (5 diffs)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (7 diffs)
-
modules/CheckSystem/CheckSystem.h (modified) (1 diff)
-
modules/DebugLogMetrics/DebugLogMetrics.cpp (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
r3692371 r04f2743 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,6, 1686 #define PRODUCTVER 0,3,6, 1687 #define STRFILEVER _T("0.3.6. 168")8 #define STRPRODUCTVER _T("0.3.6. 168")9 #define STRPRODUCTDATE _T("2009-01-2 0")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") 10 10 #endif // AUTOBUILD_H -
NSC.dist
rbb8b6d1 r04f2743 18 18 ;CheckWMI.dll 19 19 ; 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 ; 20 29 ; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! 21 30 ;RemoteConfiguration.dll 22 ; NSCA Agent is a new beta module use with care!23 ;NSCAAgent.dll24 ; LUA script module used to write your own "check deamon" (sort of) early beta.25 ;LUAScript.dll26 ; Script to check external scripts and/or internal aliases, early beta.27 ;CheckExternalScripts.dll28 31 ; Check other hosts through NRPE extreme beta and probably a bit dangerous! :) 29 32 ;NRPEClient.dll -
NSClient++-2005.sln
r3692371 r04f2743 5 5 Debug.AspNetCompiler.Debug = "True" 6 6 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} 7 27 EndProjectSection 8 28 EndProject … … 1170 1190 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|Mixed Platforms.Build.0 = Debug 1171 1191 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|Win32.ActiveCfg = Debug 1172 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|Win32.Build.0 = Debug1173 1192 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|x64.ActiveCfg = Debug 1174 1193 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Debug|x64.Build.0 = Debug … … 1225 1244 {6206F046-3D36-4258-BB03-3291A7070117}.Debug|Mixed Platforms.Build.0 = Debug|Win32 1226 1245 {6206F046-3D36-4258-BB03-3291A7070117}.Debug|Win32.ActiveCfg = Debug|Win32 1227 {6206F046-3D36-4258-BB03-3291A7070117}.Debug|Win32.Build.0 = Debug|Win321228 1246 {6206F046-3D36-4258-BB03-3291A7070117}.Debug|x64.ActiveCfg = Debug|Win32 1229 1247 {6206F046-3D36-4258-BB03-3291A7070117}.Debug-MemCheck|Any CPU.ActiveCfg = Debug|Win32 … … 1266 1284 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Mixed Platforms.Build.0 = Debug|x64 1267 1285 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Win32.ActiveCfg = Debug|Win32 1268 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Win32.Build.0 = Debug|Win321269 1286 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|x64.ActiveCfg = Debug|x64 1270 1287 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|x64.Build.0 = Debug|x64 … … 1523 1540 {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|Mixed Platforms.Build.0 = Debug 1524 1541 {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|Win32.ActiveCfg = Debug 1525 {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|Win32.Build.0 = Debug1526 1542 {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|x64.ActiveCfg = Debug 1527 1543 {10A0052D-542B-47AD-85C3-1A3DD45BF2ED}.Debug|x64.Build.0 = Debug -
changelog
r3692371 r04f2743 5 5 * Improved socket performance (would be nice if we could be used as a "hub") 6 6 7 2009-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 15 2009-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 22 2009-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 28 2009-01-21 MickeM 29 + Added experimental 16 bit process support to checkProcState 30 7 31 2009-01-20 MickeM 8 32 * Fixed issue with CheckWMI when no filter was specified. … … 13 37 * 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) 14 38 * removed debug output from -noboot 15 + Added new command line option pdhmatchto use pattern matching on PDH queries39 + Added new command line pdhmatch option to use pattern matching on PDH queries 16 40 Usage: nsclient++ -noboot CheckSystem pdhmatch \Process(*)\Antal trådar 17 41 * Improved error reporting in the PDH subsystem. -
helpers/installer/Product.wxs
r3692371 r04f2743 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi"> 3 <?if def "$(var.boost)" ?>3 <?if "$(var.boost)" = "true" ?> 4 4 <?define PlatForm = "$(var.arch)" ?> 5 5 <?define Mode = "Nightly" ?> … … 19 19 <?define Mode = "Nightly" ?> 20 20 <?else?> 21 <?define PlatForm = "Unknown: $(var. SysTray.ConfigurationName)" ?>21 <?define PlatForm = "Unknown: $(var.boost)" ?> 22 22 <?endif?> 23 23 <?endif?> … … 90 90 </File> 91 91 <File Id="NSClientINI" Name="NSC.ini" LongName="NSC.ini" DiskId="1" Source="$(var.Path.ini)/NSC.ini" Vital="no"/> 92 <?if def "$(var.boost)" ?>92 <?if "$(var.boost)" = "true" ?> 93 93 <File Id="Changelog" Name="change.log" LongName="changelog.txt" DiskId="1" Source="$(var.Source)/changelog.txt" Vital="no"/> 94 94 <?else?> -
include/EnumProcess.cpp
r846bbe4 r04f2743 31 31 32 32 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 33 CEnumProcess::CEnumProcess() : PSAPI(NULL), VDMDBG(NULL), FVDMEnumTaskWOWEx(NULL) 34 { 37 35 PSAPI = ::LoadLibrary(_TEXT("PSAPI")); 38 36 if (PSAPI) 39 37 { 40 // Setup variables41 m_MAX_COUNT = 256;42 m_cProcesses = 0;43 m_cModules = 0;44 45 38 // Find PSAPI functions 46 39 FEnumProcesses = (PFEnumProcesses)::GetProcAddress(PSAPI, "EnumProcesses"); … … 53 46 } 54 47 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 } 60 54 } 61 55 62 56 CEnumProcess::~CEnumProcess() 63 57 { 64 delete [] lpString;65 if (m_pProcesses) {delete[] m_pProcesses;}66 if (m_pModules) {delete[] m_pModules;}67 58 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 62 struct find_16bit_container { 63 std::list<CEnumProcess::CProcessEntry> *target; 64 DWORD pid; 65 }; 66 BOOL 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 82 CEnumProcess::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])); 112 123 } 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 129 CEnumProcess::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); 164 155 } 165 166 if (!OK) return FALSE; 167 168 m_cModules = cbNeeded/sizeof(HMODULE); 169 return FillMStructPSAPI(dwPID, *m_pCurrentM, pEntry); 156 entry.filename = path; 170 157 } 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; 216 161 } 217 162 … … 233 178 MEMORY_BASIC_INFORMATION mbi; 234 179 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()); 236 181 LPBYTE lpBuffer = (LPBYTE)malloc (sysinfo.dwPageSize); 237 182 if (lpBuffer == NULL) 238 throw EnumProcException(_T("Failed to allocate buffer"));183 throw process_enumeration_exception(_T("Failed to allocate buffer")); 239 184 SIZE_T dwBytesRead; 240 185 if (!ReadProcessMemory( hProcess, mbi.BaseAddress, (LPVOID)lpBuffer, sysinfo.dwPageSize, &dwBytesRead)) { 241 186 free(lpBuffer); 242 throw EnumProcException(_T("ReadProcessMemory failed"), GetLastError());187 throw process_enumeration_exception(_T("ReadProcessMemory failed: ") + error::lookup::last_error()); 243 188 } 244 189 LPBYTE lpPos = lpPos = lpBuffer + ((DWORD)PROCESS_DATA_BLOCK_ADDRESS - (DWORD)mbi.BaseAddress); … … 271 216 } 272 217 273 274 BOOL CEnumProcess::FillPStructPSAPI(DWORD dwPID, CEnumProcess::CProcessEntry* pEntry)275 {276 pEntry->dwPID = dwPID;277 // Open process to get filename278 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 filename301 //GetModuleFileNameEx302 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 header349 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_lfanew353 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 39 39 typedef BOOL (WINAPI *PFEnumProcessModules)(HANDLE hProcess, HMODULE * lphModule, DWORD cb, LPDWORD lpcbNeeded); 40 40 typedef DWORD (WINAPI *PFGetModuleFileNameEx)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); 41 //typedef BOOL ( WINAPI *PROCESSENUMPROC )(DWORD dwProcessId, DWORD dwAttributes, LPARAM lpUserDefined ); 42 typedef BOOL ( WINAPI *TASKENUMPROCEX )(DWORD dwThreadId, WORD hMod16, WORD hTask16, PSZ pszModName, PSZ pszFileName, LPARAM lpUserDefined ); 43 typedef INT (WINAPI *PFVDMEnumTaskWOWEx)(DWORD dwProcessId, TASKENUMPROCEX fp, LPARAM lparam); 41 44 #else 42 45 // Functions loaded from PSAPI … … 44 47 typedef BOOL (WINAPI *PFEnumProcessModules)(HANDLE hProcess, HMODULE * lphModule, DWORD cb, LPDWORD lpcbNeeded); 45 48 typedef DWORD (WINAPI *PFGetModuleFileNameEx)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); 49 typedef BOOL ( WINAPI *TASKENUMPROCEX )(DWORD dwThreadId, WORD hMod16, WORD hTask16, PSZ pszModName, PSZ pszFileName, LPARAM lpUserDefined ); 50 typedef INT (WINAPI *PFVDMEnumTaskWOWEx)(DWORD dwProcessId, TASKENUMPROCEX fp, LPARAM lparam); 46 51 #endif 52 53 #define DEFAULT_BUFFER_SIZE 1024 47 54 48 55 class CEnumProcess … … 50 57 public: 51 58 52 class EnumProcException { 53 std::wstring error_; 59 class error_reporter { 54 60 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_; 61 70 } 62 71 }; 63 72 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 { 69 74 std::wstring filename; 70 75 std::wstring command_line; 71 76 DWORD dwPID; 72 // Constructors/Destructor73 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; }79 77 }; 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); 80 82 81 83 struct CModuleEntry … … 93 95 virtual ~CEnumProcess(); 94 96 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);100 97 std::wstring GetCommandLine(HANDLE hProcess); 98 bool has_PSAPI() { 99 return PSAPI != NULL; 100 } 101 101 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; 102 private: 113 103 114 104 // PSAPI related members 115 105 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; 120 107 // PSAPI related functions 121 108 PFEnumProcesses FEnumProcesses; // Pointer to EnumProcess 122 109 PFEnumProcessModules FEnumProcessModules; // Pointer to EnumProcessModules 123 110 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; 127 112 }; 128 113 -
include/checkHelpers.hpp
r3692371 r04f2743 31 31 typedef enum { warning, critical} ResultType; 32 32 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 }; 35 45 36 46 static std::wstring formatAbove(std::wstring str, ResultType what) { … … 48 58 return str + _T(" < critical"); 49 59 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"); 50 74 } 51 75 static std::wstring formatState(std::wstring str, ResultType what) { … … 107 131 return crit.gatherPerfData(getAlias(), value, warn, crit); 108 132 } 133 bool hasBounds() { 134 return warn.hasBounds() || crit.hasBounds(); 135 } 109 136 void runCheck(typename TContents::TValueType &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) { 110 137 std::wstring tstr; 111 138 if (crit.check(value, getAlias(), tstr, critical)) { 139 std::wcout << _T("crit") << std::endl; 112 140 NSCHelper::escalteReturnCodeToCRIT(returnCode); 113 141 } else if (warn.check(value, getAlias(), tstr, warning)) { 142 std::wcout << _T("warn") << std::endl; 114 143 NSCHelper::escalteReturnCodeToWARN(returnCode); 115 144 }else if (show == showLong) { 145 std::wcout << _T("long") << std::endl; 116 146 tstr = getAlias() + _T(": ") + TContents::toStringLong(value); 117 147 }else if (show == showShort) { 148 std::wcout << _T("short") << std::endl; 118 149 tstr = getAlias() + _T(": ") + TContents::toStringShort(value); 119 150 } 151 std::wcout << _T("result: ") << tstr << _T("--") << std::endl; 120 152 if (perfData) 121 153 perf += gatherPerfData(value); … … 124 156 if (!tstr.empty()) 125 157 message += tstr; 158 std::wcout << _T("result: ") << tstr << _T("--") << std::endl; 126 159 } 127 160 }; … … 750 783 751 784 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 752 880 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<int ,int>, int_handler> > MaxMinPercentageBoundsInteger; 753 881 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<__int64, __int64>, int64_handler> > MaxMinPercentageBoundsInt64; -
include/filter_framework.hpp
r3692371 r04f2743 338 338 } else if (value.substr(0,3) == _T("in:")) { 339 339 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); 340 348 } else { 341 349 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 57 57 else if (p__.first == (_T("MinCrit") postfix)) { obj.crit.min = p__.second; } 58 58 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 59 63 #define MAP_OPTIONS_PUSH_WTYPE(type, value, obj, list) \ 60 64 else if (p__.first == value) { type o; o.obj = p__.second; list.push_back(o); } -
modules/CheckDisk/CheckDisk.cpp
rc09c225 r04f2743 63 63 } 64 64 65 class error_reporter { 66 public: 67 virtual void report_error(std::wstring error) = 0; 68 virtual void report_warning(std::wstring error) = 0; 69 }; 70 71 65 72 struct 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_) {} 67 74 const WIN32_FIND_DATA wfd; 68 75 const std::wstring path; 76 error_reporter *errors; 69 77 }; 70 78 typedef std::unary_function<const file_finder_data&, bool> baseFinderFunction; … … 86 94 return error; 87 95 } 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); 89 99 error = true; 90 100 } … … 95 105 96 106 template <class finder_function> 97 void recursive_scan(std::wstring dir, finder_function & f ) {107 void recursive_scan(std::wstring dir, finder_function & f, error_reporter * errors) { 98 108 std::wstring baseDir; 99 109 std::wstring::size_type pos = dir.find_last_of('\\'); … … 106 116 if (hFind != INVALID_HANDLE_VALUE) { 107 117 do { 108 if (!f(file_finder_data(wfd, baseDir )))118 if (!f(file_finder_data(wfd, baseDir, errors))) 109 119 break; 110 120 if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) { 111 121 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); 113 123 } 114 124 } while (FindNextFile(hFind, &wfd)); 115 125 } else { 116 f.setError( _T("File not found"));126 f.setError(errors, _T("File not found")); 117 127 } 118 128 FindClose(hFind); … … 281 291 } 282 292 293 class 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 }; 283 301 284 302 … … 318 336 std::wstring sName = path.getAlias(); 319 337 get_size sizeFinder; 320 recursive_scan<get_size>(path.data, sizeFinder); 338 NSC_error errors; 339 recursive_scan<get_size>(path.data, sizeFinder, &errors); 321 340 if (sizeFinder.hasError()) { 322 message = _T("File not found ");341 message = _T("File not found check log for details"); 323 342 return NSCAPI::returnUNKNOWN; 324 343 } … … 416 435 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 417 436 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()); 419 438 return false; 420 439 } … … 427 446 return error; 428 447 } 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); 430 451 error = true; 431 452 } … … 453 474 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 454 475 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; 456 478 } 457 479 GetFileInformationByHandle(hFile, &_info); … … 488 510 return error; 489 511 } 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); 491 515 error = true; 492 516 } … … 523 547 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 524 548 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; 526 551 } 527 552 GetFileInformationByHandle(hFile, &_info); … … 568 593 return error; 569 594 } 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); 571 598 error = true; 572 599 } … … 596 623 } 597 624 598 recursive_scan<find_first_file_info>(path, finder); 625 NSC_error errors; 626 recursive_scan<find_first_file_info>(path, finder, &errors); 599 627 if (finder.hasError()) { 600 message = _T("File not found ");628 message = _T("File not found (check log for details)"); 601 629 return NSCAPI::returnUNKNOWN; 602 630 } … … 655 683 finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 656 684 finder.syntax = syntax; 685 NSC_error errors; 657 686 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); 659 688 if (finder.hasError()) { 660 message = _T("File not found: ") + (*pit) ;689 message = _T("File not found: ") + (*pit) + _T(" check log for details."); 661 690 return NSCAPI::returnUNKNOWN; 662 691 } … … 747 776 finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 748 777 finder.syntax = syntax; 778 NSC_error errors; 749 779 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); 751 781 if (finder.hasError()) { 752 message = _T("Error when scanning: ") + (*pit) ;782 message = _T("Error when scanning: ") + (*pit) + _T(" check log for details."); 753 783 return NSCAPI::returnUNKNOWN; 754 784 } -
modules/CheckEventLog/CheckEventLog.cpp
r3692371 r04f2743 495 495 if (command != _T("CheckEventLog")) 496 496 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 498 500 typedef std::pair<int,eventlog_filter> filteritem_type; 499 501 typedef std::list<filteritem_type > filterlist_type; … … 503 505 std::list<std::wstring> files; 504 506 filterlist_type filter_chain; 505 EventLogQueryContainer query; 507 EventLogQuery1Container query1; 508 EventLogQuery2Container query2; 506 509 507 510 bool bPerfData = true; … … 529 532 try { 530 533 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("")) 532 536 MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 533 537 MAP_OPTIONS_BOOL_TRUE(_T("unique"), unique) … … 579 583 } catch (filters::filter_exception e) { 580 584 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!"); 581 591 return NSCAPI::returnUNKNOWN; 582 592 } … … 727 737 } 728 738 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 } 734 755 if ((truncate > 0) && (message.length() > (truncate-4))) 735 756 message = message.substr(0, truncate-4) + _T("..."); 736 757 if (message.empty()) 737 758 message = _T("Eventlog check ok"); 738 NSC_DEBUG_MSG_STD(_T("Result: ") + message) ;739 759 return returnCode; 740 760 } -
modules/CheckHelpers/CheckHelpers.cpp
rc165d1d r04f2743 89 89 return NSCAPI::returnOK; 90 90 } else if (command == _T("CheckVersion")) { 91 msg = SZVERSION;91 msg = NSCModuleHelper::getApplicationVersionString(); 92 92 return NSCAPI::returnOK; 93 93 } else if (command == _T("CheckOK")) { -
modules/CheckSystem/CheckSystem.cpp
r3692371 r04f2743 53 53 * @return 54 54 */ 55 CheckSystem::CheckSystem() : p rocessMethod_(0), pdhThread(_T("pdhThread")) {}55 CheckSystem::CheckSystem() : pdhThread(_T("pdhThread")) {} 56 56 /** 57 57 * Default d-tor … … 66 66 bool CheckSystem::loadModule() { 67 67 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 }110 68 try { 111 69 NSCModuleHelper::registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer.")); … … 691 649 msg = msg.substr(0, truncate-4) + _T("..."); 692 650 if (msg.empty() && returnCode == NSCAPI::returnOK) 693 msg = _T("OK: All services are in their ap ropriate state.");651 msg = _T("OK: All services are in their appropriate state."); 694 652 else if (msg.empty()) 695 653 msg = NSCHelper::translateReturn(returnCode) + _T(": Whooha this is odd."); … … 828 786 } NSPROCDATA; 829 787 typedef std::map<std::wstring,NSPROCDATA,strEx::case_blind_string_compare> NSPROCLST; 788 789 class 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 830 798 /** 831 799 * Get a hash_map with all running processes. 832 800 * @return a hash_map with all running processes 833 801 */ 834 NSPROCLST GetProcessList( int processMethod, bool getCmdLines)802 NSPROCLST GetProcessList(bool getCmdLines, bool use16Bit) 835 803 { 836 804 NSPROCLST ret; 837 if (processMethod == 0) {838 NSC_LOG_ERROR_STD(_T("ProcessMethod not defined or not available."));839 return ret;840 }841 805 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) { 851 815 std::wstring key; 852 if (getCmdLines )853 key = entry.command_line;816 if (getCmdLines && !(*entry).command_line.empty()) 817 key = (*entry).command_line; 854 818 else 855 key = entry.filename;819 key = (*entry).filename; 856 820 NSPROCLST::iterator it = ret.find(key); 857 821 if (it == ret.end()) { 858 ret[key].entry = entry;822 ret[key].entry = (*entry); 859 823 ret[key].count = 1; 860 824 ret[key].key = key; … … 888 852 StateContainer tmpObject; 889 853 bool bPerfData = true; 854 bool use16bit = false; 890 855 bool useCmdLine = false; 891 856 typedef enum { … … 906 871 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 907 872 MAP_OPTIONS_BOOL_TRUE(_T("cmdLine"), useCmdLine) 873 MAP_OPTIONS_BOOL_TRUE(_T("16bit"), use16bit) 908 874 MAP_OPTIONS_MODE(_T("match"), _T("string"), match, match_string) 909 875 MAP_OPTIONS_MODE(_T("match"), _T("regexp"), match, match_regexp) … … 930 896 NSPROCLST runningProcs; 931 897 try { 932 runningProcs = GetProcessList( processMethod_, useCmdLine);933 } catch (CEnumProcess:: EnumProcExceptione) {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(); 936 902 return NSCAPI::returnUNKNOWN; 937 903 } catch (...) { -
modules/CheckSystem/CheckSystem.h
r99e4d8f r04f2743 30 30 private: 31 31 CheckMemory memoryChecker; 32 int processMethod_;33 32 PDHCollectorThread pdhThread; 34 33 -
modules/DebugLogMetrics/DebugLogMetrics.cpp
r3692371 r04f2743 60 60 return false; 61 61 } 62 62 /* 63 63 void getMetricsForPid(DWORD pid) { 64 64 HANDLE hProcModule = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid ); … … 82 82 83 83 } 84 */ 84 85 85 86 NSCAPI::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 374 374 strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 375 375 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_); 377 377 } 378 378 std::wstring msg, perf;
Note: See TracChangeset
for help on using the changeset viewer.








