Changeset b749b8d in nscp
- Timestamp:
- 11/04/07 17:35:28 (6 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 22d2739
- Parents:
- 12edcec
- Files:
-
- 20 edited
-
AutoBuild.h (modified) (1 diff)
-
NSClient++.cpp (modified) (3 diffs)
-
NSClient++.h (modified) (1 diff)
-
NSClient++.sln (modified) (1 diff)
-
changelog (modified) (1 diff)
-
include/PDHCounter.h (modified) (1 diff)
-
include/ServiceCmd.cpp (modified) (1 diff)
-
include/Socket.h (modified) (1 diff)
-
include/checkHelpers.hpp (modified) (2 diffs)
-
include/filter_framework.hpp (modified) (3 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (3 diffs)
-
modules/CheckDisk/CheckDisk.h (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (1 diff)
-
modules/CheckWMI/CheckWMI.cpp (modified) (4 diffs)
-
modules/CheckWMI/CheckWMI.h (modified) (1 diff)
-
modules/CheckWMI/CheckWMI.vcproj (modified) (1 diff)
-
modules/CheckWMI/WMIQuery.cpp (modified) (2 diffs)
-
modules/CheckWMI/WMIQuery.h (modified) (2 diffs)
-
modules/CheckWMI/stdafx.h (modified) (1 diff)
-
modules/NRPEListener/NRPEListener.vcproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
r12edcec rb749b8d 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,2,7,4 16 #define PRODUCTVER 0,2,7,1 397 #define STRFILEVER "0.2.7.4 1"8 #define STRPRODUCTVER "0.2.7.1 39"9 #define STRPRODUCTDATE "2007-11-0 3"5 #define FILEVER 0,2,7,42 6 #define PRODUCTVER 0,2,7,140 7 #define STRFILEVER "0.2.7.42" 8 #define STRPRODUCTVER "0.2.7.140" 9 #define STRPRODUCTDATE "2007-11-04" 10 10 #endif // AUTOBUILD_H -
NSClient++.cpp
r12edcec rb749b8d 113 113 #endif 114 114 g_bConsoleLog = true; 115 mainClient.enableDebug(true); 115 116 if (!mainClient.InitiateService()) { 116 117 LOG_ERROR_STD("Service *NOT* started!"); … … 166 167 * When the program is started as a service this will be the entry point. 167 168 */ 168 bool NSClientT::InitiateService( void) {169 bool NSClientT::InitiateService() { 169 170 try { 170 171 Settings::getInstance()->setFile(getBasePath(), "NSC.ini"); … … 173 174 return false; 174 175 } 176 if (debug_) { 177 Settings::getInstance()->setInt("log", "debug", 1); 178 } 179 175 180 try { 176 181 simpleSocket::WSAStartup(); -
NSClient++.h
r12edcec rb749b8d 66 66 MutexHandler messageMutex; 67 67 MutexRW m_mutexRW; 68 bool debug_; 68 69 69 70 public: 70 71 // c-tor, d-tor 71 NSClientT(void) {}72 NSClientT(void) : debug_(false) {} 72 73 virtual ~NSClientT(void) {} 74 void enableDebug(bool debug = true) { 75 debug_ = debug; 76 } 73 77 74 78 // Service helper functions 75 bool InitiateService( void);79 bool InitiateService(); 76 80 void TerminateService(void); 77 81 static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv); -
NSClient++.sln
r12edcec rb749b8d 132 132 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Mixed Platforms.Build.0 = Debug|x64 133 133 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Win32.ActiveCfg = Debug|Win32 134 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Win32.Build.0 = Debug|Win32135 134 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|x64.ActiveCfg = Debug|x64 136 135 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|x64.Build.0 = Debug|x64 -
changelog
r478588b rb749b8d 8 8 * Fix PDH problems 9 9 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 10 11 2007-11-04 MickeM 12 * Rewritten WMI handling as well as checks so things should be more usefull now (cf. the wiki page for details) 10 13 11 14 2007-10-29 MickeM -
include/PDHCounter.h
r4001502 rb749b8d 210 210 211 211 PDHCounter* addCounter(std::string name, PDHCounterListener *listener) { 212 std::cout << "Adding counter: " << name << std::endl;212 //std::cout << "Adding counter: " << name << std::endl; 213 213 PDHCounter *counter = new PDHCounter(name, listener); 214 214 counters_.push_back(counter); -
include/ServiceCmd.cpp
r478588b rb749b8d 18 18 #include "ServiceCmd.h" 19 19 #include <strEx.h> 20 #include <tchar.h> 20 21 #include <iostream> 21 22 -
include/Socket.h
r478588b rb749b8d 35 35 public: 36 36 SocketException(std::string error) : error_(error) {} 37 SocketException(std::string error, int errorCode) : error_(error) {38 error_ += strEx::itos(errorCode);37 SocketException(std::string error, unsigned int errorCode) : error_(error) { 38 error_ += error::format::from_system(errorCode); 39 39 } 40 40 std::string getMessage() const { -
include/checkHelpers.hpp
rdc65e35 rb749b8d 34 34 35 35 36 st d::string formatAbove(std::string str, ResultType what) {36 static std::string formatAbove(std::string str, ResultType what) { 37 37 if (what == warning) 38 38 return str + " > warning"; … … 42 42 } 43 43 44 st d::string formatBelow(std::string str, ResultType what) {44 static std::string formatBelow(std::string str, ResultType what) { 45 45 if (what == warning) 46 46 return str + " < warning"; -
include/filter_framework.hpp
ra6aaf0a rb749b8d 22 22 23 23 #include <strEx.h> 24 #include <checkHelpers.hpp> 24 25 25 26 namespace filters { … … 297 298 inList = value.substr(3); 298 299 } else { 299 throw parse_exception("Unknown filter key: " + value );300 throw parse_exception("Unknown filter key: " + value + " (numeric filters have to have an operator as well ie. foo=>5 or bar==5)"); 300 301 } 301 302 return *this; … … 303 304 }; 304 305 typedef filter_all_numeric<unsigned long long, checkHolders::time_handler<unsigned long long> > filter_all_times; 306 307 template <typename TFilterType, typename TValueType> 308 struct chained_filter { 309 enum filter_mode { 310 plus = 1, 311 minus = 2, 312 normal = 3, 313 }; 314 typedef std::pair<filter_mode,TFilterType> filteritem_type; 315 typedef std::list<filteritem_type> filterlist_type; 316 317 filterlist_type chain; 318 bool filterAll; 319 320 chained_filter() : filterAll(false) {} 321 322 void push_filter(std::string key, TFilterType filter) { 323 filter_mode mode = normal; 324 if (key.substr(0,1) == "+") 325 mode = plus; 326 if (key.substr(0,1) == "-") 327 mode = minus; 328 chain.push_back(filteritem_type(mode, filter)); 329 } 330 331 bool hasFilter() { 332 return !chain.empty(); 333 } 334 bool get_inital_state() { 335 return filterAll; 336 } 337 338 bool match(bool state, const TValueType item) { 339 bool matched = state; 340 for (filterlist_type::const_iterator cit = chain.begin(); cit != chain.end(); ++cit ) { 341 int mode = (*cit).first; 342 bool bTmpMatched = (*cit).second.matchFilter(item); 343 if ((mode == minus)&&(bTmpMatched)) { 344 // a -<filter> hit so thrash result! 345 matched = false; 346 break; 347 } else if ((mode == plus)&&(!bTmpMatched)) { 348 // a +<filter> missed hit so thrash result! 349 matched = false; 350 break; 351 } else if (bTmpMatched) { 352 matched = true; 353 } 354 } 355 return matched; 356 } 357 358 }; 359 360 305 361 } -
modules/CheckDisk/CheckDisk.cpp
r5b40546 rb749b8d 217 217 218 218 if ((!bFilter)&&!((drvType == DRIVE_FIXED)||(drvType == DRIVE_NO_ROOT_DIR))) { 219 message = "UNKNOWN: Drive is not a fixed drive: " + drive.getAlias() + " (it is a : " + strEx::itos(drvType) + ")";219 message = "UNKNOWN: Drive is not a fixed drive: " + drive.getAlias() + " (it is a " + get_filter(drvType) + " drive)"; 220 220 return NSCAPI::returnUNKNOWN; 221 221 } else if ( (bFilter)&&( (!bFilterFixed)&&((drvType==DRIVE_FIXED)||(drvType==DRIVE_NO_ROOT_DIR))) || … … 223 223 ((!bFilterRemote)&&(drvType==DRIVE_REMOTE)) || 224 224 ((!bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) ) { 225 message = "UNKNOWN: Drive does not match the current filter: " + drive.getAlias() + " (it is a : " + strEx::itos(drvType) + ")";225 message = "UNKNOWN: Drive does not match the current filter: " + drive.getAlias() + " (it is a " + get_filter(drvType) + " drive)"; 226 226 return NSCAPI::returnUNKNOWN; 227 227 } … … 255 255 message = NSCHelper::translateReturn(returnCode) + ": " + message; 256 256 return returnCode; 257 } 258 259 std::string CheckDisk::get_filter(unsigned int drvType) { 260 if (drvType==DRIVE_FIXED) 261 return "fixed"; 262 if (drvType==DRIVE_NO_ROOT_DIR) 263 return "no_root"; 264 if (drvType==DRIVE_CDROM) 265 return "cdrom"; 266 if (drvType==DRIVE_REMOTE) 267 return "remote"; 268 if (drvType==DRIVE_REMOVABLE) 269 return "removable"; 270 return "unknown: " + strEx::itos(drvType); 257 271 } 258 272 -
modules/CheckDisk/CheckDisk.h
rdc65e35 rb749b8d 48 48 bool hasCommandHandler(); 49 49 bool hasMessageHandler(); 50 std::string get_filter(unsigned int drvType); 50 51 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 51 52 -
modules/CheckEventLog/CheckEventLog.cpp
r4001502 rb749b8d 301 301 302 302 for (std::list<std::string>::const_iterator cit2 = files.begin(); cit2 != files.end(); ++cit2) { 303 std::cout << "Opening: " << (*cit2) << std::endl;304 303 HANDLE hLog = OpenEventLog(NULL, (*cit2).c_str()); 305 304 if (hLog == NULL) { -
modules/CheckWMI/CheckWMI.cpp
rdc65e35 rb749b8d 57 57 58 58 59 #define MAP_CHAINED_FILTER(value, obj) \ 60 else if (p__.first.length() > 8 && p__.first.substr(1,6) == "filter" && p__.first.substr(7,1) == "-" && p__.first.substr(8) == value) { \ 61 WMIQuery::wmi_filter filter; filter.obj = p__.second; chain.push_filter(p__.first, filter); } 62 63 #define MAP_SECONDARY_CHAINED_FILTER(value, obj) \ 64 else if (p2.first.length() > 8 && p2.first.substr(1,6) == "filter" && p2.first.substr(7,1) == "-" && p2.first.substr(8) == value) { \ 65 WMIQuery::wmi_filter filter; filter.obj = p__.second; filter.alias = p2.second; chain.push_filter(p__.first, filter); } 66 67 #define MAP_CHAINED_FILTER_STRING(value) \ 68 MAP_CHAINED_FILTER(value, string) 69 70 #define MAP_CHAINED_FILTER_NUMERIC(value) \ 71 MAP_CHAINED_FILTER(value, numeric) 59 72 60 73 NSCAPI::nagiosReturn CheckWMI::CheckSimpleWMI(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { … … 62 75 63 76 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 77 typedef filters::chained_filter<WMIQuery::wmi_filter,WMIQuery::wmi_row> filter_chain; 78 filter_chain chain; 64 79 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 65 80 if (args.empty()) { … … 67 82 return NSCAPI::returnCRIT; 68 83 } 84 unsigned int truncate = 0; 85 std::string query, alias; 86 bool bPerfData = true; 69 87 70 WMIConatiner tmpObject; 71 std::list<WMIConatiner> queries; 72 73 MAP_OPTIONS_BEGIN(args) 74 MAP_OPTIONS_STR_AND("Query", tmpObject.data, queries.push_back(tmpObject)) 75 MAP_OPTIONS_NUMERIC_ALL(tmpObject, "") 76 MAP_OPTIONS_SHOWALL(tmpObject) 88 WMIConatiner result_query; 89 try { 90 MAP_OPTIONS_BEGIN(args) 91 MAP_OPTIONS_STR("Query", query) 92 MAP_OPTIONS_STR2INT("truncate", truncate) 93 MAP_OPTIONS_STR("Alias", alias) 94 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 95 MAP_OPTIONS_NUMERIC_ALL(result_query, "") 96 MAP_OPTIONS_SHOWALL(result_query) 97 MAP_CHAINED_FILTER("string",string) 98 MAP_CHAINED_FILTER("numeric",numeric) 77 99 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 78 else if (p2.first == "Query") { 79 tmpObject.data = p__.second; 80 tmpObject.alias = p2.second; 81 queries.push_back(tmpObject); 82 } 100 MAP_SECONDARY_CHAINED_FILTER("string",string) 101 MAP_SECONDARY_CHAINED_FILTER("numeric",numeric) 102 else if (p2.first == "Query") { 103 query = p__.second; 104 alias = p2.second; 105 } 83 106 MAP_OPTIONS_MISSING_EX(p2, message, "Unknown argument: ") 84 107 MAP_OPTIONS_SECONDARY_END() 85 MAP_OPTIONS_FALLBACK_AND(tmpObject.data, queries.push_back(tmpObject)) 86 MAP_OPTIONS_END() 108 MAP_OPTIONS_END() 109 } catch (filters::parse_exception e) { 110 message = "WMIQuery failed: " + e.getMessage(); 111 return NSCAPI::returnCRIT; 112 } 87 113 88 for (std::list<WMIConatiner>::const_iterator pit = queries.begin();pit!=queries.end();++pit) { 89 WMIConatiner query = (*pit); 90 std::map<std::string,int> vals; 91 try { 92 vals = wmiQuery.execute(query.data); 93 } catch (WMIException e) { 94 message = "WMIQuery failed..."; 95 return NSCAPI::returnCRIT; 114 WMIQuery::result_type rows; 115 try { 116 rows = wmiQuery.execute(query); 117 } catch (WMIException e) { 118 message = "WMIQuery failed: " + e.getMessage(); 119 return NSCAPI::returnCRIT; 120 } 121 int hit_count = 0; 122 123 bool match = chain.get_inital_state(); 124 for (WMIQuery::result_type::iterator citRow = rows.begin(); citRow != rows.end(); ++citRow) { 125 WMIQuery::wmi_row vals = *citRow; 126 match = chain.match(match, vals); 127 if (match) { 128 strEx::append_list(message, vals.render()); 129 hit_count++; 96 130 } 97 int val = 0; //(*vals.begin()).second;131 } 98 132 99 for (std::map<std::string,int>::const_iterator it = vals.begin(); it != vals.end(); ++it) { 100 std::cout << "Values: " << (*it).first << " = " << (*it).second << std::endl; 101 } 102 103 query.setDefault(tmpObject); 104 query.runCheck(val, returnCode, message, perf); 105 } 133 if (!bPerfData) 134 result_query.perfData = false; 135 result_query.runCheck(hit_count, returnCode, message, perf); 136 if ((truncate > 0) && (message.length() > (truncate-4))) 137 message = message.substr(0, truncate-4) + "..."; 106 138 if (message.empty()) 107 message = "OK: Queries within bounds.";139 message = "OK: WMI Query returned no results."; 108 140 return returnCode; 109 141 } 110 142 143 NSCAPI::nagiosReturn CheckWMI::CheckSimpleWMIValue(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 144 message = "Not yet implemented :("; 145 return NSCAPI::returnCRIT; 146 } 111 147 112 148 … … 114 150 if (command == "CheckWMI") { 115 151 return CheckSimpleWMI(argLen, char_args, msg, perf); 152 } else if (command == "CheckWMIValue") { 153 return CheckSimpleWMIValue(argLen, char_args, msg, perf); 116 154 } 117 155 return NSCAPI::returnIgnored; -
modules/CheckWMI/CheckWMI.h
rdc65e35 rb749b8d 54 54 // Check commands 55 55 NSCAPI::nagiosReturn CheckSimpleWMI(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 56 NSCAPI::nagiosReturn CheckSimpleWMIValue(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 57 56 58 57 59 -
modules/CheckWMI/CheckWMI.vcproj
r0bc9fdd rb749b8d 996 996 </File> 997 997 <File 998 RelativePath="..\..\include\filter_framework.hpp" 999 > 1000 </File> 1001 <File 998 1002 RelativePath="..\..\include\NSCHelper.h" 999 1003 > -
modules/CheckWMI/WMIQuery.cpp
rdc65e35 rb749b8d 39 39 bool WMIQuery::initialize() 40 40 { 41 if (CoInitialize(NULL) != S_OK) 42 return false; 43 bInitialized = true; 44 if(CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_PKT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,0,0) != S_OK) { 41 NSC_LOG_ERROR_STD("Attempting Inialized WMI component"); 42 43 HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); 44 if (FAILED(hRes)) { 45 NSC_LOG_ERROR_STD("CoInitialize failed: " + error::format::from_system(hRes)); 45 46 return false; 46 47 } 48 bInitialized = true; 49 hRes = CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_PKT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL); 50 if (FAILED(hRes)) { 51 NSC_LOG_ERROR_STD("CoInitializeSecurity failed: " + error::format::from_system(hRes)); 52 return false; 53 } 54 55 NSC_LOG_ERROR_STD("Inialized WMI component"); 47 56 return true; 48 57 } … … 54 63 55 64 56 std::map<std::string,int>WMIQuery::execute(std::string query)65 WMIQuery::result_type WMIQuery::execute(std::string query) 57 66 { 58 std::map<std::string,int> ret; 59 IWbemLocator * pIWbemLocator = NULL; 67 if (!bInitialized) { 68 initialize(); 69 } 70 result_type ret; 71 72 CComPtr< IWbemLocator > locator; 73 HRESULT hr = CoCreateInstance( CLSID_WbemAdministrativeLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast< void** >( &locator ) ); 74 if (FAILED(hr)) { 75 throw WMIException("CoCreateInstance for CLSID_WbemAdministrativeLocator failed!", hr); 76 } 77 60 78 BSTR bstrNamespace = (L"root\\cimv2"); 61 //BSTR bstrNamespace = (L"root\\default"); 62 HRESULT hRes = CoCreateInstance(CLSID_WbemAdministrativeLocator,NULL,CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, 63 IID_IUnknown,(void**)&pIWbemLocator); 64 if (FAILED(hRes)) { 65 throw WMIException("CoCreateInstance for CLSID_WbemAdministrativeLocator failed!", hRes); 66 } 67 IWbemServices * pWbemServices = NULL; 68 hRes = pIWbemLocator->ConnectServer(bstrNamespace,NULL,NULL,NULL,0,NULL,NULL,&pWbemServices); 69 if (FAILED(hRes)) { 70 pIWbemLocator->Release(); 71 pIWbemLocator = NULL; 72 throw WMIException("ConnectServer failed!", hRes); 79 CComPtr< IWbemServices > service; 80 hr = locator->ConnectServer( bstrNamespace, NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &service ); 81 if (FAILED(hr)) { 82 throw WMIException("ConnectServer failed!", hr); 73 83 } 74 84 CComBSTR strQuery(query.c_str()); 75 85 BSTR strQL = (L"WQL"); 76 IEnumWbemClassObject * pEnumObject = NULL; 77 hRes = pWbemServices->ExecQuery(strQL, strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject); 78 if (FAILED(hRes)) { 79 pWbemServices->Release(); 80 pIWbemLocator->Release(); 81 pIWbemLocator = NULL; 82 throw WMIException("ExecQuery failed:" + query, hRes); 83 } 84 hRes = pEnumObject->Reset(); 85 if (FAILED(hRes)) { 86 pWbemServices->Release(); 87 pIWbemLocator->Release(); 88 pIWbemLocator = NULL; 89 throw WMIException("ExecQuery failed:" + query, hRes); 90 } 91 ULONG uCount = 1, uReturned; 92 IWbemClassObject * pClassObject = NULL; 93 hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned); 94 if (FAILED(hRes)) { 95 pWbemServices->Release(); 96 pIWbemLocator->Release(); 97 pIWbemLocator = NULL; 98 throw WMIException("ExecQuery failed!" + query, hRes); 86 87 CComPtr< IEnumWbemClassObject > enumerator; 88 hr = service->ExecQuery( strQL, strQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &enumerator ); 89 if (FAILED(hr)) { 90 throw WMIException("ExecQuery failed:" + query + " (reason is: " + ComError::getComError() + ")", hr); 99 91 } 100 92 93 CComPtr< IWbemClassObject > row = NULL; 94 ULONG retcnt; 95 int i=0; 96 while (hr = enumerator->Next( WBEM_INFINITE, 1L, &row, &retcnt ) == WBEM_S_NO_ERROR) { 97 if (SUCCEEDED(hr)) { 98 if (retcnt > 0) { 99 SAFEARRAY* pstrNames; 100 wmi_row returnRow; 101 hr = row->GetNames(NULL,WBEM_FLAG_ALWAYS|WBEM_FLAG_NONSYSTEM_ONLY,NULL,&pstrNames); 102 if (FAILED(hr)) { 103 throw WMIException("GetNames failed:" + query, hr); 104 } 101 105 102 SAFEARRAY* pstrNames; 103 hRes = pClassObject->GetNames(NULL,WBEM_FLAG_ALWAYS|WBEM_FLAG_NONSYSTEM_ONLY,NULL,&pstrNames); 104 if (FAILED(hRes)) { 105 pClassObject->Release(); 106 pWbemServices->Release(); 107 pIWbemLocator->Release(); 108 throw WMIException("GetNames failed!" + query, hRes); 106 long index = 0, begin, end; 107 CComSafeArray<BSTR> arr = pstrNames; 108 begin = arr.GetLowerBound(); 109 end = arr.GetUpperBound(); 110 for ( index = begin; index <= end; index++ ) { 111 USES_CONVERSION; 112 CComBSTR bColumn = arr.GetAt(index); 113 std::string column = OLE2T(bColumn); 114 CComVariant vValue; 115 hr = row->Get(bColumn, 0, &vValue, 0, 0); 116 if (FAILED(hr)) { 117 throw WMIException("Failed to get value for " + column + " in query: " + query, hr); 118 } 119 WMIResult value; 120 121 if (vValue.vt == VT_INT) { 122 value.setNumeric(column, vValue.intVal); 123 } else if (vValue.vt == VT_I4) { 124 value.setNumeric(column, vValue.lVal); 125 } else if (vValue.vt == VT_UINT) { 126 value.setNumeric(column, vValue.uintVal); 127 } else if (vValue.vt == VT_BSTR) { 128 value.setString(column, OLE2T(vValue.bstrVal)); 129 } else if (vValue.vt == VT_NULL) { 130 value.setString(column, "NULL"); 131 } else if (vValue.vt == VT_BOOL) { 132 value.setBoth(column, vValue.iVal, vValue.iVal?"TRUE":"FALSE"); 133 } else { 134 NSC_LOG_ERROR_STD(column + " is not supported (type-id: " + strEx::itos(vValue.vt) + ")"); 135 } 136 returnRow.addValue(column, value); 137 } 138 ret.push_back(returnRow); 139 } 140 } 141 row.Release(); 109 142 } 110 CComSafeArray<BSTR> arr = pstrNames;111 long index = 0, begin, end;112 begin = arr.GetLowerBound();113 end = arr.GetUpperBound();114 for ( index = begin; index <= end; index++ ) {115 BSTR bStr = arr.GetAt(index);116 CString str = bStr;117 std::string std_str = str;118 CComVariant vValue;119 hRes = pClassObject->Get(bStr, 0, &vValue, 0, 0);120 if (vValue.vt == VT_INT) {121 ret[std_str] = vValue.intVal;122 //std::cout << (LPCTSTR)str << " = (INT) " << vValue.intVal << std::endl;123 } else if (vValue.vt == VT_I4) {124 ret[std_str] = vValue.lVal;125 //std::cout << (LPCTSTR)str << " = (I4) " << vValue.lVal << std::endl;126 } else if (vValue.vt == VT_UINT) {127 ret[std_str] = vValue.uintVal;128 //std::cout << (LPCTSTR)str << " = (UINT) " << vValue.uintVal << std::endl;129 } else if (vValue.vt == VT_BSTR) {130 std::cout << (LPCTSTR)str << " = UNSUPPORTED (BSTR)" << std::endl;131 CString val = vValue;132 //ret[std_str] = std::string(val);133 } else {134 std::cout << (LPCTSTR)str << " = UNSUPPORTED" << vValue.vt << std::endl;135 }136 }137 pIWbemLocator->Release();138 pWbemServices->Release();139 pEnumObject->Release();140 pClassObject->Release();141 143 return ret; 142 144 } -
modules/CheckWMI/WMIQuery.h
rdc65e35 rb749b8d 23 23 #include <string> 24 24 #include <map> 25 #include <strEx.h> 26 #include <error.hpp> 27 #define NO_BOOST_DEP 28 #include <filter_framework.hpp> 25 29 30 class ComError { 31 public: 32 static std::string getComError() { 33 USES_CONVERSION; 34 CComPtr<IErrorInfo> errorInfo; 35 HRESULT hr = GetErrorInfo(NULL, &errorInfo); 36 if (FAILED(hr)) 37 return "unknown error: " + error::format::from_system(hr); 38 CComBSTR bDesc, bSource; 39 hr = errorInfo->GetSource(&bSource); 40 if (FAILED(hr)) 41 return "unknown error: " + error::format::from_system(hr); 42 hr = errorInfo->GetDescription(&bDesc); 43 if (FAILED(hr)) 44 return "unknown error: " + error::format::from_system(hr); 45 std::string ret = OLE2T(bSource); 46 ret += " - "; 47 ret += OLE2T(bDesc); 48 return ret; 49 } 50 }; 26 51 27 52 class WMIException { 53 std::string message_; 28 54 public: 29 55 WMIException(std::string str, HRESULT code) { 30 std::cout << str << std::endl; 31 56 message_ = str + ":" + error::format::from_system(code); 57 } 58 std::string getMessage() { 59 return message_; 32 60 } 33 61 }; … … 38 66 39 67 public: 68 struct WMIResult { 69 std::string alias; 70 std::string string; 71 long long numeric; 72 bool isNumeric; 73 WMIResult() : isNumeric(false), numeric(0) {} 74 void setString(std::string a, std::string s) { 75 string = s; 76 numeric = 0; 77 alias = a; 78 } 79 void setNumeric(std::string a, long long n) { 80 numeric = n; 81 string = strEx::itos(n); 82 alias = a; 83 } 84 void setBoth(std::string a, long long n, std::string s) { 85 numeric = n; 86 string = s; 87 alias = a; 88 } 89 }; 90 struct wmi_row { 91 typedef std::map<std::string,WMIResult> list_type; 92 list_type results; 93 boolean hasAlias(std::string alias) const { 94 if (alias.empty()) 95 return true; 96 return results.find(alias) != results.end(); 97 } 98 const WMIResult get(std::string alias) const { 99 WMIResult ret; 100 list_type::const_iterator cit = results.find(alias); 101 if (cit != results.end()) 102 ret = (*cit).second; 103 return ret; 104 } 105 void addValue(std::string column, WMIResult value) { 106 results[column] = value; 107 } 108 109 std::string render() { 110 std::string ret; 111 for (list_type::const_iterator it = results.begin(); it != results.end(); ++it) { 112 if (!ret.empty()) ret += ", "; 113 ret += (*it).first + "=" + (*it).second.string; 114 } 115 return ret; 116 } 117 118 }; 119 typedef std::list<wmi_row> result_type; 120 struct wmi_filter { 121 std::string alias; 122 filters::filter_all_strings string; 123 filters::filter_all_numeric<unsigned long long, checkHolders::int64_handler > numeric; 124 125 inline bool hasFilter() { 126 return string.hasFilter() || numeric.hasFilter(); 127 } 128 bool matchFilter(const wmi_row &value) const { 129 if (!value.hasAlias(alias)) { 130 NSC_DEBUG_MSG_STD("We don't have any column matching: " + alias); 131 return false; 132 } 133 if (alias.empty()) { 134 for (wmi_row::list_type::const_iterator cit = value.results.begin(); cit != value.results.end(); ++cit) { 135 if ((string.hasFilter())&&(string.matchFilter((*cit).second.string))) 136 return true; 137 else if ((numeric.hasFilter())&&(numeric.matchFilter((*cit).second.numeric))) 138 return true; 139 } 140 } else { 141 if ((string.hasFilter())&&(string.matchFilter(value.get(alias).string))) 142 return true; 143 else if ((numeric.hasFilter())&&(numeric.matchFilter(value.get(alias).numeric))) 144 return true; 145 } 146 NSC_DEBUG_MSG_STD("Value did not match a filter: " + alias); 147 return false; 148 } 149 }; 40 150 WMIQuery(void); 41 151 ~WMIQuery(void); 42 152 43 std::map<std::string,int>execute(std::string query);153 result_type execute(std::string query); 44 154 45 155 bool initialize(); -
modules/CheckWMI/stdafx.h
r12edcec rb749b8d 32 32 #define _WIN32_DCOM 33 33 #include <objbase.h> 34 34 35 #include <NSCAPI.h> 35 36 #include <NSCHelper.h> 37 #define NO_BOOST_DEP 38 #include <checkHelpers.hpp> 39 #include <filter_framework.hpp> 36 40 37 41 #include <atlbase.h> 38 #include <atlcom.h>39 #include <atlstr.h>42 //#include <atlcom.h> 43 //#include <atlstr.h> 40 44 #include <atlsafe.h> 41 45 -
modules/NRPEListener/NRPEListener.vcproj
r12edcec rb749b8d 1149 1149 </File> 1150 1150 <File 1151 RelativePath="..\..\include\error.hpp" 1152 > 1153 </File> 1154 <File 1151 1155 RelativePath=".\NRPEListener.h" 1152 1156 >
Note: See TracChangeset
for help on using the changeset viewer.








