Changeset 1e62ed5 in nscp
- Timestamp:
- 05/16/05 18:32:31 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- af5bc4b
- Parents:
- e655f61
- Files:
-
- 12 added
- 28 edited
-
Doxyfile (modified) (2 diffs)
-
NSCPlugin.cpp (modified) (2 diffs)
-
NSCPlugin.h (modified) (1 diff)
-
NSClient++.cpp (modified) (1 diff)
-
NSClient++.sln (modified) (2 diffs)
-
NSClient++.vcproj (modified) (2 diffs)
-
changelog (modified) (1 diff)
-
docs/NRPEListener/index.html (added)
-
docs/head.html (added)
-
docs/index.html (added)
-
docs/menu.html (added)
-
docs/nscplus.css (added)
-
docs/welcome.html (added)
-
include/Mutex.h (modified) (1 diff)
-
include/NSCHelper.cpp (modified) (14 diffs)
-
include/NSCHelper.h (modified) (1 diff)
-
include/ServiceCmd.cpp (modified) (3 diffs)
-
include/Socket.cpp (modified) (4 diffs)
-
include/Socket.h (modified) (1 diff)
-
include/arrayBuffer.cpp (modified) (9 diffs)
-
include/arrayBuffer.h (modified) (2 diffs)
-
include/config.h (modified) (1 diff)
-
include/strEx.h (modified) (3 diffs)
-
include/utils.cpp (modified) (1 diff)
-
include/utils.h (modified) (6 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (9 diffs)
-
modules/CheckDisk/CheckDisk.h (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.h (modified) (2 diffs)
-
modules/CheckHelpers/CheckHelpers.cpp (added)
-
modules/CheckHelpers/CheckHelpers.def (added)
-
modules/CheckHelpers/CheckHelpers.h (added)
-
modules/CheckHelpers/CheckHelpers.vcproj (added)
-
modules/CheckHelpers/stdafx.cpp (added)
-
modules/CheckHelpers/stdafx.h (added)
-
modules/CheckSystem/CheckSystem.cpp (modified) (14 diffs)
-
modules/CheckSystem/CheckSystem.h (modified) (1 diff)
-
modules/NRPEListener/NRPEListener.cpp (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.h (modified) (3 diffs)
-
modules/NSClientListener/NSClientListener.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
Doxyfile
ra0528c4 r1e62ed5 52 52 HIDE_IN_BODY_DOCS = NO 53 53 INTERNAL_DOCS = NO 54 CASE_SENSE_NAMES = YES54 CASE_SENSE_NAMES = NO 55 55 HIDE_SCOPE_NAMES = NO 56 56 SHOW_INCLUDE_FILES = YES … … 71 71 # configuration options related to warning and progress messages 72 72 #--------------------------------------------------------------------------- 73 QUIET = NO73 QUIET = YES 74 74 WARNINGS = YES 75 75 WARN_IF_UNDOCUMENTED = YES 76 76 WARN_IF_DOC_ERROR = YES 77 77 WARN_NO_PARAMDOC = YES 78 WARN_FORMAT = "$file($line) $text"78 WARN_FORMAT = "$file($line) : $text" 79 79 WARN_LOGFILE = 80 80 #--------------------------------------------------------------------------- 81 81 # configuration options related to the input files 82 82 #--------------------------------------------------------------------------- 83 INPUT = C:\Source\ NSClient++83 INPUT = C:\Source\nscplus 84 84 FILE_PATTERNS = *.cpp \ 85 85 *.h \ -
NSCPlugin.cpp
rcea178b r1e62ed5 127 127 * Plug ins may refuse to handle the plug in (if not applicable) by returning an empty string. 128 128 * 129 * @param *command The command name (is a string encoded number for legacy commands)129 * @param command The command name (is a string encoded number for legacy commands) 130 130 * @param argLen The length of the argument buffer. 131 131 * @param **arguments The arguments for this command 132 * @param returnBuffer Return buffer for plug in to store the result of the executed command. 133 * @param returnBufferLen Size of the return buffer. 132 * @param returnMessageBuffer Return buffer for plug in to store the result of the executed command. 133 * @param returnMessageBufferLen Size of returnMessageBuffer 134 * @param returnPerfBuffer Return buffer for performance data 135 * @param returnPerfBufferLen Sixe of returnPerfBuffer 134 136 * @return Status of execution. Could be error codes, buffer length messages etc. 135 137 * @throws NSPluginException if the module is not loaded. 136 * 137 * @todo Implement return status as an enum to make it simpler for clients to see potential return stats? 138 */ 139 NSCAPI::nagiosReturn NSCPlugin::handleCommand(const char *command, const unsigned int argLen, char **arguments, char* returnMessageBuffer, unsigned int returnMessageBufferLen, char* returnPerfBuffer, unsigned int returnPerfBufferLen) { 138 */ 139 NSCAPI::nagiosReturn NSCPlugin::handleCommand(const char* command, const unsigned int argLen, char **arguments, char* returnMessageBuffer, unsigned int returnMessageBufferLen, char* returnPerfBuffer, unsigned int returnPerfBufferLen) { 140 140 if (!isLoaded()) 141 141 throw NSPluginException(file_, "Library is not loaded"); … … 150 150 * @param line The line in the file that generated the message generally __LINE__ 151 151 * @throws NSPluginException if the module is not loaded. 152 * @throws153 152 */ 154 153 void NSCPlugin::handleMessage(int msgType, const char* file, const int line, const char *message) { -
NSCPlugin.h
rcea178b r1e62ed5 42 42 * 43 43 * @param file DLL filename (for which the exception is thrown) 44 * @param error An error message (human readable format)44 * @param sError An error message (human readable format) 45 45 * @param nError Error code to be appended at the end of the string 46 46 * @todo Change this to be some form of standard error code and merge with above. -
NSClient++.cpp
r945c381 r1e62ed5 261 261 * Inject a command into the plug-in stack. 262 262 * 263 * @param buffer A command string to inject. This should be a unparsed command string such as command&arg1&arg2&arg... 264 * @return The result, empty string if no result 263 * @param command Command to inject 264 * @param argLen Length of argument buffer 265 * @param **argument Argument buffer 266 * @param *returnMessageBuffer Message buffer 267 * @param returnMessageBufferLen Length of returnMessageBuffer 268 * @param *returnPerfBuffer Performance data buffer 269 * @param returnPerfBufferLen Length of returnPerfBuffer 270 * @return The command status 265 271 */ 266 272 NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { -
NSClient++.sln
rcea178b r1e62ed5 35 35 EndProject 36 36 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckSystem", "modules\CheckSystem\CheckSystem.vcproj", "{2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}" 37 ProjectSection(ProjectDependencies) = postProject 38 EndProjectSection 39 EndProject 40 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckHelpers", "modules\CheckHelpers\CheckHelpers.vcproj", "{E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}" 37 41 ProjectSection(ProjectDependencies) = postProject 38 42 EndProjectSection … … 96 100 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release.ActiveCfg = Release|Win32 97 101 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release.Build.0 = Release|Win32 102 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug|Win32 103 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug|Win32 104 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.ActiveCfg = Distribution|Win32 105 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.Build.0 = Distribution|Win32 106 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.ActiveCfg = Release|Win32 107 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.Build.0 = Release|Win32 98 108 EndGlobalSection 99 109 GlobalSection(ExtensibilityGlobals) = postSolution -
NSClient++.vcproj
rcea178b r1e62ed5 359 359 </FileConfiguration> 360 360 <FileConfiguration 361 Name="Distribution|Win32" 362 ExcludedFromBuild="TRUE"> 361 Name="Distribution|Win32"> 363 362 <Tool 364 363 Name="VCCustomBuildTool" … … 402 401 Outputs="$(InputDir)\Dist\$(InputFileName)"/> 403 402 </FileConfiguration> 403 </File> 404 <File 405 RelativePath=".\readme.html"> 404 406 </File> 405 407 <File -
changelog
rd656933 r1e62ed5 1 2004-04-20 MickeM 1 2005-05-15 MickeM 2 + Added NRPE support for checkCounter 3 + Updated documentation 4 * Make check commands ignore case 5 + Added CheckHelpers module to alter the result of various check and similar things 6 7 2005-05-14 MickeM 8 + Added support for Volumes (CheckDisk) 9 + Added support for checking all drives of a certain kind 10 + Added support for altering filter (makes it posible to check removale drives) 11 + Created webpage and better documentation 12 13 2005-04-20 MickeM 2 14 + Added multitasking to socket listsner (it can now handle multiple connections) 3 15 * Fixed bug in NSClientListener now "seqv" in check_nt shouldn't happen. 4 16 + Added COUNTER support to NSClient and CheckSystem 5 17 6 200 4-04-19 MickeM18 2005-04-19 MickeM 7 19 + Added SSL support 8 20 + Added alot of new options -
include/Mutex.h
r945c381 r1e62ed5 98 98 * Waits for the mutex object. 99 99 * @param hMutex The mutex to use 100 * @timeout The timeout before abandoning wait 100 101 */ 101 102 MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { -
include/NSCHelper.cpp
r945c381 r1e62ed5 6 6 7 7 8 #ifdef DEBUG 8 9 /** 9 10 * Wrap a return string. … … 15 16 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 16 17 */ 17 #ifdef DEBUG18 18 NSCAPI::nagiosReturn NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::nagiosReturn defaultReturnCode /* = NSCAPI::success */) { 19 19 if (str.length() >= bufLen) … … 22 22 return defaultReturnCode; 23 23 } 24 /** 25 * Wrap a return string. 26 * This function copies a string to a char buffer making sure the buffer has the correct length. 27 * 28 * @param *buffer Buffer to copy the string to. 29 * @param bufLen Length of the buffer 30 * @param str Th string to copy 31 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 32 */ 24 33 NSCAPI::errorReturn NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::errorReturn defaultReturnCode /* = NSCAPI::success */) { 25 34 if (str.length() >= bufLen) … … 29 38 } 30 39 #else 40 /** 41 * Wrap a return string. 42 * This function copies a string to a char buffer making sure the buffer has the correct length. 43 * 44 * @param *buffer Buffer to copy the string to. 45 * @param bufLen Length of the buffer 46 * @param str Th string to copy 47 * @param defaultReturnCode The default return code 48 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 49 */ 31 50 int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode ) { 32 51 // @todo deprecate this 33 52 if (str.length() >= bufLen) 34 return -1;53 return NSCAPI::isInvalidBufferLen; 35 54 strncpy(buffer, str.c_str(), bufLen); 36 55 return defaultReturnCode; … … 60 79 return "unknown"; 61 80 } 81 /** 82 * Translate a return code into the corresponding string 83 * @param returnCode 84 * @return 85 */ 62 86 std::string NSCHelper::translateReturn(NSCAPI::nagiosReturn returnCode) { 63 87 if (returnCode == NSCAPI::returnOK) … … 110 134 * @throws NSCMHExcpetion When core pointer set is unavailable or an unknown inject error occurs. 111 135 */ 136 137 /** 138 * Inject a request command in the core (this will then be sent to the plug-in stack for processing) 139 * @param command Command to inject 140 * @param argLen The length of the argument buffer 141 * @param **argument The argument buffer 142 * @param *returnMessageBuffer Buffer to hold the returned message 143 * @param returnMessageBufferLen Length of returnMessageBuffer 144 * @param *returnPerfBuffer Buffer to hold the returned performance data 145 * @param returnPerfBufferLen returnPerfBuffer 146 * @return The returned status of the command 147 */ 112 148 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) 113 149 { … … 116 152 return fNSAPIInject(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 117 153 } 154 /** 155 * Inject a request command in the core (this will then be sent to the plug-in stack for processing) 156 * @param command Command to inject (password should not be included. 157 * @param argLen The length of the argument buffer 158 * @param **argument The argument buffer 159 * @param message The return message buffer 160 * @param perf The return performance data buffer 161 * @return The return of the command 162 */ 118 163 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommand(const char* command, const unsigned int argLen, char **argument, std::string & message, std::string & perf) 119 164 { … … 151 196 * Parses a string by splitting and makes the array and also manages return buffers and such. 152 197 * @param command The command to execute 153 * @param buffer The buffer to splitwww.ikea.se 154 198 * @param buffer The buffer to split 155 199 * @param splitChar The char to use as splitter 200 * @param message The return message buffer 201 * @param perf The return performance data buffer 156 202 * @return The result of the command 157 203 */ … … 170 216 return ret; 171 217 } 218 /** 219 * A wrapper around the InjetCommand that is simpler to use. 220 * @param command The command to execute 221 * @param buffer The buffer to split 222 * @param splitChar The char to use as splitter 223 * @param message The return message buffer 224 * @param perf The return performance data buffer 225 * @return The result of the command 226 */ 172 227 NSCAPI::nagiosReturn NSCModuleHelper::InjectSplitAndCommand(const std::string command, const std::string buffer, char splitChar, std::string & message, std::string & perf) 173 228 { … … 214 269 return ret; 215 270 } 271 /** 272 * Get a section of settings strings 273 * @param section The section to retrieve 274 * @return The keys in the section 275 */ 216 276 std::list<std::string> NSCModuleHelper::getSettingsSection(std::string section) { 217 277 if (!fNSAPIGetSettingsSection) … … 241 301 return fNSAPIGetSettingsInt(section.c_str(), key.c_str(), defaultValue); 242 302 } 243 244 245 /*************************************************************************** 246 * max_state(STATE_x, STATE_y) 247 * compares STATE_x to STATE_y and returns result based on the following 248 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL 249 * 250 * Note that numerically the above does not hold 251 ****************************************************************************/ 303 /** 304 * Returns the biggest of the two states 305 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL 306 * @param a 307 * @param b 308 * @return 309 */ 252 310 NSCAPI::nagiosReturn NSCHelper::maxState(NSCAPI::nagiosReturn a, NSCAPI::nagiosReturn b) 253 311 { … … 260 318 else if (a == NSCAPI::returnUNKNOWN || b == NSCAPI::returnUNKNOWN) 261 319 return NSCAPI::returnUNKNOWN; 262 /* 263 else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) 264 return STATE_DEPENDENT; 265 */ 266 // else 267 throw "undefined state"; 268 // return max (a, b); 269 } 270 271 320 return NSCAPI::returnUNKNOWN; 321 } 272 322 /** 273 323 * Retrieve the application name (in human readable format) from the core. … … 319 369 } 320 370 321 //////////////////////////////////////////////////////////////////////////322 // Module helper functions323 //////////////////////////////////////////////////////////////////////////324 371 namespace NSCModuleWrapper { 325 372 HINSTANCE hModule_ = NULL; … … 417 464 /** 418 465 * Wrap the HandleCommand call 419 * @param retStr The string to return to the core 420 * @param *returnBuffer A buffer to copy the return string to 421 * @param returnBufferLen length of returnBuffer 422 * @return copy status or NSCAPI::isfalse if retStr is empty 466 * @param retResult The returned result 467 * @param retMessage The returned message 468 * @param retPerformance The returned performance data 469 * @param *returnBufferMessage The return message buffer 470 * @param returnBufferMessageLen The return message buffer length 471 * @param *returnBufferPerf The return perfomance data buffer 472 * @param returnBufferPerfLen The return perfomance data buffer length 473 * @return the return code 423 474 */ 424 475 NSCAPI::nagiosReturn NSCModuleWrapper::wrapHandleCommand(NSCAPI::nagiosReturn retResult, const std::string retMessage, const std::string retPerformance, char *returnBufferMessage, unsigned int returnBufferMessageLen, char *returnBufferPerf, unsigned int returnBufferPerfLen) { -
include/NSCHelper.h
rcea178b r1e62ed5 57 57 } 58 58 #endif 59 60 /*61 inline void escalteReturnCode(NSCAPI::nagiosReturn ¤tReturnCode, NSCAPI::nagiosReturn newReturnCode) {62 if (newReturnCode == NSCAPI::returnCRIT)63 currentReturnCode = NSCAPI::returnCRIT;64 else if ((newReturnCode == NSCAPI::returnWARN) && (currentReturnCode != NSCAPI::returnCRIT) )65 currentReturnCode = NSCAPI::returnWARN;66 else if ((newReturnCode == NSCAPI::returnUNKNOWN)67 && (currentReturnCode != NSCAPI::returnCRIT)68 && (currentReturnCode != NSCAPI::returnWARN) )69 currentReturnCode = NSCAPI::returnUNKNOWN;70 }71 */72 59 inline void escalteReturnCodeToCRIT(NSCAPI::nagiosReturn ¤tReturnCode) { 73 60 currentReturnCode = NSCAPI::returnCRIT; -
include/ServiceCmd.cpp
ra0528c4 r1e62ed5 67 67 * Stars the service. 68 68 * 69 * @param szName69 * @param name The name of the service to start 70 70 * 71 71 * @author mickem … … 112 112 * Stops and removes the service 113 113 * 114 * @param szName114 * @param name The name of the service to uninstall 115 115 * 116 116 * @author mickem … … 145 145 * Stops the service 146 146 * 147 * @param szName147 * @param name The name of the serive to stop 148 148 * 149 149 * @author MickeM -
include/Socket.cpp
r945c381 r1e62ed5 3 3 #include <NSCHelper.h> 4 4 5 6 7 8 5 /** 9 * Thread procedure for the socket listener 10 * @param lpParameter Potential argument to the thread proc. 11 * @return thread exit status 12 * @todo This needs to be reworked, possibly completely redone ? 13 */ 14 15 6 * Print an error message 7 * @param error 8 */ 16 9 void simpleSocket::Socket::printError(std::string error) { 17 10 NSC_LOG_ERROR_STD(error); … … 19 12 20 13 21 void simpleSocket::Socket::readAll(DataBuffer &buffer, unsigned int tmpBufferLength /* = 1024*/) { 14 /** 15 * Read all data on the socket 16 * @param buffer 17 * @param tmpBufferLength Length of temporary buffer to use (generally larger then expected data) 18 */ 19 void simpleSocket::Socket::readAll(DataBuffer& buffer, unsigned int tmpBufferLength /* = 1024*/) { 22 20 // @todo this could be optimized a bit if we want to 23 21 // If only one buffer is needed we could "reuse" the buffer instead of copying it. … … 40 38 41 39 40 /** 41 * Startup WSA 42 * @param wVersionRequested Version to use 43 * @return stuff 44 */ 42 45 WSADATA simpleSocket::WSAStartup(WORD wVersionRequested /* = 0x202 */) { 43 46 WSADATA wsaData; … … 47 50 return wsaData; 48 51 } 52 /** 53 * Cleanup (Shutdown) WSA 54 */ 49 55 void simpleSocket::WSACleanup() { 50 56 if (::WSACleanup() != 0) -
include/Socket.h
r945c381 r1e62ed5 226 226 Listener() : pHandler_(NULL) {}; 227 227 virtual ~Listener() { 228 std::cout << "Stale process count: " << responderList_.size() << std::endl; 228 if (responderList_.size() > 0) 229 std::cout << "We had stale processes running then the socket closed." << std::endl; 229 230 // @todo check if we have stale processes here (if so log an error) 230 231 }; -
include/arrayBuffer.cpp
r1a5449e r1e62ed5 4 4 5 5 /** 6 * Make a list out of a array of char arrays (arguments type)7 * @param argLen Length of argument array8 * @param *argument[] Argument array9 * @return Argument wrapped as a list10 */6 * Make a list out of a array of char arrays (arguments type) 7 * @param argLen Length of argument array 8 * @param *argument[] Argument array 9 * @return Argument wrapped as a list 10 */ 11 11 arrayBuffer::arrayList arrayBuffer::arrayBuffer2list(const unsigned int argLen, char *argument[]) { 12 12 arrayList ret; … … 49 49 return arrayBuffer; 50 50 } 51 52 53 54 51 /** 55 52 * Joins an arrayBuffer back into a string … … 69 66 } 70 67 /** 71 * Split a string into elements as a narrayBuffer68 * Split a string into elements as a newly created arrayBuffer 72 69 * @param buffer The CharArray to split along 73 70 * @param splitChar The char to use as splitter … … 100 97 return arrayBuffer; 101 98 } 99 /** 100 * Split a string into elements as a newly created arrayBuffer 101 * @param inBuf The CharArray to split along 102 * @param splitChar The char to use as splitter 103 * @param &argLen [OUT] The length of the Array 104 * @return The arrayBuffer 105 */ 102 106 char ** arrayBuffer::split2arrayBuffer(const std::string inBuf, char splitChar, unsigned int &argLen) { 103 107 if (inBuf.empty()) … … 144 148 145 149 #ifdef _DEBUG 150 /** 151 * Test function for createEmptyArrayBuffer 152 */ 146 153 void arrayBuffer::test_createEmptyArrayBuffer() { 147 154 std::cout << "arrayBuffer::test_createEmptyArrayBuffer() : "; … … 154 161 destroyArrayBuffer(c, argLen); 155 162 } 163 /** 164 * Test function for split2arrayBuffer 165 * @param buffer 166 * @param splitter 167 * @param OUT_argLen 168 */ 156 169 void arrayBuffer::test_split2arrayBuffer_str(std::string buffer, char splitter, int OUT_argLen) { 157 170 std::cout << "arrayBuffer::test_split2arrayBuffer(" << buffer << ", ...) : "; … … 164 177 destroyArrayBuffer(c, argLen); 165 178 } 179 /** 180 * Test function for split2arrayBuffer 181 * @param buffer 182 * @param splitter 183 * @param OUT_argLen 184 */ 166 185 void arrayBuffer::test_split2arrayBuffer_char(char* buffer, char splitter, int OUT_argLen) { 167 186 std::cout << "arrayBuffer::test_split2arrayBuffer(" << buffer << ", ...) : "; … … 175 194 } 176 195 196 /** 197 * Test function for ArrayBuffer 198 */ 177 199 void arrayBuffer::run_testArrayBuffer() { 178 200 test_createEmptyArrayBuffer(); … … 195 217 test_split2arrayBuffer_char("foo&&&", '&', 4); 196 218 } 197 198 219 #endif -
include/arrayBuffer.h
r1a5449e r1e62ed5 1 1 #pragma once 2 2 3 3 /** 4 * @ingroup NSClient++ 5 * 6 * A simple namespace (wrapper) to wrap functions to manipulate an array buffer. 7 * 8 * @version 1.0 9 * first version 10 * 11 * @date 05-14-2005 12 * 13 * @author mickem 14 * 15 * @par license 16 * This code is absolutely free to use and modify. The code is provided "as is" with 17 * no expressed or implied warranty. The author accepts no liability if it causes 18 * any damage to your computer, causes your pet to fall ill, increases baldness 19 * or makes your car start emitting strange noises when you start it up. 20 * This code has no bugs, just undocumented features! 21 * 22 * @todo 23 * 24 * @bug 25 * 26 */ 4 27 namespace arrayBuffer { 5 6 28 typedef std::list<std::string> arrayList; 7 8 29 arrayList arrayBuffer2list(const unsigned int argLen, char **argument); 9 30 char ** list2arrayBuffer(const arrayList lst, unsigned int &argLen); … … 14 35 void destroyArrayBuffer(char **argument, const unsigned int argLen); 15 36 16 17 37 #ifdef _DEBUG 18 38 void test_createEmptyArrayBuffer(); 19 39 void test_split2arrayBuffer_str(std::string buffer, char splitter, int OUT_argLen); 20 40 void test_split2arrayBuffer_char(char* buffer, char splitter, int OUT_argLen); 21 22 41 void run_testArrayBuffer(); 23 42 #endif 24 25 43 } -
include/config.h
r945c381 r1e62ed5 5 5 6 6 // Version 7 #define SZVERSION "0. 0.9 rc1 2005-04-19"7 #define SZVERSION "0.3.0 a1 2005-05-16" 8 8 9 9 // internal name of the service -
include/strEx.h
rcea178b r1e62ed5 99 99 100 100 inline long long stoi64_as_BKMG(std::string s) { 101 std::string::size_type p = s.find_first_of("BMKG ");101 std::string::size_type p = s.find_first_of("BMKGT"); 102 102 if (p == std::string::npos) 103 103 return _atoi64(s.c_str()); … … 110 110 else if (s[p] == 'G') 111 111 return _atoi64(s.c_str())*1024*1024*1024; 112 else if (s[p] == 'T') 113 return _atoi64(s.c_str())*1024*1024*1024*1024; 112 114 else 113 115 return _atoi64(s.c_str()); 114 116 } 115 inline std::string itos_as_BKMG(long long i) { 116 if (i > (1024*1024*1024)) 117 return itos(i/(1024*1024*1024))+"G (" + itos(i) + "B)"; 118 if (i > (1024*1024)) 119 return itos(i/(1024*1024))+"M (" + itos(i) + "B)"; 120 if (i > (1024)) 121 return itos(i/(1024))+"K (" + itos(i) + "B)"; 122 return itos(i>>24)+"B"; 117 #define BKMG_RANGE "BKMGTP" 118 #define BKMG_SIZE 5 119 120 inline std::string itos_as_BKMG(unsigned __int64 i) { 121 unsigned __int64 cpy = i; 122 char postfix[] = BKMG_RANGE; 123 int idx = 0; 124 while ((cpy > 1024)&&(idx<BKMG_SIZE)) { 125 cpy/=1024; 126 idx++; 127 } 128 std::string ret = itos(cpy); 129 ret += postfix[idx]; 130 if (idx > 0) { 131 ret += " (" + itos(i) + "B)"; 132 } 133 return ret; 123 134 } 124 135 … … 151 162 return token(buffer.substr(0, pos-1), buffer.substr(++pos)); 152 163 } 164 165 166 template<class _E> 167 struct blind_traits : public std::char_traits<_E> 168 { 169 static bool eq(const _E& x, const _E& y) { 170 return tolower( x ) == tolower( y ); 171 } 172 static bool lt(const _E& x, const _E& y) { 173 return tolower( x ) < tolower( y ); 174 } 175 176 static int compare(const _E *x, const _E *y, size_t n) { 177 return strnicmp( x, y, n ); 178 } 179 180 // There's no memichr(), so we roll our own. It ain't rocket science. 181 static const _E * __cdecl find(const _E *buf, size_t len, const _E& ch) { 182 // Jerry says that x86s have special mojo for memchr(), so the 183 // memchr() calls end up being reasonably efficient in practice. 184 const _E *pu = (const _E *)memchr(buf, ch, len); 185 const _E *pl = (const _E *)memchr(buf, tolower( ch ), len); 186 if ( ! pu ) 187 return pl; // Might be NULL; if so, NULL's the word. 188 else if ( ! pl ) 189 return pu; 190 else 191 // If either one was NULL, we return the other; if neither is 192 // NULL, we return the lesser of the two. 193 return ( pu < pl ) ? pu : pl; 194 } 195 196 // I'm reasonably sure that this is eq() for wide characters. Maybe. 197 static bool eq_int_type(const int_type& ch1, const int_type& ch2) { 198 return char_traits<_E>::eq_int_type( tolower( ch1 ), tolower( ch2 ) ); 199 } 200 }; 201 202 // And here's our case-blind string class. 203 typedef std::basic_string<char, blind_traits<char>, std::allocator<char> > blindstr; 204 153 205 #ifdef _DEBUG 154 206 inline void test_getToken(std::string in1, char in2, std::string out1, std::string out2) { -
include/utils.cpp
rcea178b r1e62ed5 1 1 #include <utils.h> 2 2 3 4 checkHolders::Size::Size() : type_(none), value_(0) {}5 6 void checkHolders::Size::set(std::string s) {7 std::string::size_type p = s.find_first_of('%');8 if (p == std::string::npos) {9 value_ = strEx::stoi64_as_BKMG(s);10 type_ = size;11 } else {12 value_ = strEx::stoi64(s.substr(0,p));13 type_ = percentage;14 }15 }16 checkHolders::Size::checkResult checkHolders::Size::check(long long value, long long max) const {17 long long p = getValue(value, max);18 if (p == value_)19 return same;20 else if (p > value_)21 return above;22 return below;23 }24 std::string checkHolders::Size::prettyPrint(std::string name, long long value, long long max) const {25 if (type_ == percentage)26 return name + ": " + strEx::itos(getValue(value, max));27 return name + ": " + strEx::itos_as_BKMG(getValue(value, max));28 }29 30 std::string checkHolders::SizeMaxMin::printPerfHead(bool percentage, std::string name, long long value, long long total)31 {32 if (percentage)33 return name + "=" + strEx::itos(value*100/total)+ "% ";34 return name + "=" + strEx::itos(value) + ";";35 }36 std::string checkHolders::SizeMaxMin::printPerfData(bool percentage, long long value, long long total)37 {38 if (percentage) {39 if (max.hasBounds()) {40 if (max.isPercentage()) {41 return strEx::itos(max.value_) + ";";42 } else {43 return strEx::itos((max.value_*total)/100) + ";";44 }45 } else if (min.hasBounds()) {46 if (min.isPercentage()) {47 return strEx::itos(min.value_) + ";";48 } else {49 return strEx::itos((min.value_*total)/100) + ";";50 }51 }52 }53 return "0;";54 }55 56 std::string checkHolders::SizeMaxMin::printPerf(std::string name, long long value, long long total, SizeMaxMin &warn, SizeMaxMin &crit)57 {58 std::string s;59 bool bPercentage = warn.isPercentage() && crit.isPercentage();60 s = printPerfHead(bPercentage, name, value, total);61 s += warn.printPerfData(bPercentage, value, total);62 s += crit.printPerfData(bPercentage, value, total);63 s += " ";64 return s;65 }66 3 67 4 static unsigned long crc32_table[256]; -
include/utils.h
rcea178b r1e62ed5 5 5 6 6 namespace checkHolders { 7 struct Size { 7 8 typedef unsigned __int64 drive_size; 9 template <typename TType = drive_size> 10 class drive_size_handler { 11 public: 12 static TType parse(std::string s) { 13 return strEx::stoi64_as_BKMG(s); 14 } 15 static TType parse_percent(std::string s) { 16 return strEx::stoi64(s); 17 } 18 static std::string print(TType value) { 19 return strEx::itos_as_BKMG(value); 20 } 21 static std::string print_percent(TType value) { 22 return strEx::itos(value) + "%"; 23 } 24 }; 25 26 template <typename TType = __int64> 27 class int64_handler { 28 public: 29 static TType parse(std::string s) { 30 return strEx::stoi64(s); 31 } 32 static TType parse_percent(std::string s) { 33 return strEx::stoi(s); 34 } 35 static std::string print(TType value) { 36 return strEx::itos(value); 37 } 38 static std::string print_percent(TType value) { 39 return strEx::itos(value) + "%"; 40 } 41 }; 42 43 template <typename TType = drive_size, class THandler = drive_size_handler<> > 44 class Size { 45 public: 46 typedef enum { 47 above = 1, 48 below = -1, 49 same = 0, 50 } checkResult; 51 52 bool bHasBounds_; 53 TType value_; 54 55 Size() : bHasBounds_(false), value_(0) {}; 56 void set(std::string s) { 57 value_ = THandler::parse(s); 58 bHasBounds_ = true; 59 } 60 checkResult check(TType value) const { 61 if (value == value_) 62 return same; 63 else if (value > value_) 64 return above; 65 return below; 66 } 67 std::string prettyPrint(std::string name, TType value) const { 68 return name + ": " + THandler::print(value); 69 } 70 71 inline bool hasBounds() const { 72 return bHasBounds_; 73 } 74 inline bool checkMAX(TType value) const { 75 return check(value)==above; 76 } 77 inline bool checkMIN(TType value) const { 78 return check(value)==below; 79 } 80 inline std::string toString() const { 81 return strEx::itos(value_) + (type_==percentage?"%":""); 82 } 83 }; 84 85 template <typename TType = drive_size, class THandler = drive_size_handler<> > 86 class SizePercentage { 87 public: 8 88 typedef enum { 9 89 none, … … 18 98 19 99 checkTypes type_; 20 long long value_; 21 22 Size(); 23 void set(std::string s); 24 checkResult check(long long value, long long max) const; 25 std::string prettyPrint(std::string name, long long value, long long max) const; 100 TType value_; 101 102 SizePercentage() : type_(none), value_(0) {}; 103 void set(std::string s) { 104 std::string::size_type p = s.find_first_of('%'); 105 if (p == std::string::npos) { 106 value_ = THandler::parse(s); 107 type_ = size; 108 } else { 109 value_ = THandler::parse_percent(s); 110 type_ = percentage; 111 } 112 } 113 checkResult check(TType value, TType max) const { 114 unsigned long long p = getValue(value, max); 115 if (p == value_) 116 return same; 117 else if (p > value_) 118 return above; 119 return below; 120 } 121 std::string prettyPrint(std::string name, TType value, TType max) const { 122 if (type_ == percentage) 123 return name + ": " + THandler::print_percent(getValue(value, max)); 124 return name + ": " + THandler::print(getValue(value, max)); 125 } 26 126 27 127 inline bool hasBounds() const { … … 31 131 return type_ == percentage; 32 132 } 33 inline bool checkMAX( long long value, long longmax) const {133 inline bool checkMAX(TType value, TType max) const { 34 134 return check(value, max)==above; 35 135 } 36 inline bool checkMIN( long long value, long longmax) const {136 inline bool checkMIN(TType value, TType max) const { 37 137 return check(value, max)==below; 38 138 } … … 40 140 return strEx::itos(value_) + (type_==percentage?"%":""); 41 141 } 42 inline long long getValue( long long value, long longmax) const {142 inline long long getValue(TType value, TType max) const { 43 143 if (type_ == percentage) { 44 144 return static_cast<int>((value*100) / max); … … 50 150 } 51 151 }; 52 struct SizeMaxMin { 53 Size max; 54 Size min; 152 153 154 template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = Size<TType, THandler> > 155 class SizeMaxMin { 156 public: 157 THolder max; 158 THolder min; 159 typedef SizeMaxMin<TType, THandler, THolder> TMyType; 160 161 std::string printPerfData() 162 { 163 if (max.hasBounds()) { 164 return THandler::print(max.value_) + ";"; 165 } else if (min.hasBounds()) { 166 return THandler::print(min.value_) + ";"; 167 } 168 return "0;"; 169 } 170 static std::string printPerf(std::string name, TType value, TMyType &warn, TMyType &crit) 171 { 172 return name + "=" + strEx::itos(value) + ";" + warn.printPerfData() + crit.printPerfData(); 173 } 174 175 }; 176 template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizePercentage<TType, THandler> > 177 struct SizeMaxMinPercentage { 178 public: 179 THolder max; 180 THolder min; 181 typedef SizeMaxMinPercentage<TType, THandler, THolder> TMyType; 55 182 56 183 bool isPercentage() { … … 61 188 return false; 62 189 } 63 std::string printPerfData(bool percentage, long long value, long long total); 64 static std::string printPerfHead(bool percentage, std::string name, long long value, long long total); 65 static std::string printPerf(std::string name, long long value, long long total, SizeMaxMin &warn, SizeMaxMin &crit); 66 }; 190 std::string printPerfData(bool bPercentage, TType value, TType total) 191 { 192 if (bPercentage) { 193 if (max.hasBounds()) { 194 if (max.isPercentage()) { 195 return THandler::print_percent(max.value_) + ";"; 196 } else { 197 return THandler::print_percent((total*100)/(max.value_==0?1:max.value_)) + ";"; 198 } 199 } else if (min.hasBounds()) { 200 if (min.isPercentage()) { 201 return THandler::print_percent(min.value_) + ";"; 202 } else { 203 return THandler::print_percent((total*100)/(min.value_==0?1:min.value_)) + ";"; 204 } 205 } 206 } else { 207 if (max.hasBounds()) { 208 if (max.isPercentage()) { 209 return THandler::print((max.value_*total)/100) + ";"; 210 } else { 211 return THandler::print(max.value_) + ";"; 212 } 213 } else if (min.hasBounds()) { 214 if (min.isPercentage()) { 215 return THandler::print((min.value_*total)/100) + ";"; 216 } else { 217 return THandler::print(min.value_) + ";"; 218 } 219 } 220 } 221 return "0;"; 222 } 223 static std::string printPerf(std::string name, TType value, TType total, TMyType &warn, TMyType &crit) 224 { 225 std::string s; 226 bool percentage = crit.isPercentage() || warn.isPercentage(); 227 if (percentage) 228 s += name + "=" + strEx::itos(value*100/total)+ "% "; 229 else 230 s+= name + "=" + strEx::itos(value) + ";"; 231 s += warn.printPerfData(percentage, value, total); 232 s += crit.printPerfData(percentage, value, total); 233 s += " "; 234 return s; 235 } 236 237 }; 238 /* 239 template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMinPercentage<> > 240 class PerformancePrinterPercentage { 241 public: 242 static std::string printPerf(std::string name, TType value, TType total, THolder &warn, THolder &crit) 243 { 244 std::string s; 245 bool percentage = crit.isPercentage() || warn.isPercentage(); 246 if (percentage) 247 s += name + "=" + strEx::itos(value*100/total)+ "% "; 248 else 249 s+= name + "=" + strEx::itos(value) + ";"; 250 s += warn.printPerfData(percentage, value, total); 251 s += crit.printPerfData(percentage, value, total); 252 s += " "; 253 return s; 254 } 255 }; 256 template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMin<> > 257 class PerformancePrinter { 258 public: 259 static std::string printPerf(std::string name, TType value, THolder &warn, THolder &crit) 260 { 261 return name + "=" + strEx::itos(value) + ";" + warn.printPerfData() + crit.printPerfData(); 262 } 263 }; 264 */ 67 265 } 68 266 void generate_crc32_table(void); -
modules/CheckDisk/CheckDisk.cpp
rd656933 r1e62ed5 83 83 } 84 84 85 86 #define MY_FILTER_UNKNOWN 0 87 #define MY_FILTER_NO_ROOT_DIR 1 88 #define MY_FILTER_REMOVABLE 2 89 #define MY_FILTER_FIXED 4 90 #define MY_FILTER_REMOTE 8 91 #define MY_FILTER_CDROM 16 92 #define MY_FILTER_RAMDISK 32 93 85 94 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 86 // CheckFileSize87 // request: CheckFileSize <option> <option>...88 // <option> MaxWarn=<size gmkb>89 // MaxCrit=<size gmkb>90 // MinWarn=<size gmkb>91 // MinCrit=<size gmkb>92 // ShowAll93 // File=<path>94 // File:<shortname>=<path>95 //96 // Return: <return state>&<return string>...97 // <return state> 0 - No errors98 // 1 - Unknown99 // 2 - Errors100 // <size gmkb> is a size with a possible modifier letter (such as G for gigabyte, M for Megabyte, K for kilobyte etc)101 // Examples:102 // <return string> <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit>103 // test: CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.*104 // CheckFileSize105 //106 // check_nscp -H <ip> -p <port> -s <passwd> -c <commandstring>107 //108 // ./check_nscp -H 192.168.0.167 -p 1234 -s pwd -c 'CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.*'109 // WIN: 1G (2110962363B)|WIN:2110962363:1073741824:4294967296110 95 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 111 96 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 115 100 } 116 101 117 checkHolders::SizeMaxMin warn;118 checkHolders::SizeMaxMin crit;102 checkHolders::SizeMaxMinPercentage<> warn; 103 checkHolders::SizeMaxMinPercentage<> crit; 119 104 bool bShowAll = false; 120 105 bool bNSClient = false; 106 bool bCheckAll = false; 107 108 bool bFilter = false; 109 bool bFilterRemote = false; 110 bool bFilterRemovable = false; 111 bool bFilterFixed = false; 112 bool bFilterCDROM = false; 121 113 std::list<std::string> drives; 122 114 … … 135 127 } else if (p.first == "MinCrit") { 136 128 crit.min.set(p.second); 137 } else if (p.first == "ShowAll") {129 } else if (p.first == SHOW_ALL) { 138 130 bShowAll = true; 139 131 } else if (p.first == "nsclient") { 140 132 bNSClient = true; 133 } else if (p.first == "FilterType") { 134 bFilter = true; 135 if (p.second == "FIXED") { 136 bFilterFixed = true; 137 } else if (p.second == "CDROM") { 138 bFilterCDROM= true; 139 } else if (p.second == "REMOVABLE") { 140 bFilterRemovable = true; 141 } else if (p.second == "REMOTE") { 142 bFilterRemote= true; 143 } 144 } else if (p.first == "CheckAll") { 145 bCheckAll = true; 141 146 } else { 142 147 drives.push_back(p.first); 148 } 149 } 150 151 if (bCheckAll) { 152 DWORD dwDrives = GetLogicalDrives(); 153 int idx = 0; 154 while (dwDrives != 0) { 155 if (dwDrives & 0x1) { 156 std::string drv; 157 drv += static_cast<char>('A' + idx); drv += ":\\"; 158 UINT drvType = GetDriveType(drv.c_str()); 159 if ((!bFilter)&&(drvType == DRIVE_FIXED)) { 160 drives.push_back(drv); 161 } else if ((bFilter)&&(bFilterFixed)&&(drvType==DRIVE_FIXED)) { 162 drives.push_back(drv); 163 } else if ((bFilter)&&(bFilterCDROM)&&(drvType==DRIVE_CDROM)) { 164 drives.push_back(drv); 165 } else if ((bFilter)&&(bFilterRemote)&&(drvType==DRIVE_REMOTE)) { 166 drives.push_back(drv); 167 } else if ((bFilter)&&(bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) { 168 drives.push_back(drv); 169 } 170 } 171 idx++; 172 dwDrives >>= 1; 143 173 } 144 174 } … … 148 178 if (drive.length() == 1) 149 179 drive += ":"; 150 if (GetDriveType(drive.c_str()) != DRIVE_FIXED){ 151 message = "ERROR: Drive is not a fixed drive: " + drive; 152 return NSCAPI::returnUNKNOWN; 153 } 180 UINT drvType = GetDriveType(drive.c_str()); 181 182 if ((!bFilter)&&(drvType != DRIVE_FIXED)) { 183 message = "UNKNOWN: Drive is not a fixed drive: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 184 return NSCAPI::returnUNKNOWN; 185 } else if ((bFilter)&&(!bFilterFixed)&&(drvType==DRIVE_FIXED)) { 186 message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 187 return NSCAPI::returnUNKNOWN; 188 } else if ((bFilter)&&(!bFilterCDROM)&&(drvType==DRIVE_CDROM)) { 189 message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 190 return NSCAPI::returnUNKNOWN; 191 } else if ((bFilter)&&(!bFilterRemote)&&(drvType==DRIVE_REMOTE)) { 192 message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 193 return NSCAPI::returnUNKNOWN; 194 } else if ((bFilter)&&(!bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) { 195 message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 196 return NSCAPI::returnUNKNOWN; 197 } 198 154 199 ULARGE_INTEGER freeBytesAvailableToCaller; 155 200 ULARGE_INTEGER totalNumberOfBytes; 156 201 ULARGE_INTEGER totalNumberOfFreeBytes; 157 202 if (!GetDiskFreeSpaceEx(drive.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 158 message = " ERROR: Could not get free space for" + drive;203 message = "UNKNOWN: Could not get free space for: " + drive; 159 204 return NSCAPI::returnUNKNOWN; 160 205 } … … 165 210 } else { 166 211 std::string tStr; 167 long longusedSpace = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart;168 long longtotalSpace = totalNumberOfBytes.QuadPart;212 checkHolders::drive_size usedSpace = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 213 checkHolders::drive_size totalSpace = totalNumberOfBytes.QuadPart; 169 214 if (crit.max.hasBounds() && crit.max.checkMAX(usedSpace, totalSpace)) { 170 message += crit.max.prettyPrint(drive, usedSpace, totalSpace);215 tStr += crit.max.prettyPrint(drive, usedSpace, totalSpace) + " > critical"; 171 216 NSCHelper::escalteReturnCodeToCRIT(returnCode); 172 217 } else if (crit.min.hasBounds() && crit.min.checkMIN(usedSpace, totalSpace)) { 173 tStr = crit.min.prettyPrint(drive, usedSpace, totalSpace) ;218 tStr = crit.min.prettyPrint(drive, usedSpace, totalSpace) + " < critical"; 174 219 NSCHelper::escalteReturnCodeToCRIT(returnCode); 175 220 } else if (warn.max.hasBounds() && warn.max.checkMAX(usedSpace, totalSpace)) { 176 tStr = warn.max.prettyPrint(drive, usedSpace, totalSpace) ;221 tStr = warn.max.prettyPrint(drive, usedSpace, totalSpace) + " > warning"; 177 222 NSCHelper::escalteReturnCodeToWARN(returnCode); 178 223 } else if (warn.min.hasBounds() && warn.min.checkMIN(usedSpace, totalSpace)) { 179 tStr = warn.min.prettyPrint(drive, usedSpace, totalSpace) ;224 tStr = warn.min.prettyPrint(drive, usedSpace, totalSpace) + " < warning"; 180 225 NSCHelper::escalteReturnCodeToWARN(returnCode); 181 226 } else if (bShowAll) { 182 227 tStr = drive + ": " + strEx::itos_as_BKMG(usedSpace); 183 228 } 184 perf += checkHolders::SizeMaxMin ::printPerf(drive, usedSpace, totalSpace, warn, crit);229 perf += checkHolders::SizeMaxMinPercentage<>::printPerf(drive, usedSpace, totalSpace, warn, crit); 185 230 if (!message.empty() && !tStr.empty()) 186 231 message += ", "; … … 191 236 if (message.empty()) 192 237 message = "All drive sizes are within bounds."; 238 else 239 message = NSCHelper::translateReturn(returnCode) + ": " + message; 193 240 return returnCode; 194 241 } … … 246 293 } else if (p.first == "MinCrit") { 247 294 minCrit = strEx::stoi64_as_BKMG(p.second); 248 } else if (p.first == "ShowAll") {295 } else if (p.first == SHOW_ALL) { 249 296 bShowAll = true; 250 297 } else if (p.first.find(":") != std::string::npos) { … … 295 342 if (message.empty()) 296 343 message = "OK all file sizes are within bounds."; 344 else 345 message = NSCHelper::translateReturn(returnCode) + ": " + message; 297 346 return returnCode; 298 347 } … … 301 350 #define BUFFER_SIZE 1024*64 302 351 303 NSCAPI::nagiosReturn CheckDisk::handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) {352 NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { 304 353 if (command == "CheckFileSize") { 305 354 return CheckFileSize(argLen, char_args, msg, perf); -
modules/CheckDisk/CheckDisk.h
rcea178b r1e62ed5 1 1 NSC_WRAPPERS_MAIN(); 2 #include <config.h> 3 #include <strEx.h> 2 4 3 5 class CheckDisk { … … 14 16 bool hasCommandHandler(); 15 17 bool hasMessageHandler(); 16 NSCAPI::nagiosReturn handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &message, std::string &perf);18 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 17 19 18 20 // Check commands -
modules/CheckEventLog/CheckEventLog.cpp
r1a5449e r1e62ed5 296 296 #define BUFFER_SIZE 1024*64 297 297 298 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {298 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 299 299 if (command != "CheckEventLog") 300 300 return NSCAPI::returnIgnored; -
modules/CheckEventLog/CheckEventLog.h
r1eef1ee r1e62ed5 1 1 NSC_WRAPPERS_MAIN(); 2 3 #include <strEx.h> 2 4 3 5 class CheckEventLog { … … 14 16 bool hasCommandHandler(); 15 17 bool hasMessageHandler(); 16 NSCAPI::nagiosReturn handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &message, std::string &perf);18 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 17 19 }; -
modules/CheckSystem/CheckSystem.cpp
r945c381 r1e62ed5 84 84 */ 85 85 NSCModuleWrapper::module_version CheckSystem::getModuleVersion() { 86 NSCModuleWrapper::module_version version = {0, 0, 1};86 NSCModuleWrapper::module_version version = {0, 3, 0 }; 87 87 return version; 88 88 } … … 113 113 * @return 114 114 */ 115 NSCAPI::nagiosReturn CheckSystem::handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) {115 NSCAPI::nagiosReturn CheckSystem::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { 116 116 std::list<std::string> stl_args; 117 117 CheckSystem::returnBundle rb; 118 118 if (command == "checkCPU") { 119 return checkCPU( command,argLen, char_args, msg, perf);119 return checkCPU(argLen, char_args, msg, perf); 120 120 } else if (command == "checkUpTime") { 121 return checkUpTime( command,argLen, char_args, msg, perf);121 return checkUpTime(argLen, char_args, msg, perf); 122 122 } else if (command == "checkServiceState") { 123 return checkServiceState( command,argLen, char_args, msg, perf);123 return checkServiceState(argLen, char_args, msg, perf); 124 124 } else if (command == "checkProcState") { 125 return checkProcState( command,argLen, char_args, msg, perf);125 return checkProcState(argLen, char_args, msg, perf); 126 126 } else if (command == "checkMem") { 127 return checkMem( command,argLen, char_args, msg, perf);127 return checkMem(argLen, char_args, msg, perf); 128 128 } else if (command == "checkCounter") { 129 return checkCounter( command,argLen, char_args, msg, perf);129 return checkCounter(argLen, char_args, msg, perf); 130 130 } 131 131 return NSCAPI::returnIgnored; … … 135 135 // checkCPU warn=80 crit=90 time=20m time=10s time=4 showAll 136 136 // checkCPU 20 10 4 nsclient 137 NSCAPI::nagiosReturn CheckSystem::checkCPU(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf)137 NSCAPI::nagiosReturn CheckSystem::checkCPU(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 138 138 { 139 139 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 208 208 // checkUpTime crit=1d warn=6h 209 209 // checkUpTime nsclient 210 NSCAPI::nagiosReturn CheckSystem::checkUpTime(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf)210 NSCAPI::nagiosReturn CheckSystem::checkUpTime(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 211 211 { 212 212 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 234 234 PDHCollector *pObject = pdhThread.getThread(); 235 235 assert(pObject); 236 long long uptime = pObject->getUptime();236 unsigned long long uptime = pObject->getUptime(); 237 237 if (bNSCLientCompatible) { 238 238 msg = strEx::itos(uptime); … … 270 270 *</pre> 271 271 * 272 * @param args 273 * @return 274 */ 275 NSCAPI::nagiosReturn CheckSystem::checkServiceState(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 272 * @param command Command to execute 273 * @param argLen The length of the argument buffer 274 * @param **char_args The argument buffer 275 * @param &msg String to put message in 276 * @param &perf String to put performance data in 277 * @return The status of the command 278 */ 279 NSCAPI::nagiosReturn CheckSystem::checkServiceState(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 276 280 { 277 281 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 330 334 331 335 332 // checkMem showAll maxWarn=50 maxCrit=75 333 NSCAPI::nagiosReturn CheckSystem::checkMem(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 336 /** 337 * Check availible memory and return various check results 338 * Example: checkMem showAll maxWarn=50 maxCrit=75 339 * 340 * @param command Command to execute 341 * @param argLen The length of the argument buffer 342 * @param **char_args The argument buffer 343 * @param &msg String to put message in 344 * @param &perf String to put performance data in 345 * @return The status of the command 346 */ 347 NSCAPI::nagiosReturn CheckSystem::checkMem(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 334 348 { 335 349 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 343 357 bool bNSCLientCompatible = false; 344 358 345 checkHolders::SizeMaxMin warn;346 checkHolders::SizeMaxMin crit;359 checkHolders::SizeMaxMinPercentage<> warn; 360 checkHolders::SizeMaxMinPercentage<> crit; 347 361 348 362 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { … … 390 404 tStr = "page: " + strEx::itos_as_BKMG(pageCommit); 391 405 } 392 perf += checkHolders::SizeMaxMin ::printPerf("page", pageCommit, pageCommitLimit, warn, crit);406 perf += checkHolders::SizeMaxMinPercentage<>::printPerf("page", pageCommit, pageCommitLimit, warn, crit); 393 407 msg += tStr; 394 408 } 395 409 if (msg.empty()) 396 msg ="Memory ok."; 410 msg = "OK memory within bounds."; 411 else 412 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 397 413 return returnCode; 398 414 } … … 419 435 } 420 436 421 NSCAPI::nagiosReturn CheckSystem::checkProcState(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 437 /** 438 * Check process state and return result 439 * 440 * @param command Command to execute 441 * @param argLen The length of the argument buffer 442 * @param **char_args The argument buffer 443 * @param &msg String to put message in 444 * @param &perf String to put performance data in 445 * @return The status of the command 446 */ 447 NSCAPI::nagiosReturn CheckSystem::checkProcState(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 422 448 { 423 449 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 482 508 } 483 509 484 NSCAPI::nagiosReturn CheckSystem::checkCounter(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 510 /** 511 * Check a counter and return the value 512 * 513 * @param command Command to execute 514 * @param argLen The length of the argument buffer 515 * @param **char_args The argument buffer 516 * @param &msg String to put message in 517 * @param &perf String to put performance data in 518 * @return The status of the command 519 * 520 * @todo add parsing support for NRPE 521 */ 522 NSCAPI::nagiosReturn CheckSystem::checkCounter(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 485 523 { 486 524 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 489 527 return NSCAPI::returnUNKNOWN; 490 528 } 491 std::list<std:: string> counters;492 NSCAPI::nagiosReturn ret = NSCAPI::returnOK;529 std::list<std::pair<std::string,std::string> > counters; 530 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 493 531 bool bShowAll = false; 494 532 bool bNSCLientCompatible = false; 533 534 checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> > warn; 535 checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> > crit; 495 536 496 537 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { … … 500 541 else if (t.first == SHOW_FAIL) { 501 542 bShowAll = false; 543 } else if (t.first == "MaxWarn") { 544 warn.max.set(t.second); 545 } else if (t.first == "MinWarn") { 546 warn.min.set(t.second); 547 } else if (t.first == "MaxCrit") { 548 crit.max.set(t.second); 549 } else if (t.first == "MinCrit") { 550 crit.min.set(t.second); 502 551 } else if (t.first == NSCLIENT) { 503 552 bNSCLientCompatible = true; 504 } else if (t.first == "counter") { 505 counters.push_back(t.second); 553 } else if (t.first == "Counter") { 554 counters.push_back(std::pair<std::string,std::string>("",t.second)); 555 } else if (t.first.find(":") != std::string::npos) { 556 std::pair<std::string,std::string> t2 = strEx::split(t.first,":"); 557 if (t2.first == "Counter") { 558 counters.push_back(std::pair<std::string,std::string>(t2.second,t.second)); 559 } else { 560 msg = "Unknown command: " + t.first; 561 return NSCAPI::returnUNKNOWN; 562 } 506 563 } else { 507 counters.push_back( t.first);508 } 509 } 510 511 for (std::list<std:: string>::iterator it = counters.begin(); it != counters.end(); ++it) {564 counters.push_back(std::pair<std::string,std::string>("",t.first)); 565 } 566 } 567 568 for (std::list<std::pair<std::string,std::string> >::iterator it = counters.begin(); it != counters.end(); ++it) { 512 569 try { 513 570 try { 514 571 PDH::PDHQuery pdh; 515 572 PDHCollectors::StaticPDHCounterListener counter; 516 pdh.addCounter((*it) , &counter);573 pdh.addCounter((*it).second, &counter); 517 574 pdh.open(); 518 575 pdh.collect(); 519 msg += strEx::itos(counter.getValue()); 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; 600 } 601 520 602 pdh.close(); 521 603 } catch (const PDH::PDHException &e) { … … 531 613 } 532 614 if (msg.empty()) 533 msg ="uhmm..."; 534 return ret; 615 msg = "OK all counters within bounds."; 616 else 617 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 618 return returnCode; 535 619 } 536 620 NSC_WRAPPERS_MAIN_DEF(gNSClientCompat); -
modules/CheckSystem/CheckSystem.h
r945c381 r1e62ed5 29 29 bool hasCommandHandler(); 30 30 bool hasMessageHandler(); 31 NSCAPI::nagiosReturn handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf);31 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 32 32 33 33 34 NSCAPI::nagiosReturn checkCPU(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf);35 NSCAPI::nagiosReturn checkUpTime(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf);36 NSCAPI::nagiosReturn checkServiceState(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf);37 NSCAPI::nagiosReturn checkMem(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf);38 NSCAPI::nagiosReturn checkProcState(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf);39 NSCAPI::nagiosReturn checkCounter(const std::string command, constunsigned int argLen, char **char_args, std::string &msg, std::string &perf);34 NSCAPI::nagiosReturn checkCPU(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 35 NSCAPI::nagiosReturn checkUpTime(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 36 NSCAPI::nagiosReturn checkServiceState(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 37 NSCAPI::nagiosReturn checkMem(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 38 NSCAPI::nagiosReturn checkProcState(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 39 NSCAPI::nagiosReturn checkCounter(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 40 40 41 41 -
modules/NRPEListener/NRPEListener.cpp
r945c381 r1e62ed5 38 38 if (t.first.empty() || t.second.empty()) { 39 39 NSC_LOG_ERROR_STD("Invalid command definition: " + (*it)); 40 } else 41 addCommand(t.first, t.second); 40 } else { 41 addCommand(t.first.c_str(), t.second); 42 } 42 43 } 43 44 … … 96 97 97 98 98 NSCAPI::nagiosReturn NRPEListener::handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {99 NSCAPI::nagiosReturn NRPEListener::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 99 100 commandList::iterator it = commands.find(command); 100 101 if (it == commands.end()) -
modules/NRPEListener/NRPEListener.h
rd656933 r1e62ed5 10 10 simpleSSL::Listener socket_ssl_; 11 11 simpleSocket::Listener<> socket_; 12 typedef std::map<st d::string, std::string> commandList;12 typedef std::map<strEx::blindstr, std::string> commandList; 13 13 commandList commands; 14 14 unsigned int timeout; … … 25 25 bool hasCommandHandler(); 26 26 bool hasMessageHandler(); 27 NSCAPI::nagiosReturn handleCommand(const st d::stringcommand, const unsigned int argLen, char **char_args, std::string &message, std::string &perf);27 NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 28 28 29 29 private: … … 54 54 NRPEPacket handlePacket(NRPEPacket p); 55 55 int executeNRPECommand(std::string command, std::string &msg, std::string &perf); 56 void addCommand(st d::stringkey, std::string args) {56 void addCommand(strEx::blindstr key, std::string args) { 57 57 commands[key] = args; 58 58 } -
modules/NSClientListener/NSClientListener.cpp
r945c381 r1e62ed5 63 63 } 64 64 65 /** 66 * Main command parser and delegator. 67 * This also handles a lot of the simpler responses (though some are deferred to other helper functions) 68 * 69 #define REQ_CLIENTVERSION 1 // Works fine! 70 #define REQ_CPULOAD 2 // Quirks 71 - Needs settings for default buffer size (backlog) and possibly other things. 72 - Buffer needs to be synced with the client (don't know the size of that) 73 - I think the idea was that the buffer would recursive to make a smaller memory footprint. 74 (ie. the first level buffer have samples from every second, next level samples from every minute, next level hours etc...) 75 (and I don't know the status of this, doesn't seem to be that way) 76 #define REQ_UPTIME 3 // Works fine! 77 #define REQ_USEDDISKSPACE 4 // Works fine! 78 #define REQ_SERVICESTATE 5 // Works fine! 79 #define REQ_PROCSTATE 6 // Works fine! 80 #define REQ_MEMUSE 7 // Works fine! 81 //#define REQ_COUNTER 8 // ! - not implemented Have to look at this, if anyone has a sample let me know... 82 //#define REQ_FILEAGE 9 // ! - not implemented Don't know how to use 83 //#define REQ_INSTANCES 10 // ! - not implemented Don't know how to use 84 * 85 */ 65 86 66 87 std::string NSClientListener::parseRequest(std::string buffer) {
Note: See TracChangeset
for help on using the changeset viewer.








