Changeset 2c34b97 in nscp
- Timestamp:
- 02/25/07 13:37:27 (6 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- dc65e35
- Parents:
- 2603350
- Files:
-
- 9 edited
-
changelog (modified) (1 diff)
-
include/Socket.h (modified) (1 diff)
-
include/checkHelpers.hpp (modified) (1 diff)
-
include/utils.h (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.cpp (modified) (15 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (10 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.cpp (modified) (4 diffs)
-
modules/NSClientListener/NSClientListener.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r2603350 r2c34b97 10 10 * Add option to recheck DNS in real time 11 11 12 2006-02-25 MickeM 13 + Added possibility to check many memory checks in one go, just stack type options. 14 type=paged type=physical etc... 15 * Fixed a performance check bug in the last nightly. 16 * Fixed a potential crash when a maleformed check-file-age command was issued. 17 + Added support for more then and NSClient command 18 12 19 2006-02-22 MickeM 13 20 + Added debug output to see if the socket is bound and/or has shutdown. -
include/Socket.h
r2603350 r2c34b97 48 48 unsigned int getLength() const { 49 49 return length_; 50 } 51 void nibble(const unsigned int length) { 52 if (length > length_) 53 return; 54 unsigned int newLen = length_-length; 55 char *tBuf = new char[newLen+1]; 56 memcpy(tBuf, &buffer_[length], newLen); 57 char *oldBuf = buffer_; 58 buffer_ = tBuf; 59 length_ = newLen; 60 delete [] oldBuf; 61 } 62 63 DataBuffer unshift(const unsigned int length) { 64 DataBuffer ret; 65 if (length > length_) 66 return ret; 67 ret.copyFrom(buffer_, length); 68 unsigned int newLen = length_-length; 69 char *tBuf = new char[newLen+1]; 70 memcpy(tBuf, &buffer_[length], newLen); 71 char *oldBuf = buffer_; 72 buffer_ = tBuf; 73 length_ = newLen; 74 delete [] oldBuf; 75 return ret; 76 } 77 const unsigned long long find(char c) { 78 if (buffer_ == NULL) 79 return 0; 80 if (length_ == 0) 81 return 0; 82 const char *pos = strchr(buffer_, c); 83 if (pos == NULL) 84 return 0; 85 return pos-buffer_; 50 86 } 51 87 void copyFrom(const char* buffer, const unsigned int length) { -
include/checkHelpers.hpp
r2603350 r2c34b97 652 652 } else if (min.hasBounds()) { 653 653 return min.gatherPerfData(alias, value, warn.min.getPerfBound(value), crit.min.getPerfBound(value)); 654 } else { 655 NSC_DEBUG_MSG_STD("Missing bounds for maxmin-bounds check: " + alias); 654 656 } 655 657 return ""; -
include/utils.h
r2603350 r2c34b97 76 76 std::pair<std::string,std::string> arg = strEx::split(p__.first,splt); if (false) {} 77 77 78 #define MAP_OPTIONS_SECONDARY_STR_AND(opt, value, objfirst, objsecond, extra) \ 79 else if (opt.first == value) { objfirst = p__.second; objsecond = opt.second; extra;} 80 78 81 #define MAP_OPTIONS_SECONDARY_END() } -
modules/CheckDisk/CheckDisk.cpp
r2603350 r2c34b97 44 44 }; 45 45 typedef std::unary_function<const file_finder_data&, bool> baseFinderFunction; 46 46 47 struct get_size : public baseFinderFunction 47 48 { 48 get_size() : size(0) { } 49 bool error; 50 get_size() : size(0), error(false) { } 49 51 result_type operator()(argument_type ffd) { 50 52 if (!(ffd.wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) { … … 55 57 inline unsigned long long getSize() { 56 58 return size; 59 } 60 inline const bool hasError() const { 61 return error; 62 } 63 inline void setError(std::string) { 64 error = true; 57 65 } 58 66 private: … … 80 88 } 81 89 } while (FindNextFile(hFind, &wfd)); 90 } else { 91 f.setError("File not found"); 82 92 } 83 93 FindClose(hFind); … … 185 195 if (drive.data.length() == 1) 186 196 drive.data += ":"; 187 if (!bPerfData) 188 drive.perfData = false; 197 drive.perfData = bPerfData; 189 198 UINT drvType = GetDriveType(drive.data.c_str()); 190 199 … … 268 277 get_size sizeFinder; 269 278 recursive_scan<get_size>(path.data, sizeFinder); 279 if (sizeFinder.hasError()) { 280 message = "File not found"; 281 return NSCAPI::returnUNKNOWN; 282 } 270 283 path.setDefault(tmpObject); 271 if (!bPerfData) 272 path.perfData = false; 284 path.perfData = bPerfData; 273 285 274 286 checkHolders::disk_size_type size = sizeFinder.getSize(); … … 337 349 struct find_first_file_info : public baseFinderFunction 338 350 { 339 340 351 file_info info; 341 bool bError;342 std::string message;343 find_first_file_info() : bError(false) {}352 bool error; 353 // std::string message; 354 find_first_file_info() : error(false) {} 344 355 result_type operator()(argument_type ffd) { 345 356 if ((ffd.wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) … … 350 361 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 351 362 if (hFile == INVALID_HANDLE_VALUE) { 352 message = "Could not open file: " + ffd.path + "\\" + ffd.wfd.cFileName + ": " + strEx::itos(GetLastError()); 353 bError = true; 363 setError("Could not open file: " + ffd.path + "\\" + ffd.wfd.cFileName + ": " + strEx::itos(GetLastError())); 354 364 return false; 355 365 } … … 358 368 info = file_info(_info, ffd.wfd.cFileName); 359 369 return false; 370 } 371 inline const bool hasError() const { 372 return error; 373 } 374 inline void setError(std::string) { 375 error = true; 360 376 } 361 377 }; … … 366 382 bool bFilterAll; 367 383 bool bFilterIn; 368 bool bError;384 bool error; 369 385 std::string message; 370 386 std::string syntax; … … 372 388 unsigned int hit_count; 373 389 374 file_filter_function() : hit_count(0), bError(false), bFilterIn(true), bFilterAll(true) {}390 file_filter_function() : hit_count(0), error(false), bFilterIn(true), bFilterAll(true) {} 375 391 result_type operator()(argument_type ffd) { 376 392 if ((ffd.wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) … … 381 397 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); 382 398 if (hFile == INVALID_HANDLE_VALUE) { 383 message = "Could not open file: " + ffd.path + "\\" + ffd.wfd.cFileName + ": " + strEx::itos(GetLastError()); 384 bError = true; 385 return false; 399 setError("Could not open file: " + ffd.path + "\\" + ffd.wfd.cFileName + ": " + strEx::itos(GetLastError())); 386 400 } 387 401 GetFileInformationByHandle(hFile, &_info); … … 411 425 return true; 412 426 } 427 inline const bool hasError() const { 428 return error; 429 } 430 inline void setError(std::string) { 431 error = true; 432 } 413 433 }; 414 434 … … 421 441 return NSCAPI::returnUNKNOWN; 422 442 } 423 std::string dstr, path; 443 std::string dstr = "%#c"; 444 std::string path; 424 445 find_first_file_info finder; 425 446 MAP_OPTIONS_BEGIN(stl_args) … … 428 449 MAP_OPTIONS_END() 429 450 451 if (path.empty()) { 452 message = "ERROR: no file specified."; 453 return NSCAPI::returnUNKNOWN; 454 } 455 430 456 recursive_scan<find_first_file_info>(path, finder); 431 if (finder. bError) {432 message = " ERROR: could not find file.";457 if (finder.hasError()) { 458 message = "File not found"; 433 459 return NSCAPI::returnUNKNOWN; 434 460 } … … 495 521 for (std::list<std::string>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 496 522 recursive_scan<file_filter_function>((*pit), finder); 523 if (finder.hasError()) { 524 message = "File not found: " + (*pit); 525 return NSCAPI::returnUNKNOWN; 526 } 497 527 } 498 528 message = finder.message; 499 if (finder. bError)529 if (finder.error) 500 530 return NSCAPI::returnUNKNOWN; 501 531 query.runCheck(finder.hit_count, returnCode, message, perf); -
modules/CheckSystem/CheckSystem.cpp
r2603350 r2c34b97 45 45 bool CheckSystem::loadModule() { 46 46 pdhThread.createThread(); 47 48 47 std::string wantedMethod = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_ENUMPROC_METHOD, C_SYSTEM_ENUMPROC_METHOD_DEFAULT); 49 50 48 CEnumProcess tmp; 51 49 int method = tmp.GetAvailableMethods(); 52 53 54 55 50 if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_AUTO) { 56 51 OSVERSIONINFO osVer = systemInfo::getOSVersion(); … … 111 106 112 107 int CheckSystem::commandLineExec(const char* command,const unsigned int argLen,char** args) { 113 if ( stricmp(command, "debugpdh") == 0) {108 if (_stricmp(command, "debugpdh") == 0) { 114 109 PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 115 110 for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { … … 224 219 } 225 220 } 226 } else if ( stricmp(command, "listpdh") == 0) {221 } else if (_stricmp(command, "listpdh") == 0) { 227 222 PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 228 223 for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { … … 352 347 } else { 353 348 load.setDefault(tmpObject); 354 if (!bPerfData) 355 load.perfData = false; 349 load.perfData = bPerfData; 356 350 load.runCheck(value, returnCode, msg, perf); 357 351 } … … 403 397 } else { 404 398 value *= 1000; 405 if (!bPerfData) 406 bounds.perfData = false; 399 bounds.perfData = bPerfData; 407 400 bounds.runCheck(value, returnCode, msg, perf); 408 401 } … … 539 532 else 540 533 value = checkHolders::state_none; 541 if (!bPerfData) 542 (*it).perfData = false; 534 (*it).perfData = bPerfData; 543 535 (*it).runCheck(value, returnCode, msg, perf); 544 536 } … … 551 543 return returnCode; 552 544 } 553 554 545 555 546 /** … … 572 563 return NSCAPI::returnUNKNOWN; 573 564 } 565 std::list<MemoryConatiner> list; 574 566 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 575 567 bool bShowAll = false; 576 568 bool bPerfData = true; 577 569 bool bNSClient = false; 578 MemoryConatiner bounds; 579 typedef enum { tPaged, tPage, tVirtual, tPhysical } check_type; 580 check_type type = tPaged; 570 MemoryConatiner tmpObject; 581 571 582 572 MAP_OPTIONS_BEGIN(stl_args) 583 MAP_OPTIONS_DISK_ALL(bounds, "", "Free", "Used") 584 MAP_OPTIONS_STR("Alias", bounds.data) 585 MAP_OPTIONS_SHOWALL(bounds) 573 MAP_OPTIONS_STR_AND("type", tmpObject.data, list.push_back(tmpObject)) 574 MAP_OPTIONS_STR_AND("Type", tmpObject.data, list.push_back(tmpObject)) 575 MAP_OPTIONS_DISK_ALL(tmpObject, "", "Free", "Used") 576 MAP_OPTIONS_STR("Alias", tmpObject.data) 577 MAP_OPTIONS_SHOWALL(tmpObject) 586 578 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 587 579 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 588 MAP_OPTIONS_ MODE("type", "paged", type, tPaged)589 MAP_OPTIONS_MODE("type", "page", type, tPage)590 MAP_OPTIONS_MODE("type", "virtual", type, tVirtual)591 MAP_OPTIONS_ MODE("type", "physical", type, tPhysical)580 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 581 MAP_OPTIONS_SECONDARY_STR_AND(p2,"type", tmpObject.data, tmpObject.alias, list.push_back(tmpObject)) 582 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 583 MAP_OPTIONS_SECONDARY_END() 592 584 MAP_OPTIONS_MISSING(msg, "Unknown argument: ") 593 585 MAP_OPTIONS_END() 594 595 596 checkHolders::PercentageValueType<unsigned long long, unsigned long long> value; 597 if (type == tPaged) { 598 PDHCollector *pObject = pdhThread.getThread(); 599 if (!pObject) { 600 msg = "ERROR: PDH Collection thread not running."; 601 return NSCAPI::returnUNKNOWN; 602 } 603 value.value = pObject->getMemCommit(); 604 value.total = pObject->getMemCommitLimit(); 605 if (bounds.data.empty()) 606 bounds.data = "paged bytes"; 607 } else { 608 CheckMemory::memData data; 609 try { 610 data = memoryChecker.getMemoryStatus(); 611 } catch (CheckMemoryException e) { 612 msg = e.getError() + ":" + strEx::itos(e.getErrorCode()); 613 return NSCAPI::returnCRIT; 614 } 615 // MEMORYSTATUS mem; 616 // GlobalMemoryStatus(&mem); 617 if (type == tPage) { 586 if (bNSClient) { 587 tmpObject.data = "paged"; 588 list.push_back(tmpObject); 589 } 590 591 checkHolders::PercentageValueType<unsigned long long, unsigned long long> dataPaged; 592 CheckMemory::memData data; 593 bool firstPaged = true; 594 bool firstMem = true; 595 for (std::list<MemoryConatiner>::const_iterator pit = list.begin(); pit != list.end(); ++pit) { 596 MemoryConatiner check = (*pit); 597 checkHolders::PercentageValueType<unsigned long long, unsigned long long> value; 598 if (firstPaged && (check.data == "paged")) { 599 firstPaged = false; 600 PDHCollector *pObject = pdhThread.getThread(); 601 if (!pObject) { 602 msg = "ERROR: PDH Collection thread not running."; 603 return NSCAPI::returnUNKNOWN; 604 } 605 dataPaged.value = pObject->getMemCommit(); 606 dataPaged.total = pObject->getMemCommitLimit(); 607 } else if (firstMem) { 608 try { 609 data = memoryChecker.getMemoryStatus(); 610 } catch (CheckMemoryException e) { 611 msg = e.getError() + ":" + strEx::itos(e.getErrorCode()); 612 return NSCAPI::returnCRIT; 613 } 614 } 615 616 if (check.data == "page") { 618 617 value.value = data.pageFile.total-data.pageFile.avail; // mem.dwTotalPageFile-mem.dwAvailPageFile; 619 618 value.total = data.pageFile.total; //mem.dwTotalPageFile; 620 if ( bounds.data.empty())621 bounds.data= "page file";622 } else if (type == tPhysical) {619 if (check.alias.empty()) 620 check.alias = "page file"; 621 } else if (check.data == "physical") { 623 622 value.value = data.phys.total-data.phys.avail; //mem.dwTotalPhys-mem.dwAvailPhys; 624 623 value.total = data.phys.total; //mem.dwTotalPhys; 625 if ( bounds.data.empty())626 bounds.data= "physical memory";627 } else if (type == tVirtual) {624 if (check.alias.empty()) 625 check.alias = "physical memory"; 626 } else if (check.data == "virtual") { 628 627 value.value = data.virtualMem.total-data.virtualMem.avail;//mem.dwTotalVirtual-mem.dwAvailVirtual; 629 628 value.total = data.virtualMem.total;//mem.dwTotalVirtual; 630 if (bounds.data.empty()) 631 bounds.data = "virtual memory"; 632 } 633 } 634 635 if (bNSClient) { 636 msg = strEx::itos(value.total) + "&" + strEx::itos(value.value); 637 return NSCAPI::returnOK; 638 } else { 639 if (!bPerfData) 640 bounds.perfData = false; 641 bounds.runCheck(value, returnCode, msg, perf); 642 } 629 if (check.alias.empty()) 630 check.alias = "virtual memory"; 631 } else if (check.data == "paged") { 632 value.value = dataPaged.value; 633 value.total = dataPaged.total; 634 if (check.alias.empty()) 635 check.alias = "paged bytes"; 636 } else { 637 msg = check.data + " is not a known check..."; 638 return NSCAPI::returnCRIT; 639 } 640 if (bNSClient) { 641 msg = strEx::itos(value.total) + "&" + strEx::itos(value.value); 642 return NSCAPI::returnOK; 643 } else { 644 check.perfData = bPerfData; 645 check.runCheck(value, returnCode, msg, perf); 646 } 647 } 648 NSC_DEBUG_MSG_STD("Perf data: " + strEx::itos(bPerfData) + ":" + perf); 649 643 650 if (msg.empty()) 644 651 msg = "OK memory within bounds."; … … 767 774 value.state = checkHolders::state_stopped; 768 775 } 769 if (!bPerfData) 770 (*it).perfData = false; 776 (*it).perfData = bPerfData; 771 777 (*it).runCheck(value, returnCode, msg, perf); 772 778 } … … 857 863 msg += strEx::itos(value); 858 864 } else { 859 if (!bPerfData) 860 counter.perfData = false; 865 counter.perfData = bPerfData; 861 866 counter.setDefault(tmpObject); 862 867 counter.runCheck(value, returnCode, msg, perf); -
modules/NRPEListener/NRPEListener.cpp
r2603350 r2c34b97 37 37 bool NRPEListener::loadModule() { 38 38 bUseSSL_ = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_USE_SSL ,NRPE_SETTINGS_USE_SSL_DEFAULT)==1; 39 noPerfData_ = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PERFDATA,NRPE_SETTINGS_PERFDATA_DEFAULT)== 1;39 noPerfData_ = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PERFDATA,NRPE_SETTINGS_PERFDATA_DEFAULT)==0; 40 40 timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,NRPE_SETTINGS_TIMEOUT_DEFAULT); 41 41 std::list<std::string> commands = NSCModuleHelper::getSettingsSection(NRPE_HANDLER_SECTION_TITLE); -
modules/NSClientListener/NSClientListener.cpp
r2603350 r2c34b97 122 122 123 123 std::string NSClientListener::parseRequest(std::string buffer) { 124 NSC_DEBUG_MSG_STD("Data: " + buffer); 125 126 std::string::size_type pos = buffer.find_first_of("\n\r"); 127 if (pos != std::string::npos) { 128 std::string::size_type pos2 = buffer.find_first_not_of("\n\r", pos); 129 if (pos2 != std::string::npos) { 130 std::string rest = buffer.substr(pos2); 131 NSC_DEBUG_MSG_STD("Ignoring datat: " + rest); 132 } 133 buffer = buffer.substr(0, pos); 134 } 135 124 136 strEx::token pwd = strEx::getToken(buffer, '&'); 125 137 if (!isPasswordOk(pwd.first)) { … … 134 146 135 147 int c = atoi(cmd.first.c_str()); 148 149 NSC_DEBUG_MSG_STD("Data: " + cmd.second); 150 136 151 137 152 // prefix various commands … … 209 224 {} 210 225 226 void NSClientListener::sendTheResponse(simpleSocket::Socket *client, std::string response) { 227 client->send(response.c_str(), static_cast<int>(response.length()), 0); 228 } 229 230 void NSClientListener::retrivePacket(simpleSocket::Socket *client) { 231 simpleSocket::DataBuffer db; 232 233 int i; 234 for (i=0;i<30;i++) { 235 client->readAll(db); 236 237 if (db.getLength() > 0) { 238 unsigned long long pos = db.find('\n'); 239 if (pos==0) { 240 std::string incoming(db.getBuffer(), db.getLength()); 241 sendTheResponse(client, parseRequest(incoming)); 242 break; 243 } else if (pos!=0) { 244 simpleSocket::DataBuffer buffer = db.unshift(pos); 245 std::string bstr(buffer.getBuffer(), buffer.getLength()); 246 db.nibble(1); 247 std::string rstr(db.getBuffer(), db.getLength()); 248 std::string incoming(buffer.getBuffer(), buffer.getLength()); 249 sendTheResponse(client, parseRequest(incoming) + "\n"); 250 } 251 } else { 252 Sleep(100); 253 } 254 } 255 if (i == 100) { 256 NSC_LOG_ERROR_STD("Could not retrieve NSClient packet."); 257 client->close(); 258 return; 259 } 260 } 261 262 211 263 void NSClientListener::onAccept(simpleSocket::Socket *client) { 212 264 if (!allowedHosts.inAllowedHosts(client->getAddrString())) { … … 215 267 return; 216 268 } 217 simpleSocket::DataBuffer db; 218 219 int i; 220 for (i=0;i<100;i++) { 221 client->readAll(db); 222 // @todo Make this check if a packet is read instead of just if we have data 223 if (db.getLength() > 0) 224 break; 225 Sleep(100); 226 } 227 if (i == 100) { 228 NSC_LOG_ERROR_STD("Could not retrieve NSClient packet."); 229 client->close(); 230 return; 231 } 269 retrivePacket(client); 232 270 233 271 234 272 235 273 // client->readAll(db); 236 if (db.getLength() > 0) {237 std::string incoming(db.getBuffer(), db.getLength());274 // if (db.getLength() > 0) { 275 // std::string incoming(db.getBuffer(), db.getLength()); 238 276 // NSC_DEBUG_MSG_STD("Incoming data: " + incoming); 239 std::string response = parseRequest(incoming);277 // std::string response = parseRequest(incoming); 240 278 // NSC_DEBUG_MSG("Outgoing data: " + response); 241 client->send(response.c_str(), static_cast<int>(response.length()), 0);242 }279 // client->send(response.c_str(), static_cast<int>(response.length()), 0); 280 // } 243 281 client->close(); 244 282 } -
modules/NSClientListener/NSClientListener.h
r2603350 r2c34b97 30 30 31 31 std::string parseRequest(std::string buffer); 32 void sendTheResponse(simpleSocket::Socket *client, std::string response); 33 void retrivePacket(simpleSocket::Socket *client); 32 34 bool isPasswordOk(std::string remotePassword); 33 35
Note: See TracChangeset
for help on using the changeset viewer.








