source: nscp/modules/NRPEClient/NRPEClient.h @ a44cb15

0.4.00.4.10.4.2
Last change on this file since a44cb15 was a44cb15, checked in by Michael Medin <michael@…>, 22 months ago
  • Implemented registration of channels (so no longer faked)
  • Added settings key to change the NSCAAgent channel name
  • Addded proper channel handling to PythonScript module
  • Improved error handling in channels API
  • Rewrote wrapper API to use templates and classes instead of macros (ish)
  • Improved the internal plugin wrapping API to support multiple plugin load
  • Fixed so PythonScript module supports multiple plugin load (with new argument for plugin_id)
  • Added API for registrying routers and handling routing (almost there now)
  • Fixed issue with messages due to new API
  • Property mode set to 100644
File size: 5.2 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();
23NSC_WRAPPERS_CLI();
24
25
26#include <map>
27#include <nrpe/packet.hpp>
28
29
30class NRPEClient : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {
31private:
32        typedef enum {
33                inject, script, script_dir,
34        } command_type;
35        struct nrpe_connection_data {
36                std::wstring host;
37                std::wstring command;
38                std::wstring arguments;
39                std::wstring command_line;
40                std::vector<std::wstring> argument_vector;
41                int port;
42                int timeout;
43                unsigned int buffer_length;
44                bool no_ssl;
45                nrpe_connection_data(unsigned int buffer_length_ = 1024)
46                        : host(_T("127.0.0.1")),
47                        port(5666),
48                        timeout(10),
49                        no_ssl(false),
50                        buffer_length(buffer_length_)
51                {}
52                void parse_arguments() {
53                        for (std::vector<std::wstring>::const_iterator cit = argument_vector.begin(); cit != argument_vector.end(); ++cit) {
54                                if (!arguments.empty())
55                                        arguments += _T("!");
56                                arguments += *cit;
57                        }
58                }
59                std::wstring get_cli(std::wstring arguments_) {
60                        if (command_line.empty()) {
61                                command_line = command;
62                                if (command_line.empty())
63                                        command_line = _T("_NRPE_CHECK");
64                                if (!arguments_.empty())
65                                        command_line += _T("!") + arguments_;
66                                else if (!arguments.empty())
67                                        command_line += _T("!") + arguments;
68                        }
69                        return command_line;
70                }
71                std::wstring toString() {
72                        std::wstringstream ss;
73                        ss << _T("host: ") << host;
74                        ss << _T(", port: ") << port;
75                        ss << _T(", timeout: ") << timeout;
76                        ss << _T(", no_ssl: ") << no_ssl;
77                        ss << _T(", buffer_length: ") << buffer_length;
78                        ss << _T(", command: ") << command;
79                        ss << _T(", argument: ") << arguments;
80                        return ss.str();
81                }
82        };
83        struct nrpe_result_data {
84                nrpe_result_data() {}
85                nrpe_result_data(int result_, std::wstring text_) : result(result_), text(text_) {}
86                std::wstring text;
87                int result;
88        };
89        typedef std::map<strEx::blindstr, nrpe_connection_data> command_list;
90        command_list commands;
91        unsigned int buffer_length_;
92        std::wstring cert_;
93
94public:
95        NRPEClient();
96        virtual ~NRPEClient();
97        // Module calls
98        bool loadModule();
99        bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode);
100        bool unloadModule();
101
102
103        static std::wstring getModuleName() {
104#ifdef USE_SSL
105                return _T("NRPE client (w/ SSL)");
106#else
107                return _T("NRPE client");
108#endif
109        }
110        static nscapi::plugin_wrapper::module_version getModuleVersion() {
111                nscapi::plugin_wrapper::module_version version = {0, 0, 1 };
112                return version;
113        }
114        static std::wstring getModuleDescription() {
115                return _T("A simple client for checking remote NRPE servers (think proxy).\n")
116#ifndef USE_BOOST
117                _T("BOOST support is missing (this is probably very bad)!\n")
118#endif
119#ifndef USE_SSL
120                _T("SSL support is missing (so you cant use encryption)!")
121#endif
122        ;
123        }
124
125        bool hasCommandHandler();
126        bool hasMessageHandler();
127        NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
128        int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
129        std::wstring getConfigurationMeta();
130
131private:
132        nrpe_result_data  execute_nrpe_command(nrpe_connection_data con, std::wstring arguments);
133        nrpe::packet send_nossl(std::wstring host, int port, int timeout, nrpe::packet packet);
134        nrpe::packet send_ssl(std::wstring host, int port, int timeout, nrpe::packet packet);
135        void add_options(po::options_description &desc, nrpe_connection_data &command_data);
136
137private:
138        void add_command(std::wstring key, std::wstring args);
139        void add_server(std::wstring key, std::wstring args);
140
141};
142
Note: See TracBrowser for help on using the repository browser.