Changeset 079055f in nscp
- Timestamp:
- 02/17/05 22:41:31 (8 years ago)
- Children:
- 5ba0a58
- Parents:
- 5969055
- Location:
- trunk
- Files:
-
- 8 edited
-
NSClient++.cpp (modified) (1 diff)
-
TCPSocketResponder.cpp (modified) (1 diff)
-
include/NSCHelper.cpp (modified) (2 diffs)
-
include/NSCHelper.h (modified) (1 diff)
-
modules/NSClientCompat/NSClientCompat.cpp (modified) (2 diffs)
-
modules/NSClientCompat/NSCommands.cpp (modified) (1 diff)
-
modules/SysTray/TrayIcon.cpp (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NSClient++.cpp
rea8a900 r079055f 260 260 LOG_ERROR("Return buffer to small, need to increase it in the ini file."); 261 261 } else { // Something else went wrong... 262 LOG_ERROR ("Unknown error from handleCommand");262 LOG_ERROR_STD("Unknown error from handleCommand: " + strEx::itos(c)); 263 263 } 264 264 } catch(const NSPluginException& e) { -
trunk/TCPSocketResponder.cpp
rc67f92f r079055f 104 104 client=accept(server, (struct sockaddr*)&from,&fromlen); 105 105 if (client != INVALID_SOCKET) { 106 LOG_ERROR_STD("Accept returned: " + strEx::itos((DWORD)client));107 106 char *buff = new char[RECV_BUFFER_LEN+1]; 108 107 int n=recv(client,buff,RECV_BUFFER_LEN,0); -
trunk/include/NSCHelper.cpp
r05bfaf2 r079055f 14 14 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 15 15 */ 16 int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str ) {16 int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode /* = NSCAPI::success */) { 17 17 if (str.length() > bufLen) 18 18 return NSCAPI::invalidBufferLen; 19 19 strncpy(buffer, str.c_str(), bufLen); 20 return NSCAPI::success;20 return defaultReturnCode; 21 21 } 22 22 /** … … 288 288 if (retStr.empty()) 289 289 return NSCAPI::isfalse; 290 return NSCHelper::wrapReturnString(returnBuffer, returnBufferLen, retStr );290 return NSCHelper::wrapReturnString(returnBuffer, returnBufferLen, retStr, NSCAPI::handled); 291 291 } 292 292 /** -
trunk/include/NSCHelper.h
r05bfaf2 r079055f 7 7 namespace NSCHelper 8 8 { 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); 10 10 std::list<std::string> makelist(const unsigned int argLen, char **argument); 11 11 std::string translateMessageType(NSCAPI::messageTypes msgType); -
trunk/modules/NSClientCompat/NSClientCompat.cpp
re0705d4 r079055f 86 86 * This also handles a lot of the simpler responses (though some are deferred to other helper functions) 87 87 * 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 98 103 * 99 104 * @param command … … 109 114 switch (id) { 110 115 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 } 113 122 case REQ_UPTIME: 114 123 return strEx::itos(pdhCollector->getUptime()); 115 124 116 125 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 } 122 142 case REQ_SERVICESTATE: 123 143 return NSCommands::serviceState(NSCHelper::makelist(argLen, args)); -
trunk/modules/NSClientCompat/NSCommands.cpp
re0705d4 r079055f 82 82 state = error; 83 83 if (!ret.empty()) ret += " - "; 84 ret += exe + " : Stopped";84 ret += exe + " : not running"; 85 85 } else if (showAll) { 86 86 if (!ret.empty()) ret += " - "; -
trunk/modules/SysTray/TrayIcon.cpp
r5969055 r079055f 43 43 case WM_INITDIALOG: 44 44 addIcon(hwndDlg); 45 // return TRUE;46 45 break; 47 46 -
trunk/readme.txt
re0705d4 r079055f 1 ** ROUGH DRAFT ** 2 ** Spelling missate etc... :) ** 3 4 1 5 NSClient++ is a windows service that allows performance metrics to be gathered by Nagios 2 6 (and possibly other monitoring tools). It is an attempt to create a NSClient compatible … … 4 8 5 9 10 Installation: 11 NSClient++ -install 12 Will install the NT service 13 14 NSClient++ -uninstall 15 Will uninstall the service 16 17 NSClient++ -start 18 Will start the service 19 20 NSClient++ -stop 21 Will stop the service 22 23 NSClient++ -test 24 Will start in interactive mode: 25 enter 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. 26 It also listens to the port in this mode so it can be used to run the client standalone. 27 Notice output is *NOT* piped t othe stdard output unless you enable the console logger module. 6 28 7 29 30 31 32 33 The API is quite simple: 34 The following functions are available for a module to "export": (think DLL) 35 36 NSLoadModule 37 - Loading of modules (done when the service starts) 38 NSGetModuleName 39 - Used to get a nice name for the module. 40 NSGetModuleVersion 41 - Not really used but... 42 NSHasCommandHandler 43 - Let the "core" know it can handle commands (from nagios) 44 NSHasMessageHandler 45 - Used to let the "core" know it wants to see all log/debug/error messages that are generated. 46 NSHandleMessage 47 - Used to digest a log/debug/error message. 48 NSHandleCommand 49 - Used to (possibly) digest a command. 50 When 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 52 NSUnloadModule 53 - Used to unload and terminate "stuff" nicely. (Generally this is when the service terminates) 54 NSModuleHelperInit 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 57 So the API is quite simple and straight forward (I hope :) 58 59 To 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 85 There are a few more things to this but overall I have tried to keep things simple. 86 87 The 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 92 Also 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 94 As 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.








