Changeset c1810e3 in nscp
- Timestamp:
- 08/03/12 00:02:45 (10 months ago)
- Branches:
- master, 0.4.1, 0.4.2
- Children:
- 6aac723
- Parents:
- b611d99
- Files:
-
- 9 edited
-
changelog (modified) (1 diff)
-
include/pdh/core.hpp (modified) (3 diffs)
-
include/settings/client/settings_client.hpp (modified) (1 diff)
-
include/socket/server.hpp (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (1 diff)
-
modules/CheckSystem/CMakeLists.txt (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (3 diffs)
-
modules/CheckSystem/CheckSystem.h (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
rb611d99 rc1810e3 4 4 * Fix dependonservice LanManWorkStation (old win) 5 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-08-02 MickeM 8 * major improvments to the CheckSystem command line syntax: 9 Run: "nscp sys" to get help. 10 A good way to validate your CheckSystem issues are running the following: 11 nscp sys --validate 6 12 7 13 2012-08-02 MickeM -
include/pdh/core.hpp
rd6c3131 rc1810e3 37 37 bool more_data_; 38 38 bool negative_denominator_; 39 long status_; 39 40 public: 40 41 /* … … 43 44 */ 44 45 PDHError() : error_(false), more_data_(false), negative_denominator_(false) {} 45 PDHError(PDH_STATUS status) : error_(status!=ERROR_SUCCESS), more_data_(status==PDH_MORE_DATA), negative_denominator_(status==PDH_CALC_NEGATIVE_DENOMINATOR)46 PDHError(PDH_STATUS status) : status_(status), error_(status!=ERROR_SUCCESS), more_data_(status==PDH_MORE_DATA), negative_denominator_(status==PDH_CALC_NEGATIVE_DENOMINATOR) 46 47 { 47 48 if (is_error()) { … … 49 50 } 50 51 } 51 PDHError(const PDHError &other) : error_(other.error_), more_data_(other.more_data_), message_(other.message_), negative_denominator_(other.negative_denominator_) {}52 PDHError(const PDHError &other) : error_(other.error_), more_data_(other.more_data_), message_(other.message_), negative_denominator_(other.negative_denominator_), status_(other.status_) {} 52 53 PDHError& operator=(PDHError const& other) { 53 54 error_ = other.error_; 54 55 more_data_ = other.more_data_; 55 56 message_ = other.message_; 57 status_ = other.status_; 56 58 negative_denominator_ = other.negative_denominator_; 57 59 return *this; -
include/settings/client/settings_client.hpp
rd6194a0 rc1810e3 695 695 696 696 697 void register_key(std::wstring path, std::wstring key, int type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced = false) { 698 core_->register_key(path, key, type, title, description, defaultValue, advanced); 699 } 697 700 void register_all() { 698 701 BOOST_FOREACH(key_list::value_type v, keys_) { -
include/socket/server.hpp
r724a835 rc1810e3 106 106 ip::tcp::endpoint endpoint = *endpoint_iterator; 107 107 acceptor_.open(endpoint.protocol()); 108 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 108 boost::system::error_code er; 109 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true), er); 110 if (er) { 111 protocol_->log_error(__FILE__, __LINE__, "Failed to set reuse on socket: " + er.message()); 112 } 109 113 protocol_->log_debug(__FILE__, __LINE__, "Attempting to bind to: " + protocol_->get_info().get_endpoint_string()); 110 114 acceptor_.bind(endpoint); -
modules/CheckExternalScripts/CheckExternalScripts.cpp
ra48fd4c rc1810e3 101 101 wrappings_[_T("ps1")] = _T("cmd /c echo scripts\\\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -"); 102 102 wrappings_[_T("bat")] = _T("scripts\\\\%SCRIPT% %ARGS%"); 103 get_core()->settings_register_key(wrappings_path, _T("vbs"), NSCAPI::key_string, _T("VISUAL BASIC WRAPPING"), _T(""), wrappings_[_T("vbs")], false);104 get_core()->settings_register_key(wrappings_path, _T("ps1"), NSCAPI::key_string, _T("POWERSHELL WRAPPING"), _T(""), wrappings_[_T("ps1")], false);105 get_core()->settings_register_key(wrappings_path, _T("bat"), NSCAPI::key_string, _T("BATCH FILE WRAPPING"), _T(""), wrappings_[_T("bat")], false);103 settings.register_key(wrappings_path, _T("vbs"), NSCAPI::key_string, _T("VISUAL BASIC WRAPPING"), _T(""), wrappings_[_T("vbs")], false); 104 settings.register_key(wrappings_path, _T("ps1"), NSCAPI::key_string, _T("POWERSHELL WRAPPING"), _T(""), wrappings_[_T("ps1")], false); 105 settings.register_key(wrappings_path, _T("bat"), NSCAPI::key_string, _T("BATCH FILE WRAPPING"), _T(""), wrappings_[_T("bat")], false); 106 106 } 107 107 -
modules/CheckSystem/CMakeLists.txt
r8d89d7a rc1810e3 49 49 ${Boost_FILESYSTEM_LIBRARY} 50 50 ${Boost_REGEX_LIBRARY} 51 ${Boost_PROGRAM_OPTIONS_LIBRARY} 51 52 ${NSCP_DEF_PLUGIN_LIB} 52 53 ) -
modules/CheckSystem/CheckSystem.cpp
r53be5c8 rc1810e3 28 28 #include <boost/regex.hpp> 29 29 #include <boost/assign/list_of.hpp> 30 #include <boost/program_options.hpp> 30 31 31 32 #include <tlhelp32.h> … … 80 81 } 81 82 83 void load_counters(std::map<std::wstring,std::wstring> &counters, sh::settings_registry &settings) { 84 settings.alias().add_path_to_settings() 85 (_T("pdh/counters"), sh::wstring_map_path(&counters) 86 , _T("PDH COUNTERS"), _T("Define various PDH counters to check.")) 87 ; 88 89 settings.register_all(); 90 settings.notify(); 91 settings.clear(); 92 93 if (counters.empty() || missing_system_counters(counters)) { 94 std::wstring path = settings.alias().get_settings_path(_T("pdh/counters")); 95 96 counters[PDH_SYSTEM_KEY_UPT] = _T("\\2\\674"); 97 counters[PDH_SYSTEM_KEY_MCL] = _T("\\4\\30"); 98 counters[PDH_SYSTEM_KEY_MCB] = _T("\\4\\26"); 99 counters[PDH_SYSTEM_KEY_CPU] = _T("\\238(_total)\\6"); 100 settings.register_key(path, PDH_SYSTEM_KEY_UPT, NSCAPI::key_string, _T("UPTIME"), _T("PDH Key for system uptime."), _T("\\2\\674"), false); 101 settings.register_key(path, PDH_SYSTEM_KEY_MCL, NSCAPI::key_string, _T("Commit limit"), _T("PDH key for memory commit limit"), _T("\\4\\30"), false); 102 settings.register_key(path, PDH_SYSTEM_KEY_MCB, NSCAPI::key_string, _T("Commit bytes"), _T("PDH Key for system CPU load."), _T("\\4\\26"), false); 103 settings.register_key(path, PDH_SYSTEM_KEY_CPU, NSCAPI::key_string, _T("CPU Load"), _T("PDH Key for system CPU load."), _T("\\238(_total)\\6"), false); 104 settings.register_key(path + _T("/") + PDH_SYSTEM_KEY_CPU, _T("collection strategy"), NSCAPI::key_string, _T("Collection Strategy"), _T("Collection strategy for CPP is usually round robin."), _T("round robin"), false); 105 } 106 } 82 107 bool CheckSystem::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 83 108 PDHCollector::system_counter_data *data = new PDHCollector::system_counter_data; 84 109 data->check_intervall = 1; 85 110 try { 86 typedef std::map<std::wstring,std::wstring> counter_map_type;87 counter_map_type counters;88 89 111 sh::settings_registry settings(get_settings_proxy()); 90 112 settings.set_alias(_T("check"), alias, _T("system/windows")); 91 113 92 settings.alias().add_path_to_settings() 93 (_T("pdh/counters"), sh::wstring_map_path(&counters) 94 , _T("PDH COUNTERS"), _T("Define various PDH counters to check.")) 95 ; 96 97 settings.register_all(); 98 settings.notify(); 99 settings.clear(); 100 101 if (counters.empty() || missing_system_counters(counters)) { 102 std::wstring path = settings.alias().get_settings_path(_T("pdh/counters")); 103 104 get_core()->settings_register_key(path, PDH_SYSTEM_KEY_UPT, NSCAPI::key_string, _T("UPTIME"), _T("PDH Key for system uptime."), _T("\\2\\674"), false); 105 get_core()->settings_register_key(path, PDH_SYSTEM_KEY_MCL, NSCAPI::key_string, _T("Commit limit"), _T("PDH key for memory commit limit"), _T("\\4\\30"), false); 106 get_core()->settings_register_key(path, PDH_SYSTEM_KEY_MCB, NSCAPI::key_string, _T("Commit bytes"), _T("PDH Key for system CPU load."), _T("\\4\\26"), false); 107 get_core()->settings_register_key(path, PDH_SYSTEM_KEY_CPU, NSCAPI::key_string, _T("CPU Load"), _T("PDH Key for system CPU load."), _T("\\238(_total)\\6"), false); 108 get_core()->settings_register_key(path + _T("/") + PDH_SYSTEM_KEY_CPU, _T("collection strategy"), NSCAPI::key_string, _T("Collection Strategy"), _T("Collection strategy for CPP is usually round robin."), _T("round robin"), false); 109 } 114 load_counters(counters, settings); 110 115 111 116 settings.alias().add_path_to_settings() … … 227 232 } 228 233 234 std::wstring validate_counter(std::wstring counter) { 235 std::wstring error; 236 if (!PDH::PDHResolver::validate(counter, error, false)) { 237 NSC_LOG_ERROR_STD(_T("not found: ") + error); 238 } 239 240 typedef boost::shared_ptr<PDH::PDHCounter> counter_ptr; 241 counter_ptr pCounter; 242 PDH::PDHQuery pdh; 243 typedef PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> counter_type; 244 boost::shared_ptr<counter_type> collector(new counter_type()); 245 try { 246 pdh.addCounter(counter, collector); 247 pdh.open(); 248 pdh.gatherData(); 249 pdh.close(); 250 return _T("ok(") + strEx::itos(collector->getValue()) + _T(")"); 251 } catch (const PDH::PDHException e) { 252 try { 253 pdh.gatherData(); 254 pdh.close(); 255 return _T("ok-rate(") + strEx::itos(collector->getValue()) + _T(")"); 256 } catch (const PDH::PDHException e) { 257 return _T("query failed: ") + e.getError(); 258 } 259 } 260 } 261 229 262 int CheckSystem::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) { 230 if (command == _T("help")) { 231 std::wcerr << _T("Usage: ... CheckSystem <command>") << std::endl; 232 std::wcerr << _T("Commands: debugpdh, listpdh, pdhlookup, pdhmatch, pdhobject") << std::endl; 233 return -1; 234 } 235 if (command == _T("debugpdh")) { 236 PDH::Enumerations::Objects lst; 237 try { 238 lst = PDH::Enumerations::EnumObjects(); 239 } catch (const PDH::PDHException e) { 240 std::wcout << _T("Service enumeration failed: ") << e.getError(); 241 return 0; 242 } 243 for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { 244 if ((*it).instances.size() > 0) { 245 for (PDH::Enumerations::Instances::const_iterator it2 = (*it).instances.begin();it2!=(*it).instances.end();++it2) { 246 for (PDH::Enumerations::Counters::const_iterator it3 = (*it).counters.begin();it3!=(*it).counters.end();++it3) { 247 std::wstring counter = _T("\\") + (*it).name + _T("(") + (*it2).name + _T(")\\") + (*it3).name; 248 std::wcout << _T("testing: ") << counter << _T(": "); 249 std::list<std::wstring> errors; 250 std::list<std::wstring> status; 251 std::wstring error; 252 bool bStatus = true; 253 if (PDH::PDHResolver::validate(counter, error, false)) { 254 status.push_back(_T("open")); 255 } else { 256 errors.push_back(_T("NOT found: ") + error); 257 bStatus = false; 258 } 259 if (bStatus) { 260 261 typedef boost::shared_ptr<PDH::PDHCounter> counter_ptr; 262 counter_ptr pCounter; 263 PDH::PDHQuery pdh; 264 try { 265 pdh.addCounter(counter); 266 pdh.open(); 267 268 if (pCounter != NULL) { 269 try { 270 PDH::PDHCounterInfo info = pCounter->getCounterInfo(); 271 errors.push_back(_T("CounterName: ") + info.szCounterName); 272 errors.push_back(_T("ExplainText: ") + info.szExplainText); 273 errors.push_back(_T("FullPath: ") + info.szFullPath); 274 errors.push_back(_T("InstanceName: ") + info.szInstanceName); 275 errors.push_back(_T("MachineName: ") + info.szMachineName); 276 errors.push_back(_T("ObjectName: ") + info.szObjectName); 277 errors.push_back(_T("ParentInstance: ") + info.szParentInstance); 278 errors.push_back(_T("Type: ") + strEx::itos(info.dwType)); 279 errors.push_back(_T("Scale: ") + strEx::itos(info.lScale)); 280 errors.push_back(_T("Default Scale: ") + strEx::itos(info.lDefaultScale)); 281 errors.push_back(_T("Status: ") + strEx::itos(info.CStatus)); 282 status.push_back(_T("described")); 283 } catch (const PDH::PDHException e) { 284 errors.push_back(_T("Describe failed: ") + e.getError()); 285 bStatus = false; 286 } 287 } 288 289 pdh.gatherData(); 290 pdh.close(); 291 status.push_back(_T("queried")); 292 } catch (const PDH::PDHException e) { 293 errors.push_back(_T("Query failed: ") + e.getError()); 294 bStatus = false; 295 try { 296 pdh.gatherData(); 297 pdh.close(); 298 bStatus = true; 299 } catch (const PDH::PDHException e) { 300 errors.push_back(_T("Query failed (again!): ") + e.getError()); 263 if (command == _T("pdh") || command == _T("help") || command.empty()) { 264 namespace po = boost::program_options; 265 266 std::wstring lookup, counter, list_string; 267 po::options_description desc("Allowed options"); 268 desc.add_options() 269 ("help,h", "Show help screen") 270 ("porcelain", "Computer parsable format") 271 ("lookup-index", po::wvalue<std::wstring>(&lookup), "Lookup a numeric value in the PDH index table") 272 ("lookup-name", po::wvalue<std::wstring>(&lookup), "Lookup a string value in the PDH index table") 273 ("expand-path", po::wvalue<std::wstring>(&lookup), "Expand a counter path contaning wildcards into corresponding objects (for instance --expand-path \\System\\*)") 274 ("check", "Check that performance counters are working") 275 ("list", po::wvalue<std::wstring>(&list_string)->implicit_value(_T("")), "List counters and/or instances") 276 ("validate", po::wvalue<std::wstring>(&list_string)->implicit_value(_T("")), "List counters and/or instances") 277 ("all", "List/check all counters not configured counter") 278 ("counter", po::wvalue<std::wstring>(&counter)->implicit_value(_T("")), "Specify which counter to work with") 279 ("filter", po::wvalue<std::wstring>(&counter)->implicit_value(_T("")), "Specify a filter to match (substring matching)") 280 ; 281 boost::program_options::variables_map vm; 282 283 if (command == _T("help")) { 284 std::stringstream ss; 285 ss << "pdh Command line syntax:" << std::endl; 286 ss << desc; 287 result = utf8::cvt<std::wstring>(ss.str()); 288 return NSCAPI::isSuccess; 289 } 290 291 std::vector<std::wstring> args(arguments.begin(), arguments.end()); 292 po::wparsed_options parsed = po::basic_command_line_parser<wchar_t>(args).options(desc).run(); 293 po::store(parsed, vm); 294 po::notify(vm); 295 296 bool porcelain = vm.count("porcelain"); 297 bool all = vm.count("all"); 298 bool validate = vm.count("validate"); 299 bool list = vm.count("list") || (validate && counter.empty()); 300 if (counter.empty()) 301 counter = list_string; 302 303 if (vm.count("help") || (vm.count("check") == 0 && vm.count("list") == 0 && vm.count("validate") == 0 && lookup.empty())) { 304 std::stringstream ss; 305 ss << "pdh Command line syntax:" << std::endl; 306 ss << desc; 307 result = utf8::cvt<std::wstring>(ss.str()); 308 return NSCAPI::isSuccess; 309 } 310 311 312 if (list) { 313 if (all) { 314 if (!porcelain) { 315 result += _T("Listing all counters\n"); 316 result += _T("---------------------------\n"); 317 } 318 try { 319 int total = 0, match = 0; 320 PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 321 BOOST_FOREACH(PDH::Enumerations::Object &obj, lst) { 322 if (!obj.error.empty()) { 323 result += _T("error,") + obj.name + _T(",") + utf8::to_unicode(obj.error) + _T("\n"); 324 } else if (obj.instances.size() > 0) { 325 BOOST_FOREACH(const PDH::Enumerations::Instance &inst, obj.instances) { 326 BOOST_FOREACH(const PDH::Enumerations::Counter &count, obj.counters) { 327 std::wstring line = _T("\\") + obj.name + _T("(") + inst.name + _T(")\\") + count.name; 328 total++; 329 if (!counter.empty() && line.find(counter) == std::wstring::npos) 330 continue; 331 std::wstring status; 332 if (validate) 333 status = validate_counter(line); 334 if (porcelain) 335 line = _T("counter,") + obj.name + _T(",") + inst.name + _T(",") + count.name + _T(", ") + status; 336 else if (validate) 337 line = line + _T(": ") + status; 338 result += line + _T("\n"); 339 match++; 301 340 } 302 341 } 303 304 } 305 if (!bStatus) { 306 std::list<std::wstring>::const_iterator cit = status.begin(); 307 for (;cit != status.end(); ++cit) { 308 std::wcout << *cit << _T(", "); 342 } else { 343 BOOST_FOREACH(const PDH::Enumerations::Counter &count, obj.counters) { 344 std::wstring line = _T("\\") + obj.name + _T("\\") + count.name; 345 total++; 346 if (!counter.empty() && line.find(counter) == std::wstring::npos) 347 continue; 348 std::wstring status; 349 if (validate) 350 status = validate_counter(line); 351 352 if (porcelain) 353 line = _T("counter,") + obj.name + _T(",,") + _T(",") + count.name + _T(", ") + status; 354 else if (validate) 355 line = line + _T(": ") + status; 356 result += line + _T("\n"); 357 match++; 309 358 } 310 std::wcout << std::endl;311 std::wcout << _T(" | Log") << std::endl;312 std::wcout << _T("--+------ -- -") << std::endl;313 cit = errors.begin();314 for (;cit != errors.end(); ++cit) {315 std::wcout << _T(" | ") << *cit << std::endl;316 }317 } else {318 std::list<std::wstring>::const_iterator cit = status.begin();319 for (;cit != status.end(); ++cit) {320 std::wcout << *cit << _T(", ");;321 }322 std::wcout << std::endl;323 359 } 324 360 } 361 if (!porcelain) { 362 result += _T("---------------------------\n"); 363 result += _T("Listed ") + strEx::itos(match) + _T(" of ") + strEx::itos(total) + _T(" counters."); 364 } 365 } catch (const PDH::PDHException e) { 366 result = _T("ERROR: Service enumeration failed: ") + e.getError(); 367 return NSCAPI::hasFailed; 325 368 } 326 369 } else { 327 if ((*it).counters.size() == 0) { 328 std::wcout << _T("empty counter: ") << (*it).name << std::endl; 370 int count = 0, match = 0; 371 if (counters.empty()) { 372 sh::settings_registry settings(get_settings_proxy()); 373 settings.set_alias(_T("check"), _T("system/windows"), _T("system/windows")); 374 375 load_counters(counters, settings); 329 376 } 330 for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { 331 std::wstring counter = _T("\\") + (*it).name + _T("\\") + (*it2).name; 332 std::wcout << _T("testing: ") << counter << _T(": "); 333 std::wstring error; 334 if (PDH::PDHResolver::validate(counter, error, false)) { 335 std::wcout << _T(" found "); 336 } else { 337 std::wcout << _T(" *NOT* found (") << error << _T(") ") << std::endl; 338 break; 377 if (!porcelain) { 378 result += _T("Listing configured counters\n"); 379 result += _T("---------------------------\n"); 380 } 381 BOOST_FOREACH(const counter_map_type::value_type v, counters) { 382 std::wstring line = v.first + _T(" = ") + v.second; 383 std::wstring status; 384 count++; 385 if (!counter.empty() && line.find(counter) == std::wstring::npos) 386 continue; 387 388 if (validate) 389 status = validate_counter(v.second); 390 391 if (porcelain) 392 line = v.first + _T(",") + v.second + _T(",") + status; 393 else if (validate) 394 line = v.first + _T(" = ") + v.second + _T(": ") + status; 395 else 396 line = v.first + _T(" = ") + v.second; 397 result += line + _T("\n"); 398 match++; 399 } 400 if (!porcelain) { 401 result += _T("---------------------------\n"); 402 result += _T("Listed ") + strEx::itos(match) + _T(" of ") + strEx::itos(count) + _T(" counters."); 403 } 404 } 405 return NSCAPI::isSuccess; 406 } else if (vm.count("lookup-index")) { 407 try { 408 DWORD dw = PDH::PDHResolver::lookupIndex(lookup); 409 if (porcelain) { 410 result += strEx::itos(dw); 411 } else { 412 result += _T("--+--[ Lookup Result ]----------------------------------------\n"); 413 result += _T(" | Index for '") + lookup + _T("' is ") + strEx::itos(dw) + _T("\n"); 414 result += _T("--+-----------------------------------------------------------"); 415 } 416 } catch (const PDH::PDHException e) { 417 result += _T("Index not found: ") + lookup + _T("\n"); 418 return NSCAPI::hasFailed; 419 } 420 } else if (vm.count("lookup-name")) { 421 try { 422 std::wstring name = PDH::PDHResolver::lookupIndex(strEx::stoi(lookup)); 423 if (porcelain) { 424 result += name; 425 } else { 426 result += _T("--+--[ Lookup Result ]----------------------------------------\n"); 427 result += _T(" | Index for '") + lookup + _T("' is ") + name + _T("\n"); 428 result += _T("--+-----------------------------------------------------------"); 429 } 430 } catch (const PDH::PDHException e) { 431 result += _T("Failed to lookup index: ") + e.getError(); 432 return NSCAPI::hasFailed; 433 } 434 } else if (vm.count("expand-path")) { 435 try { 436 if (porcelain) { 437 BOOST_FOREACH(const std::wstring &s, PDH::PDHResolver::PdhExpandCounterPath(lookup)) { 438 result += s + _T("\n"); 339 439 } 340 bool bOpend = false; 341 try { 342 PDH::PDHQuery pdh; 343 //PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 344 pdh.addCounter(counter); 345 pdh.open(); 346 pdh.gatherData(); 347 pdh.close(); 348 bOpend = true; 349 } catch (const PDH::PDHException e) { 350 std::wcout << _T(" could *not* be open (") << e.getError() << _T(") ") << std::endl; 351 break; 352 } 353 std::wcout << _T(" open "); 354 std::wcout << std::endl; 355 } 356 } 357 } 358 } else if (command == _T("listpdh")) { 359 bool porcelain = arguments.size() > 0 && arguments.front() == _T("--porcelain"); 360 PDH::Enumerations::Objects lst; 361 try { 362 lst = PDH::Enumerations::EnumObjects(); 363 } catch (const PDH::PDHException e) { 364 result = _T("ERROR: Service enumeration failed: ") + e.getError(); 365 return NSCAPI::returnUNKNOWN; 366 } 367 std::wstringstream ss; 368 BOOST_FOREACH(PDH::Enumerations::Object &obj, lst) { 369 if (!obj.error.empty()) { 370 ss << "error," << obj.name << "," << utf8::to_unicode(obj.error) << _T("\n"); 371 } else if (obj.instances.size() > 0) { 372 BOOST_FOREACH(const PDH::Enumerations::Instance &inst, obj.instances) { 373 BOOST_FOREACH(const PDH::Enumerations::Counter &count, obj.counters) { 374 if (porcelain) 375 ss << "counter," << obj.name << _T(",") << inst.name << _T(",") << count.name << _T("\n"); 376 else 377 ss << _T("\\") << obj.name << _T("(") << inst.name << _T(")\\") << count.name << _T("\n"); 440 } else { 441 result += _T("--+--[ Lookup Result ]----------------------------------------"); 442 BOOST_FOREACH(const std::wstring &s, PDH::PDHResolver::PdhExpandCounterPath(lookup)) { 443 result += _T(" | Found '") + s + _T("\n"); 378 444 } 379 445 } 380 } else { 381 BOOST_FOREACH(const PDH::Enumerations::Counter &count, obj.counters) { 382 if (porcelain) 383 ss << obj.name << _T(",") << count.name << _T("\n"); 384 else 385 ss << _T("\\") << obj.name << _T("\\") << count.name << _T("\n"); 386 } 387 } 388 } 389 result = ss.str(); 390 return NSCAPI::returnOK; 391 } else if (command == _T("pdhlookup")) { 392 try { 393 if (arguments.size() == 0) { 394 NSC_LOG_ERROR_STD(_T("Need to specify counter index name!")); 395 return 0; 396 } 397 std::wstring name = arguments.front(); 398 DWORD dw = PDH::PDHResolver::lookupIndex(name); 399 NSC_LOG_MESSAGE_STD(_T("--+--[ Lookup Result ]----------------------------------------")); 400 NSC_LOG_MESSAGE_STD(_T(" | Index for '") + name + _T("' is ") + strEx::itos(dw)); 401 NSC_LOG_MESSAGE_STD(_T("--+-----------------------------------------------------------")); 402 } catch (const PDH::PDHException e) { 403 NSC_LOG_ERROR_STD(_T("Failed to lookup index: ") + e.getError()); 404 return 0; 405 } 406 } else if (command == _T("pdhmatch")) { 407 try { 408 if (arguments.size() == 0) { 409 NSC_LOG_ERROR_STD(_T("Need to specify counter index name!")); 410 return 0; 411 } 412 std::wstring name = arguments.front(); 413 std::list<std::wstring> list = PDH::PDHResolver::PdhExpandCounterPath(name.c_str()); 414 NSC_LOG_MESSAGE_STD(_T("--+--[ Lookup Result ]----------------------------------------")); 415 for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 416 NSC_LOG_MESSAGE_STD(_T(" | Found '") + *cit); 417 } 418 NSC_LOG_MESSAGE_STD(_T("--+-----------------------------------------------------------")); 419 } catch (const PDH::PDHException e) { 420 NSC_LOG_ERROR_STD(_T("Failed to lookup index: ") + e.getError()); 421 return 0; 422 } 423 } else if (command == _T("pdhobject")) { 424 try { 425 if (arguments.size() == 0) { 426 NSC_LOG_ERROR_STD(_T("Need to specify counter index name!")); 427 return 0; 428 } 429 std::wstring name = arguments.front(); 430 PDH::Enumerations::pdh_object_details list = PDH::Enumerations::EnumObjectInstances(name.c_str()); 431 NSC_LOG_MESSAGE_STD(_T("--+--[ Lookup Result ]----------------------------------------")); 432 for (std::list<std::wstring>::const_iterator cit = list.counters.begin(); cit != list.counters.end(); ++cit) { 433 NSC_LOG_MESSAGE_STD(_T(" | Found Counter: ") + *cit); 434 } 435 for (std::list<std::wstring>::const_iterator cit = list.instances.begin(); cit != list.instances.end(); ++cit) { 436 NSC_LOG_MESSAGE_STD(_T(" | Found Instance: ") + *cit); 437 } 438 NSC_LOG_MESSAGE_STD(_T("--+-----------------------------------------------------------")); 439 } catch (const PDH::PDHException e) { 440 NSC_LOG_ERROR_STD(_T("Failed to lookup index: ") + e.getError()); 441 return 0; 446 } catch (const PDH::PDHException e) { 447 result += _T("Failed to lookup index: ") + e.getError(); 448 return NSCAPI::hasFailed; 449 } 442 450 } 443 451 } -
modules/CheckSystem/CheckSystem.h
r523576e rc1810e3 32 32 CheckMemory memoryChecker; 33 33 PDHCollectorThread pdhThread; 34 35 typedef std::map<std::wstring,std::wstring> counter_map_type; 36 counter_map_type counters; 34 37 35 38 public: -
version.txt
rb611d99 rc1810e3 1 1 version=0.4.1 2 build=2 53 date=2012-08-0 12 build=26 3 date=2012-08-02
Note: See TracChangeset
for help on using the changeset viewer.








