source: nscp/trunk/modules/CheckExternalScripts/CheckExternalScripts.h @ 9741fa5

Last change on this file since 9741fa5 was 9741fa5, checked in by Michael Medin <michael@…>, 5 years ago

2008-02-09 MickeM

+ New module CheckExternalScripts to handle 1, external script (similar to the old NRPE but in its own module)

  • Can Check batch/vbs/programs/*
  • Works with NSCA module (if you don't want to have NRPE at the same time)
  • Simpler syntax (discarded old and added new section for alias)
  • Started to add "sample alias" to ease initial setup and give some nice ideas (please provide me with feedback on them)
  • Property mode set to 100644
File size: 3.3 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
26class CheckExternalScripts {
27private:
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
40public:
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
64private:
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
77private:
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
Note: See TracBrowser for help on using the repository browser.