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