| 1 | /************************************************************************** |
|---|
| 2 | * Copyright (C) 2004-2007 by Michael Medin <michael@medin.name> * |
|---|
| 3 | * * |
|---|
| 4 | * This code is part of NSClient++ - http://trac.nakednuns.org/nscp * |
|---|
| 5 | * * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify * |
|---|
| 7 | * it under the terms of the GNU General Public License as published by * |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
|---|
| 9 | * (at your option) any later version. * |
|---|
| 10 | * * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, * |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 14 | * GNU General Public License for more details. * |
|---|
| 15 | * * |
|---|
| 16 | * You should have received a copy of the GNU General Public License * |
|---|
| 17 | * along with this program; if not, write to the * |
|---|
| 18 | * Free Software Foundation, Inc., * |
|---|
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #include <socket_helpers.hpp> |
|---|
| 23 | #include "nrpe_server.hpp" |
|---|
| 24 | |
|---|
| 25 | NSC_WRAPPERS_MAIN(); |
|---|
| 26 | |
|---|
| 27 | class NRPEListener { |
|---|
| 28 | private: |
|---|
| 29 | typedef enum { |
|---|
| 30 | inject, script, script_dir, |
|---|
| 31 | } command_type; |
|---|
| 32 | struct command_data { |
|---|
| 33 | command_data() : type(inject) {} |
|---|
| 34 | command_data(command_type type_, std::wstring arguments_) : type(type_), arguments(arguments_) {} |
|---|
| 35 | command_type type; |
|---|
| 36 | std::wstring arguments; |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | unsigned int timeout; |
|---|
| 40 | socketHelpers::allowedHosts allowedHosts; |
|---|
| 41 | bool noPerfData_; |
|---|
| 42 | unsigned int buffer_length_; |
|---|
| 43 | std::wstring root_; |
|---|
| 44 | bool bUseSSL_; |
|---|
| 45 | |
|---|
| 46 | public: |
|---|
| 47 | NRPEListener(); |
|---|
| 48 | virtual ~NRPEListener(); |
|---|
| 49 | // Module calls |
|---|
| 50 | bool loadModule(NSCAPI::moduleLoadMode mode); |
|---|
| 51 | bool unloadModule(); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | std::wstring getModuleName() { |
|---|
| 55 | #ifdef USE_SSL |
|---|
| 56 | return _T("NRPE server (w/ SSL)"); |
|---|
| 57 | #else |
|---|
| 58 | return _T("NRPE server"); |
|---|
| 59 | #endif |
|---|
| 60 | } |
|---|
| 61 | nscapi::plugin_wrapper::module_version getModuleVersion() { |
|---|
| 62 | nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; |
|---|
| 63 | return version; |
|---|
| 64 | } |
|---|
| 65 | std::wstring getModuleDescription() { |
|---|
| 66 | 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."); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | bool hasCommandHandler(); |
|---|
| 70 | bool hasMessageHandler(); |
|---|
| 71 | NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); |
|---|
| 72 | std::wstring getConfigurationMeta(); |
|---|
| 73 | boost::shared_ptr<nrpe::server::server> server_; |
|---|
| 74 | |
|---|
| 75 | private: |
|---|
| 76 | class NRPEException { |
|---|
| 77 | std::wstring error_; |
|---|
| 78 | public: |
|---|
| 79 | NRPEException(std::wstring s) { |
|---|
| 80 | error_ = s; |
|---|
| 81 | } |
|---|
| 82 | std::wstring getMessage() { |
|---|
| 83 | return error_; |
|---|
| 84 | } |
|---|
| 85 | }; |
|---|
| 86 | }; |
|---|
| 87 | |
|---|