Changeset 5d8cb39 in nscp
- Timestamp:
- 03/21/05 22:03:51 (8 years ago)
- Children:
- 091d894
- Parents:
- 55b33c1
- Location:
- trunk
- Files:
-
- 8 edited
-
changelog (modified) (2 diffs)
-
modules/NRPEListener/NRPESocket.cpp (modified) (3 diffs)
-
modules/NSClientCompat/NSClientCompat.cpp (modified) (3 diffs)
-
modules/NSClientCompat/NSClientCompat.h (modified) (2 diffs)
-
modules/NSClientCompat/NSCommands.cpp (modified) (7 diffs)
-
modules/NSClientCompat/NSCommands.h (modified) (2 diffs)
-
modules/NSClientListener/NSClientSocket.cpp (modified) (1 diff)
-
modules/NSClientListener/NSClientSocket.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/changelog
r55b33c1 r5d8cb39 1 1 2005-03-21 MickeM 2 2 * Fixed BUG in inject command (now things should "work" again, but far from stable) 3 + Added NRPE return code 4 * Fixed some return states to NSClientListener (not verified yet, but soon they wil lbe back in order :) 3 5 4 6 2005-03-20 MickeM … … 8 10 - Most API calls have new "return codes" (typedef:ed INT to allow for return code compiler checks) 9 11 - A lot of the old return codes have changed 10 *Preliminary NRPE support (can parse and execute incoming requests, cant return data yet, and no encryption)11 *New SimpleSocket in include/ will be used as base class for Listeners12 + Preliminary NRPE support (can parse and execute incoming requests, cant return data yet, and no encryption) 13 + New SimpleSocket in include/ will be used as base class for Listeners 12 14 * A lot of rewrite to the NSC API 13 15 14 16 2005-03-19 MickeM 15 17 * Refactored out NSCLient Listener as a separate module 16 *Added initial NRPE listener module (not yet implemented only a shell)18 + Added initial NRPE listener module (not yet implemented only a shell) 17 19 * Changed Module API (Inject function has new syntax) 18 *Added some tokenizer function to charEx19 *Added new wrapper function to inject Command20 + Added some tokenizer function to charEx 21 + Added new wrapper function to inject Command 20 22 * Minor changes in relation to refactor work 21 23 -
trunk/modules/NRPEListener/NRPESocket.cpp
rc515660 r5d8cb39 23 23 }packet; 24 24 25 static unsigned long crc32_table[256]; 26 27 /* build the crc table - must be called before calculating the crc value */ 28 void generate_crc32_table(void){ 29 unsigned long crc, poly; 30 int i, j; 31 32 poly=0xEDB88320L; 33 for(i=0;i<256;i++){ 34 crc=i; 35 for(j=8;j>0;j--){ 36 if(crc & 1) 37 crc=(crc>>1)^poly; 38 else 39 crc>>=1; 40 } 41 crc32_table[i]=crc; 42 } 43 44 return; 45 } 46 47 /* calculates the CRC 32 value for a buffer */ 48 unsigned long calculate_crc32(char *buffer, int buffer_size){ 49 register unsigned long crc; 50 int this_char; 51 int current_index; 52 53 crc=0xFFFFFFFF; 54 55 for(current_index=0;current_index<buffer_size;current_index++){ 56 this_char=(int)buffer[current_index]; 57 crc=((crc>>8) & 0x00FFFFFF) ^ crc32_table[(crc ^ this_char) & 0xFF]; 58 } 59 60 return (crc ^ 0xFFFFFFFF); 61 } 62 25 63 void NRPESocket::onAccept(SOCKET client) { 26 64 NSC_DEBUG_MSG("Accepting connection from remote host"); … … 28 66 SimpleSocketListsner::readAllDataBlock block = SimpleSocketListsner::readAll(client); 29 67 packet *p = reinterpret_cast<packet*>(block.first); 30 /*31 char* foo = new char[1024];32 sprintf(foo, "packet_version = %d, packet_type = %d, crc32 = %d, result_code = %d",33 ntohs(p->packet_version), ntohs(p->packet_type), ntohl(p->crc32_value), ntohs(p->result_code));34 35 NSC_DEBUG_MSG_STD("Incoming header: " + foo);36 */37 68 // @todo Verify versions and stuff, and ofcource add SSL (but thats in the future :) 38 69 NSC_DEBUG_MSG_STD("Incoming data: " + p->buffer); … … 40 71 charEx::token cmd = charEx::getToken(p->buffer, '!'); 41 72 std::string msg, perf; 42 NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '!', msg, perf); 73 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '!', msg, perf); 74 //QUERY_PACKET 75 packet p2; 76 strncpy(p2.buffer, (msg+"|"+perf).c_str(), 1023); 77 p2.buffer[1023] = 0; 78 p2.packet_type = htons(2); 79 p2.packet_version = htons(2); 80 p2.result_code = htons(static_cast<int>(ret)); 81 82 generate_crc32_table(); 83 p2.crc32_value = 0; 84 p2.crc32_value = htonl(calculate_crc32(reinterpret_cast<char*>(&p2),sizeof(p2))); 85 send(client, reinterpret_cast<char*>(&p2), sizeof(p2), 0); 43 86 44 87 delete [] block.first; -
trunk/modules/NSClientCompat/NSClientCompat.cpp
rc515660 r5d8cb39 99 99 #define REQ_MEMUSE 7 // Works fine! 100 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 Don t know how to use102 //#define REQ_INSTANCES 10 // ! - not implemented Don t know how to use101 //#define REQ_FILEAGE 9 // ! - not implemented Don't know how to use 102 //#define REQ_INSTANCES 10 // ! - not implemented Don't know how to use 103 103 * 104 104 * @param command … … 109 109 NSCAPI::nagiosReturn NSClientCompat::handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { 110 110 std::list<std::string> stl_args; 111 NSClientCompat::returnBundle rb; 111 112 int id = atoi(command.c_str()); 112 113 if (id == 0) … … 143 144 return NSCAPI::returnOK; 144 145 } 145 /*146 146 case REQ_SERVICESTATE: 147 return NSCommands::serviceState(NSCHelper::arrayBuffer2list(argLen, args)); 147 rb = NSCommands::serviceState(NSCHelper::arrayBuffer2list(argLen, char_args)); 148 msg = rb.msg_; 149 perf = rb.perf_; 150 return rb.code_; 151 148 152 149 153 case REQ_PROCSTATE: 150 return NSCommands::procState(NSCHelper::arrayBuffer2list(argLen, args)); 154 rb = NSCommands::procState(NSCHelper::arrayBuffer2list(argLen, char_args)); 155 msg = rb.msg_; 156 perf = rb.perf_; 157 return rb.code_; 151 158 152 159 case REQ_MEMUSE: 153 returnstrEx::itos(pdhCollector->getMemCommitLimit()) + "&" +160 msg = strEx::itos(pdhCollector->getMemCommitLimit()) + "&" + 154 161 strEx::itos(pdhCollector->getMemCommit()); 162 return NSCAPI::returnOK; 155 163 156 164 case REQ_USEDDISKSPACE: 157 return NSCommands::usedDiskSpace(NSCHelper::arrayBuffer2list(argLen, args)); 158 */ 165 rb = NSCommands::usedDiskSpace(NSCHelper::arrayBuffer2list(argLen, char_args)); 166 msg = rb.msg_; 167 perf = rb.perf_; 168 return rb.code_; 159 169 } 160 170 return NSCAPI::returnIgnored; -
trunk/modules/NSClientCompat/NSClientCompat.h
rc515660 r5d8cb39 1 #pragma once 1 2 #include "PDHCollector.h" 2 3 … … 7 8 PDHCollectorThread pdhThread; 8 9 PDHCollector *pdhCollector; 10 11 public: 12 typedef struct rB { 13 NSCAPI::nagiosReturn code_; 14 std::string msg_; 15 std::string perf_; 16 rB(NSCAPI::nagiosReturn code, std::string msg) : code_(code), msg_(msg) {} 17 rB() : code_(NSCAPI::returnUNKNOWN) {} 18 } returnBundle; 9 19 10 20 public: -
trunk/modules/NSClientCompat/NSCommands.cpp
r079055f r5d8cb39 59 59 * @todo Is this correct ? (has never been used so is most likely broken) 60 60 */ 61 std::stringNSCommands::procState(std::list<std::string> args) {61 NSClientCompat::returnBundle NSCommands::procState(std::list<std::string> args) { 62 62 if (args.empty()) 63 return "ERROR: Missing argument exception.";63 return NSClientCompat::returnBundle(NSCAPI::returnCRIT, "ERROR: Missing argument exception."); 64 64 NSPROCLST procs; 65 65 std::string ret; … … 72 72 } catch (char *c) { 73 73 NSC_LOG_ERROR_STD("ERROR: " + c); 74 return (std::string)("ERROR: ") + c;74 return NSClientCompat::returnBundle(NSCAPI::returnCRIT, (std::string)"ERROR: " + c); 75 75 } 76 76 for (std::list<std::string>::iterator it = args.begin();it!=args.end();it++) { … … 90 90 if (ret.empty()) 91 91 ret ="All processes are running."; 92 return strEx::itos(state) + "&" + ret;92 return NSClientCompat::returnBundle(state, ret); 93 93 } 94 94 … … 133 133 * @return 134 134 */ 135 std::stringNSCommands::serviceState(std::list<std::string> args) {135 NSClientCompat::returnBundle NSCommands::serviceState(std::list<std::string> args) { 136 136 if (args.empty()) 137 return "ERROR: Missing argument exception.";137 return NSClientCompat::returnBundle(NSCAPI::returnCRIT, "ERROR: Missing argument exception."); 138 138 else { 139 139 std::string ret; … … 162 162 if (ret.empty()) 163 163 ret ="All services are running."; 164 return strEx::itos(nState) + "&" + ret;164 return NSClientCompat::returnBundle(nState, ret); 165 165 } 166 166 } … … 176 176 * @return A string with a list of drive usage stats 177 177 */ 178 std::stringNSCommands::usedDiskSpace(std::list<std::string> args) {178 NSClientCompat::returnBundle NSCommands::usedDiskSpace(std::list<std::string> args) { 179 179 if (args.empty()) 180 return "ERROR: Missing argument exception.";180 return NSClientCompat::returnBundle(NSCAPI::returnCRIT, "ERROR: Missing argument exception."); 181 181 std::string ret; 182 182 for (std::list<std::string>::iterator it = args.begin();it!=args.end();it++) { … … 185 185 path += ":"; 186 186 if (GetDriveType(path.c_str()) != DRIVE_FIXED) 187 return "ERROR: Drive is not a fixed drive." + path;187 return NSClientCompat::returnBundle(NSCAPI::returnCRIT, "ERROR: Drive is not a fixed drive." + path); 188 188 ULARGE_INTEGER freeBytesAvailableToCaller; 189 189 ULARGE_INTEGER totalNumberOfBytes; 190 190 ULARGE_INTEGER totalNumberOfFreeBytes; 191 191 if (!GetDiskFreeSpaceEx(path.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) 192 return "ERROR: Could not get freespace." + path;192 return NSClientCompat::returnBundle(NSCAPI::returnCRIT, "ERROR: Could not get free space for" + path); 193 193 ret += strEx::itos(static_cast<__int64>(totalNumberOfFreeBytes.QuadPart)) + "&"; 194 194 ret += strEx::itos(static_cast<__int64>(totalNumberOfBytes.QuadPart)) + "&"; 195 195 } 196 return ret;196 return NSClientCompat::returnBundle(NSCAPI::returnUNKNOWN, ret); 197 197 } -
trunk/modules/NSClientCompat/NSCommands.h
re0705d4 r5d8cb39 2 2 3 3 #include <EnumNtSrv.h> 4 4 #include "NSClientCompat.h" 5 5 6 6 … … 8 8 typedef enum ServiceState { ok = 0, unknown = 1, error = 2 } ServiceState; 9 9 std::string cmdServiceStateCheckItem(bool bShowAll, int &nState, TNtServiceInfo &info); 10 std::stringserviceState(std::list<std::string> args);11 std::stringusedDiskSpace(std::list<std::string> args);12 std::stringprocState(std::list<std::string> args);13 } 10 NSClientCompat::returnBundle serviceState(std::list<std::string> args); 11 NSClientCompat::returnBundle usedDiskSpace(std::list<std::string> args); 12 NSClientCompat::returnBundle procState(std::list<std::string> args); 13 }; -
trunk/modules/NSClientListener/NSClientSocket.cpp
r55b33c1 r5d8cb39 85 85 std::string message, perf; 86 86 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '&', message, perf); 87 return NSCHelper::translateReturn(ret) + "&" + message + "|" + perf; 87 int c = atoi(cmd.first.c_str()); 88 switch (c) { 89 case REQ_CLIENTVERSION: 90 case REQ_UPTIME: 91 case REQ_CPULOAD: 92 case REQ_USEDDISKSPACE: 93 return message; 94 case REQ_SERVICESTATE: 95 case REQ_PROCSTATE: 96 return NSCHelper::translateReturn(ret) + "&" + message; 97 default: 98 return NSCHelper::translateReturn(ret) + "&" + message + "|" + perf; 99 } 88 100 } 89 101 -
trunk/modules/NSClientListener/NSClientSocket.h
r4f2e807 r5d8cb39 55 55 #define DEFAULT_TCP_PORT 12489 56 56 57 #define REQ_CLIENTVERSION 1 // Works fine! 58 #define REQ_CPULOAD 2 // Quirks 59 #define REQ_UPTIME 3 // Works fine! 60 #define REQ_USEDDISKSPACE 4 // Works fine! 61 #define REQ_SERVICESTATE 5 // Works fine! 62 #define REQ_PROCSTATE 6 // Works fine! 63 #define REQ_MEMUSE 7 // Works fine! 64 //#define REQ_COUNTER 8 // ! - not implemented Have to look at this, if anyone has a sample let me know... 65 //#define REQ_FILEAGE 9 // ! - not implemented Dont know how to use 66 //#define REQ_INSTANCES 10 // ! - not implemented Dont know how to use 57 67 58 68
Note: See TracChangeset
for help on using the changeset viewer.








