source: nscp/modules/CheckExternalScripts/CheckExternalScripts.h @ c0d7e82

0.4.00.4.10.4.2
Last change on this file since c0d7e82 was c0d7e82, checked in by Michael Medin <michael@…>, 3 years ago
  • Property mode set to 100644
File size: 3.6 KB
Line 
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
22NSC_WRAPPERS_MAIN();
23#include <map>
24#include <error.hpp>
25#include <execute_process.hpp>
26
27class CheckExternalScripts : public NSCModuleHelper::SimpleCommand {
28private:
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                std::wstring to_string() {
35                        return command + _T("(") + arguments + _T(")");
36                }
37        };
38        typedef std::map<std::wstring, command_data> command_list;
39        command_list commands;
40        command_list alias;
41        unsigned int timeout;
42        std::wstring scriptDirectory_;
43        std::wstring root_;
44        bool allowArgs_;
45        bool allowNasty_;
46
47public:
48        CheckExternalScripts();
49        virtual ~CheckExternalScripts();
50        // Module calls
51        bool loadModule(NSCAPI::moduleLoadMode mode);
52        bool unloadModule();
53
54
55        std::wstring getModuleName() {
56                return _T("Check External Scripts");
57        }
58        NSCModuleWrapper::module_version getModuleVersion() {
59                NSCModuleWrapper::module_version version = {0, 0, 1 };
60                return version;
61        }
62        std::wstring getModuleDescription() {
63                return _T("A simple wrapper to run external scripts and batch files.");
64        }
65
66        bool hasCommandHandler();
67        bool hasMessageHandler();
68        NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);
69        std::wstring getConfigurationMeta();
70
71private:
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
84private:
85        void addAllScriptsFrom(std::wstring path);
86        void addCommand(std::wstring key, std::wstring cmd, std::wstring args) {
87                boost::to_lower(key);
88                command_data cd = command_data(cmd, args);
89                commands[key] = cd;
90                NSCModuleHelper::registerCommand(key, _T("Script: ") + cd.to_string());
91        }
92        void addAlias(std::wstring key, std::wstring cmd, std::wstring args) {
93                boost::to_lower(key);
94                command_data cd = command_data(cmd, args);
95                alias[key] = cd;
96                NSCModuleHelper::registerCommand(key, _T("Alias for: ") + cd.to_string());
97        }
98};
99
Note: See TracBrowser for help on using the repository browser.