Changeset 079055f in nscp


Ignore:
Timestamp:
02/17/05 22:41:31 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
5ba0a58
Parents:
5969055
Message:

Verified NSCLient compatiblity for many commands and some minor tweaks (now most NSClient commands are OK)

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/NSClient++.cpp

    rea8a900 r079055f  
    260260        LOG_ERROR("Return buffer to small, need to increase it in the ini file."); 
    261261      } else {                  // Something else went wrong... 
    262         LOG_ERROR("Unknown error from handleCommand"); 
     262        LOG_ERROR_STD("Unknown error from handleCommand: " + strEx::itos(c)); 
    263263      } 
    264264    } catch(const NSPluginException& e) { 
  • trunk/TCPSocketResponder.cpp

    rc67f92f r079055f  
    104104    client=accept(server, (struct sockaddr*)&from,&fromlen); 
    105105    if (client != INVALID_SOCKET) { 
    106       LOG_ERROR_STD("Accept returned: " + strEx::itos((DWORD)client)); 
    107106      char *buff = new char[RECV_BUFFER_LEN+1]; 
    108107      int n=recv(client,buff,RECV_BUFFER_LEN,0); 
  • trunk/include/NSCHelper.cpp

    r05bfaf2 r079055f  
    1414 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 
    1515 */ 
    16 int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str) { 
     16int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode /* = NSCAPI::success */) { 
    1717  if (str.length() > bufLen) 
    1818    return NSCAPI::invalidBufferLen; 
    1919  strncpy(buffer, str.c_str(), bufLen); 
    20   return NSCAPI::success; 
     20  return defaultReturnCode; 
    2121} 
    2222/** 
     
    288288  if (retStr.empty()) 
    289289    return NSCAPI::isfalse; 
    290   return NSCHelper::wrapReturnString(returnBuffer, returnBufferLen, retStr); 
     290  return NSCHelper::wrapReturnString(returnBuffer, returnBufferLen, retStr, NSCAPI::handled); 
    291291} 
    292292/** 
  • trunk/include/NSCHelper.h

    r05bfaf2 r079055f  
    77namespace NSCHelper 
    88{ 
    9   int wrapReturnString(char *buffer, unsigned int bufLen, std::string str); 
     9  int wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode = NSCAPI::success); 
    1010  std::list<std::string> makelist(const unsigned int argLen, char **argument); 
    1111  std::string translateMessageType(NSCAPI::messageTypes msgType); 
  • trunk/modules/NSClientCompat/NSClientCompat.cpp

    re0705d4 r079055f  
    8686 * This also handles a lot of the simpler responses (though some are deferred to other helper functions) 
    8787 * 
    88  #define REQ_CLIENTVERSION  1 // x 
    89  #define REQ_CPULOAD    2 // x 
    90  #define REQ_UPTIME     3 // x 
    91  #define REQ_USEDDISKSPACE  4 // x 
    92  #define REQ_SERVICESTATE 5 // x 
    93  #define REQ_PROCSTATE    6 // x 
    94  #define REQ_MEMUSE     7 // x 
    95  //#define REQ_COUNTER    8 // ! - not implemented 
    96  //#define REQ_FILEAGE    9 // ! - not implemented 
    97  //#define REQ_INSTANCES  10  // ! - not implemented 
     88 #define REQ_CLIENTVERSION  1 // Works fine! 
     89 #define REQ_CPULOAD    2 // Quirks 
     90 - Needs settings for default buffer size (backlog) and possibly other things. 
     91 - Buffer needs to be synced with the client (don't know the size of that) 
     92 - I think the idea was that the buffer would recursive to make a smaller memory footprint. 
     93  (ie. the first level buffer have samples from every second, next level samples from every minute, next level hours etc...) 
     94  (and I don't know the status of this, doesn't seem to be that way) 
     95 #define REQ_UPTIME     3 // Works fine! 
     96 #define REQ_USEDDISKSPACE  4 // Works fine! 
     97 #define REQ_SERVICESTATE 5 // Works fine! 
     98 #define REQ_PROCSTATE    6 // Works fine! 
     99 #define REQ_MEMUSE     7 // Works fine! 
     100 //#define REQ_COUNTER    8 // ! - not implemented Have to look at this, if anyone has a sample let me know... 
     101 //#define REQ_FILEAGE    9 // ! - not implemented Dont know how to use 
     102 //#define REQ_INSTANCES  10  // ! - not implemented Dont know how to use 
    98103 * 
    99104 * @param command  
     
    109114  switch (id) { 
    110115    case REQ_CLIENTVERSION: 
    111       return NSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString(); 
    112      
     116      { 
     117        std::string version = NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern"); 
     118        if (version == "modern") 
     119          return NSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString(); 
     120        return version; 
     121      } 
    113122    case REQ_UPTIME: 
    114123      return strEx::itos(pdhCollector->getUptime()); 
    115124 
    116125    case REQ_CPULOAD: 
    117       stl_args = NSCHelper::makelist(argLen, args); 
    118       if (stl_args.empty()) 
    119         return "ERROR: Missing argument exception."; 
    120       return strEx::itos(pdhCollector->getCPUAvrage(strEx::stoi(stl_args.front())*(60/CHECK_INTERVAL))); 
    121  
     126      { 
     127        stl_args = NSCHelper::makelist(argLen, args); 
     128        if (stl_args.empty()) 
     129          return "ERROR: Missing argument exception."; 
     130        std::string ret; 
     131        while (!stl_args.empty()) { 
     132          std::string s = stl_args.front(); stl_args.pop_front(); 
     133          int v = pdhCollector->getCPUAvrage(strEx::stoi(s)*(60/CHECK_INTERVAL)); 
     134          if (v == -1) 
     135            return ret; 
     136          if (!ret.empty()) 
     137            ret += "&"; 
     138          ret += strEx::itos(v); 
     139        } 
     140        return ret; 
     141      } 
    122142    case REQ_SERVICESTATE: 
    123143      return NSCommands::serviceState(NSCHelper::makelist(argLen, args)); 
  • trunk/modules/NSClientCompat/NSCommands.cpp

    re0705d4 r079055f  
    8282        state = error; 
    8383      if (!ret.empty()) ret += " - "; 
    84       ret += exe + " : Stopped"; 
     84      ret += exe + " : not running"; 
    8585    } else if (showAll) { 
    8686      if (!ret.empty()) ret += " - "; 
  • trunk/modules/SysTray/TrayIcon.cpp

    r5969055 r079055f  
    4343  case WM_INITDIALOG: 
    4444    addIcon(hwndDlg); 
    45 //    return TRUE; 
    4645    break; 
    4746 
  • trunk/readme.txt

    re0705d4 r079055f  
     1** ROUGH DRAFT ** 
     2** Spelling missate etc... :) ** 
     3 
     4 
    15NSClient++ is a windows service that allows performance metrics to be gathered by Nagios  
    26(and possibly other monitoring tools). It is an attempt to create a NSClient compatible  
     
    48 
    59 
     10Installation: 
     11NSClient++ -install 
     12Will install the NT service 
     13 
     14NSClient++ -uninstall 
     15Will uninstall the service 
     16 
     17NSClient++ -start 
     18Will start the service 
     19 
     20NSClient++ -stop 
     21Will stop the service 
     22 
     23NSClient++ -test 
     24Will start in interactive mode: 
     25enter exit<return> to exit. ANything else will be interpreted as a command ie: foo&bar<enter> will be interpreted as a command name foo with argument bar. 
     26It also listens to the port in this mode so it can be used to run the client standalone. 
     27Notice output is *NOT* piped t othe stdard output unless you enable the console logger module. 
    628 
    729 
     30 
     31 
     32 
     33The API is quite simple: 
     34The following functions are available for a module to "export": (think DLL) 
     35 
     36NSLoadModule 
     37- Loading of modules (done when the service starts) 
     38NSGetModuleName 
     39- Used to get a nice name for the module. 
     40NSGetModuleVersion 
     41- Not really used but... 
     42NSHasCommandHandler 
     43- Let the "core" know it can handle commands (from nagios) 
     44NSHasMessageHandler 
     45- Used to let the "core" know it wants to see all log/debug/error messages that are generated. 
     46NSHandleMessage 
     47- Used to digest a log/debug/error message. 
     48NSHandleCommand 
     49- Used to (possibly) digest a command. 
     50When a command is "injected" then command is parsed and then sent along to all plugins (which accept commands) in order (they are listed in NSC.ini) and they are allowed to act on the command. If they do act on the command the "injection" is aborted and the resulting "return string" is returned to the "injecter" (normaly check_nt through a TCP stream. The ordering can thus be used to 1, optimize if things are slow (though I fail to see that unless someone makes some pretty f*cked up modules) and priority if one module overlaps the command of another (though then I would recommend someone to change the plugin command strings :) 
     51 
     52NSUnloadModule 
     53- Used to unload and terminate "stuff" nicely. (Generally this is when the service terminates) 
     54NSModuleHelperInit 
     55- Used to send along callbacks to the module (for making calls to the "core". (Ie. To allow the module to inject commands, get versions, names, and settings) 
     56 
     57So the API is quite simple and straight forward (I hope :) 
     58 
     59To make a simple call graph: 
     60 
     61* Service starts: 
     62* For each plugin 
     63        - call NSLoadModule 
     64        - call NSModuleHelperInit 
     65        - if NSHasCommandHandler 
     66                . Send to "command plugin" stack 
     67        - if NSHasMessageHandler 
     68                . Send to "message plugin" stack 
     69* Wait for socket data 
     70        - Parse socket data 
     71        - For each "command plugin" 
     72                . call NSHandleCommand 
     73                . if Command handled abort 
     74 
     75<termination signal sent to service> 
     76* For each plugin 
     77        - NSUnloadModule 
     78* Terminate service 
     79 
     80<Log/debug/error message generated in a module> 
     81* On incoming message: 
     82        - For each "message plugin" 
     83                . call NSHandleMessage 
     84 
     85There are a few more things to this but overall I have tried to keep things simple. 
     86 
     87The extensions (to the API) I'm considering as of now (depending on the fallout) is: 
     88* "SettingsHandler" to allow registry/INI/* settings modules. As the overhead of reg/ini settings system is quite low, perhaps this is overkill. But I don't know: thinking wildly there might be a reason for someone to want to load settings from a central server or whatever :) 
     89 
     90* "SocketHandlers" though this will not be a specific handler I have considered to refactor out the code and allow the socket handler (that reads the TCP socket and parses the command) to be a plugin when I do SSL as I assume SSL will come with quite a high overhead and thus I might not need it all the time. 
     91 
     92Also as mentioned this might be a good place to do a NRPE socket parser module to allow compatibility with NRPE. But this I assume is a bit in the future as I need to get "NSClient++" before I can get "NRPEClient++"... 
     93 
     94As for PassiveChecks that could be implemented as a plugin today as any plugin can inject commands into the "core". Thus a plugin can be loaded, have a background thread that every X minutes calls "core".injectCommand(); and sends the result over to nagios. (This is how I assume that passive checks work) 
     95 
     96 
     97 
     98 
     99// Michael Medin - michael <at> medin <dot> name - http://www.medin.name 
Note: See TracChangeset for help on using the changeset viewer.