Changeset d656933 in nscp for modules/CheckSystem


Ignore:
Timestamp:
04/20/05 21:08:49 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
945c381
Parents:
cea178b
Message:

+ Added multitasking to socket listsner (it can now handle multiple connections)

  • Fixed bug in NSClientListener now "seqv" in check_nt shouldn't happen. + Added COUNTER support to NSClient and CheckSystem
Location:
modules/CheckSystem
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • modules/CheckSystem/CheckSystem.cpp

    rcea178b rd656933  
    8787 * This also handles a lot of the simpler responses (though some are deferred to other helper functions) 
    8888 * 
    89  #define REQ_CLIENTVERSION  1 // Works fine! 
    90  #define REQ_CPULOAD    2 // Quirks 
    91  - Needs settings for default buffer size (backlog) and possibly other things. 
    92  - Buffer needs to be synced with the client (don't know the size of that) 
    93  - I think the idea was that the buffer would recursive to make a smaller memory footprint. 
    94   (ie. the first level buffer have samples from every second, next level samples from every minute, next level hours etc...) 
    95   (and I don't know the status of this, doesn't seem to be that way) 
    96  #define REQ_UPTIME     3 // Works fine! 
    97  #define REQ_USEDDISKSPACE  4 // Works fine! 
    98  #define REQ_SERVICESTATE 5 // Works fine! 
    99  #define REQ_PROCSTATE    6 // Works fine! 
    100  #define REQ_MEMUSE     7 // Works fine! 
    101  //#define REQ_COUNTER    8 // ! - not implemented Have to look at this, if anyone has a sample let me know... 
    102  //#define REQ_FILEAGE    9 // ! - not implemented Don't know how to use 
    103  //#define REQ_INSTANCES  10  // ! - not implemented Don't know how to use 
    10489 * 
    10590 * @param command  
     
    121106  } else if (command == "checkMem") { 
    122107    return checkMem(command, argLen, char_args, msg, perf); 
     108  } else if (command == "checkCounter") { 
     109    return checkCounter(command, argLen, char_args, msg, perf); 
    123110  } 
    124111/* 
     
    497484  return ret; 
    498485} 
     486 
     487NSCAPI::nagiosReturn CheckSystem::checkCounter(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 
     488{ 
     489  std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
     490  if (stl_args.empty()) { 
     491    msg = "ERROR: Missing argument exception."; 
     492    return NSCAPI::returnUNKNOWN; 
     493  } 
     494  std::list<std::string> counters; 
     495  NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 
     496  bool bShowAll = false; 
     497  bool bNSCLientCompatible = false; 
     498 
     499  for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 
     500    strEx::token t = strEx::getToken((*it), '='); 
     501    if (t.first == SHOW_ALL) 
     502      bShowAll = true; 
     503    else if (t.first == SHOW_FAIL)  { 
     504      bShowAll = false; 
     505    } else if (t.first == NSCLIENT) { 
     506      bNSCLientCompatible = true; 
     507    } else if (t.first == "counter") { 
     508      counters.push_back(t.second); 
     509    } else { 
     510      counters.push_back(t.first); 
     511    } 
     512  } 
     513 
     514  for (std::list<std::string>::iterator it = counters.begin(); it != counters.end(); ++it) { 
     515    try { 
     516      try { 
     517        PDH::PDHQuery pdh; 
     518        PDHCollectors::StaticPDHCounterListener counter; 
     519        pdh.addCounter((*it), &counter); 
     520        pdh.open(); 
     521        pdh.collect(); 
     522        msg += strEx::itos(counter.getValue()); 
     523        pdh.close(); 
     524      } catch (const PDH::PDHException &e) { 
     525        NSC_LOG_ERROR_STD("ERROR: " + e.str_); 
     526        msg = static_cast<std::string>("ERROR: ") + e.str_; 
     527        return 0; 
     528      } 
     529    } catch (PDH::PDHException e) { 
     530      NSC_LOG_ERROR_STD("ERROR: " + e.str_); 
     531      msg = static_cast<std::string>("ERROR: ") + e.str_; 
     532      return NSCAPI::returnCRIT; 
     533    } 
     534  } 
     535  if (msg.empty()) 
     536    msg ="uhmm..."; 
     537  return ret; 
     538} 
    499539NSC_WRAPPERS_MAIN_DEF(gNSClientCompat); 
    500540NSC_WRAPPERS_IGNORE_MSG_DEF(); 
  • modules/CheckSystem/CheckSystem.h

    rcea178b rd656933  
    3636  NSCAPI::nagiosReturn checkMem(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 
    3737  NSCAPI::nagiosReturn checkProcState(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 
     38  NSCAPI::nagiosReturn checkCounter(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 
    3839 
    3940 
  • modules/CheckSystem/PDHCollector.cpp

    rcea178b rd656933  
    113113int PDHCollector::getCPUAvrage(std::string time) { 
    114114  unsigned int mseconds = strEx::stoui_as_time(time, checkIntervall_*100); 
    115   NSC_DEBUG_MSG_STD(time + " resolved to: " + strEx::itos(mseconds) + "ms (" + strEx::itos(mseconds / (checkIntervall_*100)) + "items)"); 
    116115  MutexLock mutex(mutexHandler); 
    117116  if (!mutex.hasMutex()) { 
Note: See TracChangeset for help on using the changeset viewer.