Changeset 81e420c in nscp for modules/NRPEServer
- Timestamp:
- 09/01/11 07:05:41 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 3b11e65
- Parents:
- 1307e3f5
- Location:
- modules/NRPEServer
- Files:
-
- 2 edited
-
NRPEServer.cpp (modified) (2 diffs)
-
NRPEServer.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
modules/NRPEServer/NRPEServer.cpp
rb9498ef r81e420c 32 32 namespace sh = nscapi::settings_helper; 33 33 34 NRPEListener gNRPEListener;35 34 36 35 NRPEListener::NRPEListener() : info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(1024))) { … … 183 182 } 184 183 185 186 187 188 // void NRPEListener::onAccept(simpleSocket::Socket *client)189 // {190 // if (!allowedHosts.inAllowedHosts(client->getAddr())) {191 // NSC_LOG_ERROR(_T("Unauthorize access from: ") + client->getAddrString());192 // client->close();193 // return;194 // }195 // try {196 // simpleSocket::DataBuffer block;197 // int i;198 // int maxWait = socketTimeout_*10;199 // for (i=0;i<maxWait;i++) {200 // bool lastReadHasMore = false;201 // try {202 // lastReadHasMore = client->readAll(block, 1048);203 // } catch (simpleSocket::SocketException e) {204 // NSC_LOG_MESSAGE(_T("Could not read NRPE packet from socket :") + e.getMessage());205 // client->close();206 // return;207 // }208 // if (block.getLength() >= NRPEPacket::getBufferLength(buffer_length_))209 // break;210 // if (!lastReadHasMore) {211 // NSC_LOG_MESSAGE(_T("Could not read a full NRPE packet from socket, only got: ") + strEx::itos(block.getLength()));212 // client->close();213 // return;214 // }215 // Sleep(100);216 // }217 // if (i >= maxWait) {218 // NSC_LOG_ERROR_STD(_T("Timeout reading NRPE-packet (increase socket_timeout), we only got: ") + strEx::itos(block.getLength()));219 // client->close();220 // return;221 // }222 // if (block.getLength() == NRPEPacket::getBufferLength(buffer_length_)) {223 // try {224 // NRPEPacket out = handlePacket(NRPEPacket(block.getBuffer(), block.getLength(), buffer_length_));225 // block.copyFrom(out.getBuffer(), out.getBufferLength());226 // } catch (NRPEPacket::NRPEPacketException e) {227 // NSC_LOG_ERROR_STD(_T("NRPESocketException: ") + e.getMessage());228 // try {229 // NRPEPacket err(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("Could not construct return paket in NRPE handler check clientside (nsclient.log) logs..."), buffer_length_);230 // block.copyFrom(err.getBuffer(), err.getBufferLength());231 // } catch (NRPEPacket::NRPEPacketException e) {232 // NSC_LOG_ERROR_STD(_T("NRPESocketException (again): ") + e.getMessage());233 // client->close();234 // return;235 // }236 // }237 // int maxWait = socketTimeout_*10;238 // for (i=0;i<maxWait;i++) {239 // bool lastReadHasMore = false;240 // try {241 // if (client->canWrite())242 // lastReadHasMore = client->sendAll(block);243 // } catch (simpleSocket::SocketException e) {244 // NSC_LOG_MESSAGE(_T("Could not send NRPE packet from socket :") + e.getMessage());245 // client->close();246 // return;247 // }248 // if (!lastReadHasMore) {249 // client->close();250 // return;251 // }252 // Sleep(100);253 // }254 // if (i >= maxWait) {255 // NSC_LOG_ERROR_STD(_T("Timeout reading NRPE-packet (increase socket_timeout)"));256 // client->close();257 // return;258 // }259 // } else {260 // NSC_LOG_ERROR_STD(_T("We got more then we wanted ") + strEx::itos(NRPEPacket::getBufferLength(buffer_length_)) + _T(", we only got: ") + strEx::itos(block.getLength()));261 // client->close();262 // return;263 // }264 // } catch (simpleSocket::SocketException e) {265 // NSC_LOG_ERROR_STD(_T("SocketException: ") + e.getMessage());266 // } catch (NRPEException e) {267 // NSC_LOG_ERROR_STD(_T("NRPEException: ") + e.getMessage());268 // } catch (...) {269 // NSC_LOG_ERROR_STD(_T("Unhandled Exception in NRPE listner..."));270 // }271 // client->close();272 // }273 //274 // NRPEPacket NRPEListener::handlePacket(NRPEPacket p) {275 // if (p.getType() != NRPEPacket::queryPacket) {276 // NSC_LOG_ERROR(_T("Request is not a query."));277 // throw NRPEException(_T("Invalid query type: ") + strEx::itos(p.getType()));278 // }279 // if (p.getVersion() != NRPEPacket::version2) {280 // NSC_LOG_ERROR(_T("Request had unsupported version."));281 // throw NRPEException(_T("Invalid version"));282 // }283 // if (!p.verifyCRC()) {284 // NSC_LOG_ERROR(_T("Request had invalid checksum."));285 // throw NRPEException(_T("Invalid checksum"));286 // }287 // strEx::token cmd = strEx::getToken(p.getPayload(), '!');288 // if (cmd.first == _T("_NRPE_CHECK")) {289 // return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnOK, _T("I (") + NSCModuleHelper::getApplicationVersionString() + _T(") seem to be doing fine..."), buffer_length_);290 // }291 // std::wstring msg, perf;292 //293 // if (allowArgs_) {294 // if (!cmd.second.empty()) {295 // NSC_LOG_ERROR(_T("Request contained arguments (not currently allowed, check the allow_arguments option)."));296 // throw NRPEException(_T("Request contained arguments (not currently allowed, check the allow_arguments option)."));297 // }298 // }299 // if (allowNasty_) {300 // if (cmd.first.find_first_of(NASTY_METACHARS) != std::wstring::npos) {301 // NSC_LOG_ERROR(_T("Request command contained illegal metachars!"));302 // throw NRPEException(_T("Request command contained illegal metachars!"));303 // }304 // if (cmd.second.find_first_of(NASTY_METACHARS) != std::wstring::npos) {305 // NSC_LOG_ERROR(_T("Request arguments contained illegal metachars!"));306 // throw NRPEException(_T("Request command contained illegal metachars!"));307 // }308 // }309 // //TODO REMOVE THIS310 // //return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("TEST TEST TEST"), buffer_length_);311 //312 // NSCAPI::nagiosReturn ret = -3;313 // try {314 // ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf);315 // } catch (...) {316 // return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal exception"), buffer_length_);317 // }318 // switch (ret) {319 // case NSCAPI::returnInvalidBufferLen:320 // msg = _T("UNKNOWN: Return buffer to small to handle this command.");321 // ret = NSCAPI::returnUNKNOWN;322 // break;323 // case NSCAPI::returnIgnored:324 // msg = _T("UNKNOWN: No handler for that command");325 // ret = NSCAPI::returnUNKNOWN;326 // break;327 // case NSCAPI::returnOK:328 // case NSCAPI::returnWARN:329 // case NSCAPI::returnCRIT:330 // case NSCAPI::returnUNKNOWN:331 // break;332 // default:333 // msg = _T("UNKNOWN: Internal error.");334 // ret = NSCAPI::returnUNKNOWN;335 // }336 // if (msg.length() >= buffer_length_-1) {337 // NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :("));338 // msg = msg.substr(0,buffer_length_-2);339 // }340 // if (perf.empty()||noPerfData_) {341 // return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg, buffer_length_);342 // } else {343 // return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg + _T("|") + perf, buffer_length_);344 // }345 // }346 347 184 NSC_WRAP_DLL(); 348 NSC_WRAPPERS_MAIN_DEF( gNRPEListener);185 NSC_WRAPPERS_MAIN_DEF(NRPEListener); 349 186 NSC_WRAPPERS_IGNORE_MSG_DEF(); 350 187 NSC_WRAPPERS_IGNORE_CMD_DEF(); -
modules/NRPEServer/NRPEServer.h
rb9498ef r81e420c 48 48 49 49 50 st d::wstring getModuleName() {50 static std::wstring getModuleName() { 51 51 #ifdef USE_SSL 52 52 return _T("NRPE server"); … … 55 55 #endif 56 56 } 57 nscapi::plugin_wrapper::module_version getModuleVersion() {57 static nscapi::plugin_wrapper::module_version getModuleVersion() { 58 58 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 59 59 return version; 60 60 } 61 st d::wstring getModuleDescription() {61 static std::wstring getModuleDescription() { 62 62 return _T("A simple server that listens for incoming NRPE connection and handles them.\nNRPE is preferred over NSClient as it is more flexible. You can of cource use both NSClient and NRPE."); 63 63 }
Note: See TracChangeset
for help on using the changeset viewer.








