| 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/server.hpp>
|
|---|
| 24 |
|
|---|
| 25 | NSC_WRAPPERS_MAIN();
|
|---|
| 26 |
|
|---|
| 27 | class NRPEListener : public nscapi::impl::simple_plugin {
|
|---|
| 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 | nrpe::server::server::connection_info info_;
|
|---|
| 40 |
|
|---|
| 41 | public:
|
|---|
| 42 | NRPEListener();
|
|---|
| 43 | virtual ~NRPEListener();
|
|---|
| 44 | // Module calls
|
|---|
| 45 | bool loadModule();
|
|---|
| 46 | bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode);
|
|---|
| 47 | bool unloadModule();
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | std::wstring getModuleName() {
|
|---|
| 51 | #ifdef USE_SSL
|
|---|
| 52 | return _T("NRPE server");
|
|---|
| 53 | #else
|
|---|
| 54 | return _T("NRPE server (no SSL)");
|
|---|
| 55 | #endif
|
|---|
| 56 | }
|
|---|
| 57 | nscapi::plugin_wrapper::module_version getModuleVersion() {
|
|---|
| 58 | nscapi::plugin_wrapper::module_version version = {0, 0, 1 };
|
|---|
| 59 | return version;
|
|---|
| 60 | }
|
|---|
| 61 | std::wstring getModuleDescription() {
|
|---|
| 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 | }
|
|---|
| 64 |
|
|---|
| 65 | bool hasCommandHandler();
|
|---|
| 66 | bool hasMessageHandler();
|
|---|
| 67 | NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf);
|
|---|
| 68 | std::wstring getConfigurationMeta();
|
|---|
| 69 | boost::shared_ptr<nrpe::server::server> server_;
|
|---|
| 70 |
|
|---|
| 71 | private:
|
|---|
| 72 | class NRPEException {
|
|---|
| 73 | std::wstring error_;
|
|---|
| 74 | public:
|
|---|
| 75 | NRPEException(std::wstring s) {
|
|---|
| 76 | error_ = s;
|
|---|
| 77 | }
|
|---|
| 78 | std::wstring getMessage() {
|
|---|
| 79 | return error_;
|
|---|
| 80 | }
|
|---|
| 81 | };
|
|---|
| 82 | };
|
|---|
| 83 |
|
|---|