- Timestamp:
- 03/20/05 20:54:25 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- c6e008c
- Parents:
- 2a94f3f
- Location:
- modules
- Files:
-
- 12 edited
-
CheckDisk/CheckDisk.cpp (modified) (5 diffs)
-
CheckDisk/CheckDisk.h (modified) (1 diff)
-
CheckEventLog/CheckEventLog.cpp (modified) (3 diffs)
-
CheckEventLog/CheckEventLog.h (modified) (1 diff)
-
NRPEListener/NRPEListener.cpp (modified) (2 diffs)
-
NRPEListener/NRPEListener.h (modified) (2 diffs)
-
NRPEListener/NRPEListener.vcproj (modified) (2 diffs)
-
NRPEListener/NRPESocket.cpp (modified) (2 diffs)
-
NRPEListener/NRPESocket.h (modified) (2 diffs)
-
NSClientCompat/NSClientCompat.cpp (modified) (2 diffs)
-
NSClientCompat/NSClientCompat.h (modified) (1 diff)
-
NSClientListener/NSClientSocket.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
modules/CheckDisk/CheckDisk.cpp
r8223547 r1eef1ee 82 82 } 83 83 84 std::string CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args) {84 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 85 85 // CheckFileSize 86 86 // request: CheckFileSize&<option>&<option>... … … 108 108 // WIN: 1G (2110962363B)|WIN:2110962363:1073741824:4294967296 109 109 NSC_DEBUG_MSG("CheckFileSize"); 110 std::string perfData; 111 std::string ret; 112 NSCAPI::returnCodes returnCode = NSCAPI::returnOK; 110 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 113 111 std::list<std::string> args = NSCHelper::arrayBuffer2list(argLen, char_args); 114 if (args.empty()) 115 return "Missing argument(s)."; 112 if (args.empty()) { 113 message = "Missing argument(s)."; 114 return NSCAPI::returnCRIT; 115 } 116 116 long long maxWarn = 0; 117 117 long long maxCrit = 0; … … 142 142 paths.push_back(std::pair<std::string,std::string>(p2.second,p.second)); 143 143 } else { 144 return "Unknown command: " + p.first; 144 message = "Unknown command: " + p.first; 145 return NSCAPI::returnCRIT; 145 146 } 146 147 } else { 147 return "Unknown command: " + p.first; 148 message = "Unknown command: " + p.first; 149 return NSCAPI::returnCRIT; 148 150 } 149 151 } … … 177 179 } 178 180 if (!(*pit).first.empty()) 179 perf Data+= (*pit).first + "=" + strEx::itos(sizeFinder.getSize()) + ";" + strEx::itos(maxWarn) + ";" + strEx::itos(maxCrit) + " ";180 if (! ret.empty() && !tstr.empty())181 ret+= ", ";181 perf += (*pit).first + "=" + strEx::itos(sizeFinder.getSize()) + ";" + strEx::itos(maxWarn) + ";" + strEx::itos(maxCrit) + " "; 182 if (!message.empty() && !tstr.empty()) 183 message += ", "; 182 184 if (!tstr.empty()) 183 ret += tstr; 184 } 185 if (ret.empty()) 186 ret = "OK all file sizes are within bounds."; 187 if (!perfData.empty()) 188 ret += "|" + perfData; 189 return NSCHelper::returnNSCP(returnCode, ret); 185 message += tstr; 186 } 187 if (message.empty()) 188 message = "OK all file sizes are within bounds."; 189 return returnCode; 190 190 } 191 191 … … 193 193 #define BUFFER_SIZE 1024*64 194 194 195 std::string CheckDisk::handleCommand(const std::string command, const unsigned int argLen, char **char_args) {195 NSCAPI::nagiosReturn CheckDisk::handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { 196 196 if (command == "CheckFileSize") { 197 return CheckFileSize(argLen, char_args );197 return CheckFileSize(argLen, char_args, msg, perf); 198 198 // } else if (command == "CheckFileDate") { 199 199 } 200 return "";200 return NSCAPI::returnIgnored; 201 201 } 202 202 -
modules/CheckDisk/CheckDisk.h
r36c340d r1eef1ee 14 14 bool hasCommandHandler(); 15 15 bool hasMessageHandler(); 16 std::string handleCommand(const std::string command, const unsigned int argLen, char **args);16 NSCAPI::nagiosReturn handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 17 17 18 18 // Check commands 19 std::string CheckFileSize(const unsigned int argLen, char **char_args);19 NSCAPI::nagiosReturn CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 20 20 }; -
modules/CheckEventLog/CheckEventLog.cpp
r8223547 r1eef1ee 296 296 #define BUFFER_SIZE 1024*64 297 297 298 std::string CheckEventLog::handleCommand(const std::string command, const unsigned int argLen, char **char_args) {298 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 299 299 if (command != "CheckEventLog") 300 return "";301 NSCAPI:: returnCodesrCode = NSCAPI::returnOK;300 return NSCAPI::returnIgnored; 301 NSCAPI::nagiosReturn rCode = NSCAPI::returnOK; 302 302 std::list<std::string> args = NSCHelper::arrayBuffer2list(argLen, char_args); 303 if (args.size() < 2) 304 return "Missing argument"; 303 if (args.size() < 2) { 304 message = "Missing argument"; 305 return NSCAPI::returnCRIT; 306 } 305 307 std::string ret; 306 308 bool critical = false; … … 310 312 buildQury(query, args); 311 313 } catch (std::string s) { 312 return NSCHelper::returnNSCP(NSCAPI::returnUNKNOWN, s); 314 message = s; 315 return NSCAPI::returnCRIT; 313 316 } 314 317 NSC_DEBUG_MSG_STD("Base query: " + query.toString()); 315 318 316 319 HANDLE hLog = OpenEventLog(NULL, logFile.c_str()); 317 if (hLog == NULL) 318 return NSCHelper::returnNSCP(NSCAPI::returnUNKNOWN, "Could not open the Application event log."); 320 if (hLog == NULL) { 321 message = "Could not open the Application event log."; 322 return NSCAPI::returnUNKNOWN; 323 } 319 324 320 325 DWORD dwThisRecord, dwRead, dwNeeded; … … 403 408 if (query.truncate != 0) 404 409 ret = ret.substr(0, query.truncate); 405 return NSCHelper::returnNSCP(rCode, ret); 410 message = ret; 411 return rCode; 406 412 } 407 413 -
modules/CheckEventLog/CheckEventLog.h
ra0528c4 r1eef1ee 14 14 bool hasCommandHandler(); 15 15 bool hasMessageHandler(); 16 std::string handleCommand(const std::string command, const unsigned int argLen, char **args);16 NSCAPI::nagiosReturn handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 17 17 }; -
modules/NRPEListener/NRPEListener.cpp
r2a94f3f r1eef1ee 22 22 23 23 bool NRPEListener::loadModule() { 24 socketThreadManager.createThread(NULL); 24 25 return true; 25 26 } 26 27 bool NRPEListener::unloadModule() { 28 socketThreadManager.exitThread(); 27 29 return true; 28 30 } … … 44 46 45 47 46 std::string NRPEListener::handleCommand(const std::string command, const unsigned int argLen, char **char_args) {47 return "";48 NSCAPI::nagiosReturn NRPEListener::handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 49 return NSCAPI::returnIgnored; 48 50 } 49 51 -
modules/NRPEListener/NRPEListener.h
r2a94f3f r1eef1ee 1 1 NSC_WRAPPERS_MAIN(); 2 3 4 #include "NRPESocket.h" 5 #include <Socket.h> 2 6 3 7 class NRPEListener { 4 8 private: 9 NRPESocketThread socketThreadManager; 5 10 6 11 public: … … 14 19 bool hasCommandHandler(); 15 20 bool hasMessageHandler(); 16 std::string handleCommand(const std::string command, const unsigned int argLen, char **args);21 NSCAPI::nagiosReturn handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 17 22 }; 23 -
modules/NRPEListener/NRPEListener.vcproj
r2a94f3f r1eef1ee 134 134 </File> 135 135 <File 136 RelativePath="..\..\include\Socket.cpp"> 137 </File> 138 <File 136 139 RelativePath=".\stdafx.cpp"> 137 140 <FileConfiguration … … 166 169 </File> 167 170 <File 171 RelativePath="..\..\include\Socket.h"> 172 </File> 173 <File 168 174 RelativePath=".\stdafx.h"> 169 175 </File> -
modules/NRPEListener/NRPESocket.cpp
r2a94f3f r1eef1ee 6 6 * Default c-tor 7 7 */ 8 NRPESocket::NRPESocket(): hStopEvent(NULL) {8 NRPESocket::NRPESocket(): SimpleSocketListsner(DEFAULT_NRPE_PORT) { 9 9 } 10 10 … … 12 12 } 13 13 14 typedef short int16_t; 15 typedef unsigned long u_int32_t; 14 16 15 /** 16 * Thread procedure for the socket listener 17 * @param lpParameter Potential argument to the thread proc. 18 * @return thread exit status 19 * @todo This needs to be reworked, possibly completely redone ? 20 */ 21 DWORD NRPESocket::threadProc(LPVOID lpParameter) 22 { 23 hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 24 if (!hStopEvent) { 25 NSC_LOG_ERROR_STD("Create StopEvent failed: " + strEx::itos(GetLastError())); 26 return 0; 27 } 17 typedef struct packet_struct{ 18 int16_t packet_version; 19 int16_t packet_type; 20 u_int32_t crc32_value; 21 int16_t result_code; 22 char buffer[1024]; 23 }packet; 28 24 29 WSADATA wsaData; 30 sockaddr_in local; 31 int wsaret=WSAStartup(0x101,&wsaData); 32 if(wsaret!=0) { 33 NSC_LOG_ERROR_STD("WSA Startup failed: " + strEx::itos(wsaret)); 34 return 0; 35 } 25 void NRPESocket::onAccept(SOCKET client) { 26 NSC_DEBUG_MSG("Accepting connection from remote host"); 36 27 37 local.sin_family=AF_INET; 38 local.sin_addr.s_addr=INADDR_ANY; 39 local.sin_port=htons(static_cast<u_short>(NSCModuleHelper::getSettingsInt("NRPE", "port", DEFAULT_NRPE_PORT))); 40 server=socket(AF_INET,SOCK_STREAM,0); 41 if(server==INVALID_SOCKET) { 42 WSACleanup(); 43 NSC_LOG_ERROR_STD("Could not create listening socket: " + strEx::itos(GetLastError())); 44 return 0; 45 } 28 SimpleSocketListsner::readAllDataBlock block = SimpleSocketListsner::readAll(client); 29 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)); 46 34 47 if(bind(server,(sockaddr*)&local,sizeof(local))!=0) { 48 closesocket(server); 49 WSACleanup(); 50 NSC_LOG_ERROR_STD("Could not bind socket: " + strEx::itos(GetLastError())); 51 return 0; 52 } 35 NSC_DEBUG_MSG_STD("Incoming header: " + foo); 36 */ 37 // @todo Verify versions and stuff, and ofcource add SSL (but thats in the future :) 38 NSC_DEBUG_MSG_STD("Incoming data: " + p->buffer); 53 39 54 if(listen(server,10)!=0) { 55 closesocket(server); 56 WSACleanup(); 57 NSC_LOG_ERROR_STD("Could not open socket: " + strEx::itos(GetLastError())); 58 return 0; 59 } 40 charEx::token cmd = charEx::getToken(p->buffer, '!'); 41 std::string msg, perf; 42 NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '!', msg, perf); 60 43 61 SOCKET client; 62 sockaddr_in from; 63 int fromlen=sizeof(from); 64 #define RECV_BUFFER_LEN 1024 65 while (!(WaitForSingleObject(hStopEvent, 100) == WAIT_OBJECT_0)) { 66 client=accept(server, (struct sockaddr*)&from,&fromlen); 67 if (client != INVALID_SOCKET) { 68 char *buff = new char[RECV_BUFFER_LEN+1]; 69 int n=recv(client,buff,RECV_BUFFER_LEN,0); 70 if ((n!=SOCKET_ERROR )&&(n > 0)&&(n < RECV_BUFFER_LEN)) { 71 buff[n] = '\0'; 72 NSC_DEBUG_MSG("Incoming data: "); 73 NSC_DEBUG_MSG(buff); 74 std::string ret = "fool"; //parseCommand(buff); 75 NSC_DEBUG_MSG("Outgoing data: "); 76 NSC_DEBUG_MSG(ret.c_str()); 77 send(client, ret.c_str(), ret.length(), 0); 78 } else { 79 std::string str = "ERROR: Unknown socket error"; 80 send(client,str.c_str(),str.length(),0); 81 } 82 delete [] buff; 83 closesocket(client); 84 } 85 } 86 closesocket(server); 87 WSACleanup(); 88 NSC_DEBUG_MSG("Socket closed!"); 89 return 0; 44 delete [] block.first; 45 closesocket(client); 90 46 } 91 47 92 /**93 * Exit thread callback proc.94 * This is called by the thread manager when the thread should initiate a shutdown procedure.95 * The thread manager is responsible for waiting for the actual termination of the thread.96 */97 void NRPESocket::exitThread(void) {98 NSC_DEBUG_MSG("Requesting shutdown!");99 if (!SetEvent(hStopEvent)) {100 NSC_LOG_ERROR_STD("SetStopEvent failed");101 }102 } -
modules/NRPEListener/NRPESocket.h
r2a94f3f r1eef1ee 4 4 #include <Mutex.h> 5 5 #include <WinSock2.h> 6 #include <Socket.h> 6 7 /** 7 8 * @ingroup NSClient++ … … 28 29 * 29 30 */ 30 class NRPESocket { 31 32 #define DEFAULT_NRPE_PORT 5666 33 34 35 class NRPESocket : public SimpleSocketListsner { 31 36 private: 32 MutexHandler mutexHandler;33 SOCKET server;34 HANDLE hStopEvent;35 37 36 38 public: 37 39 NRPESocket(); 38 40 virtual ~NRPESocket(); 39 DWORD threadProc(LPVOID lpParameter);40 void exitThread(void);41 41 42 42 private: 43 bool isRunning(void); 44 void stopRunning(void); 45 void startRunning(void); 46 std::list<std::string> split(char* buffer); 47 std::string parseCommand(char* request); 43 virtual void onAccept(SOCKET client); 48 44 }; 49 #define DEFAULT_NRPE_PORT 566650 51 45 52 46 -
modules/NSClientCompat/NSClientCompat.cpp
r8223547 r1eef1ee 107 107 * @return 108 108 */ 109 std::string NSClientCompat::handleCommand(const std::string command, const unsigned int argLen, char **args) {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 111 int id = atoi(command.c_str()); 112 112 if (id == 0) 113 return "";113 return NSCAPI::returnIgnored; 114 114 switch (id) { 115 115 case REQ_CLIENTVERSION: 116 116 { 117 std::string version= NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern");118 if ( version== "modern")119 returnNSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString();120 return version;117 std::string msg = NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern"); 118 if (msg == "modern") 119 msg = NSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString(); 120 return NSCAPI::returnOK; 121 121 } 122 122 case REQ_UPTIME: 123 return strEx::itos(pdhCollector->getUptime()); 123 msg= strEx::itos(pdhCollector->getUptime()); 124 return NSCAPI::returnOK; 124 125 125 126 case REQ_CPULOAD: 126 127 { 127 stl_args = NSCHelper::arrayBuffer2list(argLen, args); 128 if (stl_args.empty()) 129 return "ERROR: Missing argument exception."; 130 std::string ret; 128 stl_args = NSCHelper::arrayBuffer2list(argLen, char_args); 129 if (stl_args.empty()) { 130 msg = "ERROR: Missing argument exception."; 131 return NSCAPI::returnCRIT; 132 } 131 133 while (!stl_args.empty()) { 132 134 std::string s = stl_args.front(); stl_args.pop_front(); 133 135 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); 136 if (v == -1) { 137 return NSCAPI::returnOK; 138 } 139 if (!msg.empty()) 140 msg += "&"; 141 msg += strEx::itos(v); 139 142 } 140 return ret;143 return NSCAPI::returnOK; 141 144 } 145 /* 142 146 case REQ_SERVICESTATE: 143 147 return NSCommands::serviceState(NSCHelper::arrayBuffer2list(argLen, args)); … … 152 156 case REQ_USEDDISKSPACE: 153 157 return NSCommands::usedDiskSpace(NSCHelper::arrayBuffer2list(argLen, args)); 158 */ 154 159 } 155 return "";160 return NSCAPI::returnIgnored; 156 161 } 157 162 -
modules/NSClientCompat/NSClientCompat.h
ra0528c4 r1eef1ee 18 18 bool hasCommandHandler(); 19 19 bool hasMessageHandler(); 20 std::string handleCommand(const std::string command, const unsigned int argLen, char **args);20 NSCAPI::nagiosReturn handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 21 21 }; -
modules/NSClientListener/NSClientSocket.cpp
r2a94f3f r1eef1ee 83 83 charEx::token cmd = charEx::getToken(pwd.second, '&'); 84 84 NSC_DEBUG_MSG("Command: " + cmd.first); 85 return NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '&'); 85 std::string message, perf; 86 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '&', message, perf); 87 // @todo fix some way to interpret return code 88 return message; 86 89 } 87 90
Note: See TracChangeset
for help on using the changeset viewer.








