| 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 | NSC_WRAPPERS_MAIN();
|
|---|
| 23 | #include <map>
|
|---|
| 24 | #include <error.hpp>
|
|---|
| 25 |
|
|---|
| 26 | class CheckExternalScripts {
|
|---|
| 27 | private:
|
|---|
| 28 | struct command_data {
|
|---|
| 29 | command_data() {}
|
|---|
| 30 | command_data(std::wstring command_, std::wstring arguments_) : command(command_), arguments(arguments_) {}
|
|---|
| 31 | std::wstring command;
|
|---|
| 32 | std::wstring arguments;
|
|---|
| 33 | };
|
|---|
| 34 | typedef std::map<strEx::blindstr, command_data> command_list;
|
|---|
| 35 | command_list commands;
|
|---|
| 36 | command_list alias;
|
|---|
| 37 | unsigned int timeout;
|
|---|
| 38 | std::wstring scriptDirectory_;
|
|---|
| 39 |
|
|---|
| 40 | public:
|
|---|
| 41 | CheckExternalScripts();
|
|---|
| 42 | virtual ~CheckExternalScripts();
|
|---|
| 43 | // Module calls
|
|---|
| 44 | bool loadModule();
|
|---|
| 45 | bool unloadModule();
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | std::wstring getModuleName() {
|
|---|
| 49 | return _T("Check External Scripts");
|
|---|
| 50 | }
|
|---|
| 51 | NSCModuleWrapper::module_version getModuleVersion() {
|
|---|
| 52 | NSCModuleWrapper::module_version version = {0, 0, 1 };
|
|---|
| 53 | return version;
|
|---|
| 54 | }
|
|---|
| 55 | std::wstring getModuleDescription() {
|
|---|
| 56 | return _T("A simple wrapper to run external scripts and batch files.");
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | bool hasCommandHandler();
|
|---|
| 60 | bool hasMessageHandler();
|
|---|
| 61 | NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf);
|
|---|
| 62 | std::wstring getConfigurationMeta();
|
|---|
| 63 |
|
|---|
| 64 | private:
|
|---|
| 65 | class NRPEException {
|
|---|
| 66 | std::wstring error_;
|
|---|
| 67 | public:
|
|---|
| 68 | NRPEException(std::wstring s) {
|
|---|
| 69 | error_ = s;
|
|---|
| 70 | }
|
|---|
| 71 | std::wstring getMessage() {
|
|---|
| 72 | return error_;
|
|---|
| 73 | }
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | private:
|
|---|
| 78 | int executeNRPECommand(std::wstring command, std::wstring &msg, std::wstring &perf);
|
|---|
| 79 | void addAllScriptsFrom(std::wstring path);
|
|---|
| 80 | void addCommand(strEx::blindstr key, std::wstring cmd = _T(""), std::wstring args = _T("")) {
|
|---|
| 81 | commands[key] = command_data(cmd, args);
|
|---|
| 82 | }
|
|---|
| 83 | void addAlias(strEx::blindstr key, std::wstring cmd = _T(""), std::wstring args = _T("")) {
|
|---|
| 84 | alias[key] = command_data(cmd, args);
|
|---|
| 85 | }
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|