Changeset 3b8eb61 in nscp
- Timestamp:
- 05/18/05 22:46:09 (8 years ago)
- Children:
- 7da80b5
- Parents:
- f896cfb
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
-
NSClient++.cpp (modified) (11 diffs)
-
NSClient++.h (modified) (2 diffs)
-
NSClient++.vcproj (modified) (1 diff)
-
changelog (modified) (1 diff)
-
docs/SysTray/index.html (added)
-
include/EnumProcess.cpp (modified) (1 diff)
-
include/MutexRW.h (added)
-
include/PDHCounter.h (modified) (2 diffs)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (6 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (2 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NSClient++.cpp
rf896cfb r3b8eb61 174 174 */ 175 175 void NSClientT::loadPlugins(const std::list<std::string> plugins) { 176 ReadLock readLock(&m_mutexRW, true, 10000); 177 if (!readLock.IsLocked()) { 178 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 179 return; 180 } 181 /* 176 182 MutexLock lock(pluginMutex); 177 183 if (!lock.hasMutex()) { … … 179 185 return; 180 186 } 187 */ 181 188 std::list<std::string>::const_iterator it; 182 189 for (it = plugins.begin(); it != plugins.end(); ++it) { … … 188 195 */ 189 196 void NSClientT::unloadPlugins() { 190 MutexLock lock(pluginMutex,20000); 191 if (!lock.hasMutex()) { 197 { 198 WriteLock writeLock(&m_mutexRW, true, 10000); 199 if (!writeLock.IsLocked()) { 200 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 201 return; 202 } 203 /* MutexLock lock(pluginMutex,20000); 204 if (!lock.hasMutex()) { 192 205 LOG_ERROR("FATAL ERROR: Could not get mutex."); 193 206 return; 194 } 195 commandHandlers_.clear(); 207 } 208 */ 209 commandHandlers_.clear(); 210 { 211 /* MutexLock lock(messageMutex,20000); 212 if (!lock.hasMutex()) { 213 LOG_ERROR("FATAL ERROR: Could not get mutex (we will now crash BTW)."); 214 } else { 215 messageHandlers_.clear(); 216 } 217 */ 218 messageHandlers_.clear(); 219 } 220 } 196 221 { 197 MutexLock lock2(messageMutex,20000); 198 if (!lock2.hasMutex()) { 199 LOG_ERROR("FATAL ERROR: Could not get mutex (we will now crash BTW)."); 200 } else { 201 messageHandlers_.clear(); 202 } 203 } 204 for (pluginList::size_type i=plugins_.size();i>0;i--) { 205 NSCPlugin *p = plugins_[i-1]; 206 LOG_DEBUG_STD("Unloading plugin: " + p->getName() + "..."); 207 p->unload(); 208 } 209 210 for (unsigned int i=plugins_.size();i>0;i--) { 211 NSCPlugin *p = plugins_[i-1]; 212 plugins_[i-1] = NULL; 213 delete p; 214 } 215 plugins_.clear(); 222 ReadLock readLock(&m_mutexRW, true, 10000); 223 if (!readLock.IsLocked()) { 224 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 225 return; 226 } 227 for (pluginList::size_type i=plugins_.size();i>0;i--) { 228 NSCPlugin *p = plugins_[i-1]; 229 LOG_DEBUG_STD("Unloading plugin: " + p->getName() + "..."); 230 p->unload(); 231 } 232 } 233 234 { 235 WriteLock writeLock(&m_mutexRW, true, 10000); 236 if (!writeLock.IsLocked()) { 237 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 238 return; 239 } 240 for (unsigned int i=plugins_.size();i>0;i--) { 241 NSCPlugin *p = plugins_[i-1]; 242 plugins_[i-1] = NULL; 243 delete p; 244 } 245 plugins_.clear(); 246 } 216 247 } 217 248 /** … … 220 251 */ 221 252 void NSClientT::loadPlugin(const std::string file) { 253 LOG_DEBUG_STD("Loading: " + file); 222 254 addPlugin(new NSCPlugin(file)); 223 255 } … … 227 259 */ 228 260 void NSClientT::addPlugin(plugin_type plugin) { 261 { 262 ReadLock readLock(&m_mutexRW, true, 5000); 263 if (!readLock.IsLocked()) { 264 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 265 return; 266 } 267 plugin->load(); 268 } 269 /* 229 270 MutexLock lock(pluginMutex); 230 271 if (!lock.hasMutex()) { … … 232 273 return; 233 274 } 234 plugin->load(); 235 LOG_DEBUG_STD("Loading: " + plugin->getName()); 236 // @todo Catch here and unload if we fail perhaps ? 237 plugins_.insert(plugins_.end(), plugin); 238 if (plugin->hasCommandHandler()) 239 commandHandlers_.insert(commandHandlers_.end(), plugin); 240 if (plugin->hasMessageHandler()) 241 messageHandlers_.insert(messageHandlers_.end(), plugin); 275 */ 276 277 { 278 WriteLock writeLock(&m_mutexRW, true, 10000); 279 if (!writeLock.IsLocked()) { 280 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 281 return; 282 } 283 // @todo Catch here and unload if we fail perhaps ? 284 plugins_.insert(plugins_.end(), plugin); 285 if (plugin->hasCommandHandler()) 286 commandHandlers_.insert(commandHandlers_.end(), plugin); 287 if (plugin->hasMessageHandler()) 288 messageHandlers_.insert(messageHandlers_.end(), plugin); 289 } 290 242 291 } 243 292 … … 271 320 */ 272 321 NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 273 MutexLock lock(pluginMutex); 322 ReadLock readLock(&m_mutexRW, true, 5000); 323 if (!readLock.IsLocked()) { 324 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 325 return NSCAPI::returnUNKNOWN; 326 } 327 /* MutexLock lock(pluginMutex); 274 328 if (!lock.hasMutex()) { 275 329 LOG_ERROR_STD("Failed to get mutex (" + strEx::itos(lock.getWaitResult()) + "), command ignored..."); 276 330 return NSCAPI::returnUNKNOWN; 277 331 } 278 332 */ 279 333 for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 280 334 try { … … 290 344 case NSCAPI::returnCRIT: 291 345 case NSCAPI::returnUNKNOWN: 292 LOG_DEBUG_STD("Injected Result: " +(std::string) returnMessageBuffer);293 LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer);346 // LOG_DEBUG_STD("Injected Result: " +(std::string) returnMessageBuffer); 347 // LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer); 294 348 return c; 295 349 default: … … 314 368 */ 315 369 void NSClientT::reportMessage(int msgType, const char* file, const int line, std::string message) { 370 ReadLock readLock(&m_mutexRW, true, 5000); 371 if (!readLock.IsLocked()) { 372 std::cout << "Message was lost as the core was locked..." << std::endl; 373 return; 374 } 316 375 MutexLock lock(messageMutex); 317 376 if (!lock.hasMutex()) { … … 320 379 return; 321 380 } 381 /* 382 MutexLock lock(messageMutex); 383 if (!lock.hasMutex()) { 384 std::cout << "Message was lost as the core was locked..." << std::endl; 385 std::cout << message << std::endl; 386 return; 387 } 388 */ 322 389 if (g_bConsoleLog) { 323 390 std::string k = "?"; … … 364 431 } 365 432 std::string NSClientT::getBasePath(void) { 366 MutexLock lock( pluginMutex);433 MutexLock lock(internalVariables); 367 434 if (!lock.hasMutex()) { 368 435 LOG_ERROR("FATAL ERROR: Could not get mutex."); -
trunk/NSClient++.h
r5d8e0b5 r3b8eb61 7 7 #include <Mutex.h> 8 8 #include <NSCAPI.h> 9 #include <MutexRW.h> 9 10 10 11 … … 42 43 pluginList messageHandlers_; 43 44 std::string basePath; 44 MutexHandler pluginMutex; 45 MutexHandler internalVariables; 46 // MutexHandler pluginMutex; 45 47 MutexHandler messageMutex; 48 MutexRW m_mutexRW; 46 49 47 50 public: -
trunk/NSClient++.vcproj
rf896cfb r3b8eb61 296 296 </File> 297 297 <File 298 RelativePath=".\include\MutexRW.h"> 299 </File> 300 <File 298 301 RelativePath=".\include\NSCAPI.h"> 299 302 </File> -
trunk/changelog
rf896cfb r3b8eb61 1 2005-05-18 MickeM 2 * Fixed bug in NSC.ini (section title for Check System was wrong) 3 + Added multitasking for plugins (now two plugins can handle requests simultaniously) 4 * Fixed som minor issues here and there 5 1 6 2005-05-15 MickeM 2 7 + Added NRPE support for checkCounter -
trunk/include/EnumProcess.cpp
rf22f5a9 r3b8eb61 5 5 #include "stdafx.h" 6 6 #include "EnumProcess.h" 7 8 9 #ifdef _DEBUG10 #undef THIS_FILE11 static char THIS_FILE[]=__FILE__;12 #define new DEBUG_NEW13 #endif14 7 15 8 ////////////////////////////////////////////////////////////////////// -
trunk/include/PDHCounter.h
rf7f536b r3b8eb61 50 50 PDH_STATUS status; 51 51 assert(hQuery != NULL); 52 assert(hCounter_ == NULL); 52 if (hCounter_ != NULL) 53 throw PDHException("addToQuery failed (already opened): " + name_); 53 54 if (listener_) 54 55 listener_->attach(*this); 55 56 if ((status = PdhAddCounter(hQuery, name_.c_str(), 0, &hCounter_)) != ERROR_SUCCESS) 56 throw PDHException("PdhOpenQuery failed ", status);57 throw PDHException("PdhOpenQuery failed: " + name_, status); 57 58 assert(hCounter_ != NULL); 58 59 } 59 60 void remove() { 60 assert(hCounter_ != NULL); 61 if (hCounter_ == NULL) 62 return; 61 63 PDH_STATUS status; 62 64 if (listener_) … … 67 69 } 68 70 void collect() { 69 assert(hCounter_ != NULL); 71 if (hCounter_ == NULL) 72 return; 70 73 PDH_STATUS status; 71 74 if ((status = PdhGetFormattedCounterValue(hCounter_, PDH_FMT_LARGE , NULL, &data_)) != ERROR_SUCCESS) -
trunk/modules/CheckHelpers/CheckHelpers.cpp
rf896cfb r3b8eb61 103 103 std::string tMsg, tPerf; 104 104 NSCAPI::nagiosReturn tRet = NSCModuleHelper::InjectCommand((*cit2).first.c_str(), length, args, tMsg, tPerf); 105 arrayBuffer::destroyArrayBuffer(args, length); 105 106 returnCode = NSCHelper::maxState(returnCode, tRet); 106 107 if (!msg.empty()) -
trunk/modules/CheckSystem/CheckSystem.cpp
rf896cfb r3b8eb61 48 48 49 49 if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 50 NSC_DEBUG_MSG_STD("Using PSAPI method."); 50 51 if (method == (method|ENUM_METHOD::PSAPI)) { 51 52 processMethod_ = ENUM_METHOD::PSAPI; 52 53 } else { 53 NSC_LOG_ERROR_STD("PSAPI method not ava lible, check " C_SYSTEM_ENUMPROC_METHOD " option.");54 NSC_LOG_ERROR_STD("PSAPI method not available, check " C_SYSTEM_ENUMPROC_METHOD " option."); 54 55 } 55 56 } else { 57 NSC_DEBUG_MSG_STD("Using TOOLHELP method."); 56 58 if (method == (method|ENUM_METHOD::TOOLHELP)) { 57 59 processMethod_ = ENUM_METHOD::TOOLHELP; … … 68 70 */ 69 71 bool CheckSystem::unloadModule() { 70 if (!pdhThread.exitThread(20000)) 72 if (!pdhThread.exitThread(20000)) { 73 std::cout << "MAJOR ERROR: Could not unload thread..." << std::endl; 71 74 NSC_LOG_ERROR("Could not exit the thread, memory leak and potential corruption may be the result..."); 75 } 72 76 return true; 73 77 } … … 168 172 for (std::list<std::string>::iterator it = times.begin(); it != times.end(); ++it) { 169 173 PDHCollector *pObject = pdhThread.getThread(); 170 assert(pObject); 174 if (!pObject) { 175 msg = "ERROR: PDH Collection thread not running."; 176 return NSCAPI::returnUNKNOWN; 177 } 171 178 if (bNSCLientCompatible) { 172 179 int v = pObject->getCPUAvrage((*it) + "m"); … … 233 240 } 234 241 PDHCollector *pObject = pdhThread.getThread(); 235 assert(pObject); 242 if (!pObject) { 243 msg = "ERROR: PDH Collection thread not running."; 244 return NSCAPI::returnUNKNOWN; 245 } 236 246 unsigned long long uptime = pObject->getUptime(); 237 247 if (bNSCLientCompatible) { … … 381 391 382 392 PDHCollector *pObject = pdhThread.getThread(); 383 assert(pObject); 393 if (!pObject) { 394 msg = "ERROR: PDH Collection thread not running."; 395 return NSCAPI::returnUNKNOWN; 396 } 384 397 long long pageCommit = pObject->getMemCommit(); 385 398 long long pageCommitLimit = pObject->getMemCommitLimit(); … … 567 580 568 581 for (std::list<std::pair<std::string,std::string> >::iterator it = counters.begin(); it != counters.end(); ++it) { 582 std::string name; 569 583 try { 570 try { 571 PDH::PDHQuery pdh; 572 PDHCollectors::StaticPDHCounterListener counter; 573 pdh.addCounter((*it).second, &counter); 574 pdh.open(); 575 pdh.collect(); 576 std::string name = (*it).first; 577 if (name.empty()) 578 name = (*it).second; 579 if (bNSCLientCompatible) { 580 msg += strEx::itos(counter.getValue()); 581 } else { 582 std::string tStr; 583 if (crit.max.hasBounds() && crit.max.checkMAX(counter.getValue())) { 584 tStr = crit.max.prettyPrint(name, counter.getValue()) + " > critical"; 585 NSCHelper::escalteReturnCodeToCRIT(returnCode); 586 } else if (crit.min.hasBounds() && crit.min.checkMIN(counter.getValue())) { 587 tStr = crit.min.prettyPrint(name, counter.getValue()) + " < critical"; 588 NSCHelper::escalteReturnCodeToCRIT(returnCode); 589 } else if (warn.max.hasBounds() && warn.max.checkMAX(counter.getValue())) { 590 tStr = warn.max.prettyPrint(name, counter.getValue()) + " > warning"; 591 NSCHelper::escalteReturnCodeToWARN(returnCode); 592 } else if (warn.min.hasBounds() && warn.min.checkMIN(counter.getValue())) { 593 tStr = warn.min.prettyPrint(name, counter.getValue()) + " < warning"; 594 NSCHelper::escalteReturnCodeToWARN(returnCode); 595 } else if (bShowAll) { 596 tStr = name + ": " + strEx::itos(counter.getValue()); 597 } 598 perf += checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> >::printPerf(name, counter.getValue(), warn, crit); 599 msg += tStr; 584 PDH::PDHQuery pdh; 585 PDHCollectors::StaticPDHCounterListener counter; 586 std::string name = (*it).first; 587 if (name.empty()) 588 name = (*it).second; 589 pdh.addCounter((*it).second, &counter); 590 pdh.open(); 591 pdh.collect(); 592 if (bNSCLientCompatible) { 593 msg += strEx::itos(counter.getValue()); 594 } else { 595 std::string tStr; 596 if (crit.max.hasBounds() && crit.max.checkMAX(counter.getValue())) { 597 tStr = crit.max.prettyPrint(name, counter.getValue()) + " > critical"; 598 NSCHelper::escalteReturnCodeToCRIT(returnCode); 599 } else if (crit.min.hasBounds() && crit.min.checkMIN(counter.getValue())) { 600 tStr = crit.min.prettyPrint(name, counter.getValue()) + " < critical"; 601 NSCHelper::escalteReturnCodeToCRIT(returnCode); 602 } else if (warn.max.hasBounds() && warn.max.checkMAX(counter.getValue())) { 603 tStr = warn.max.prettyPrint(name, counter.getValue()) + " > warning"; 604 NSCHelper::escalteReturnCodeToWARN(returnCode); 605 } else if (warn.min.hasBounds() && warn.min.checkMIN(counter.getValue())) { 606 tStr = warn.min.prettyPrint(name, counter.getValue()) + " < warning"; 607 NSCHelper::escalteReturnCodeToWARN(returnCode); 608 } else if (bShowAll) { 609 tStr = name + ": " + strEx::itos(counter.getValue()); 600 610 } 601 602 pdh.close(); 603 } catch (const PDH::PDHException &e) { 604 NSC_LOG_ERROR_STD("ERROR: " + e.str_); 605 msg = static_cast<std::string>("ERROR: ") + e.str_; 606 return 0; 611 perf += checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> >::printPerf(name, counter.getValue(), warn, crit); 612 msg += tStr; 607 613 } 608 } catch (PDH::PDHException e) { 609 NSC_LOG_ERROR_STD("ERROR: " + e.str_); 614 pdh.close(); 615 } catch (const PDH::PDHException &e) { 616 NSC_LOG_ERROR_STD("ERROR: " + e.str_ + " (" + name + ")"); 610 617 msg = static_cast<std::string>("ERROR: ") + e.str_; 611 return NSCAPI::returnCRIT;618 return 0; 612 619 } 613 620 } -
trunk/modules/CheckSystem/PDHCollector.cpp
rae192e3 r3b8eb61 82 82 }while (!(WaitForSingleObject(hStopEvent_, checkIntervall_*100) == WAIT_OBJECT_0)); 83 83 84 if (!CloseHandle(hStopEvent_)) 85 NSC_LOG_ERROR_STD("Failed to close stopEvent handle: " + strEx::itos(GetLastError())); 86 else 87 hStopEvent_ = NULL; 88 try { 89 pdh.close(); 90 } catch (const PDH::PDHException &e) { 91 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.str_); 84 { 85 MutexLock mutex(mutexHandler); 86 if (!mutex.hasMutex()) { 87 NSC_LOG_ERROR("Failed to get Mute when closing thread!"); 88 } 89 90 if (!CloseHandle(hStopEvent_)) 91 NSC_LOG_ERROR_STD("Failed to close stopEvent handle: " + strEx::itos(GetLastError())); 92 else 93 hStopEvent_ = NULL; 94 try { 95 pdh.close(); 96 } catch (const PDH::PDHException &e) { 97 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.str_); 98 } 92 99 } 93 100 return 0; … … 99 106 */ 100 107 void PDHCollector::exitThread(void) { 108 MutexLock mutex(mutexHandler); 109 if (!mutex.hasMutex()) { 110 NSC_LOG_ERROR("Failed to get Mute when trying to close thread!"); 111 return; 112 } 101 113 if (hStopEvent_ == NULL) 102 NSC_LOG_ERROR("Failed to get Mutex!");114 NSC_LOG_ERROR("Failed to get stop event!"); 103 115 else 104 116 if (!SetEvent(hStopEvent_)) { -
trunk/modules/CheckSystem/PDHCollector.h
r5d8e0b5 r3b8eb61 49 49 50 50 private: 51 bool isRunning(void);52 void startRunning(void);53 void stopRunning(void);51 // bool isRunning(void); 52 // void startRunning(void); 53 // void stopRunning(void); 54 54 55 55 };
Note: See TracChangeset
for help on using the changeset viewer.








