source: nscp/modules/NRPEClient/NRPEClient.h @ 3bdaf18

0.4.00.4.10.4.2
Last change on this file since 3bdaf18 was 3bdaf18, checked in by Michael Medin <michael@…>, 2 years ago

Tweaks to building on linux, stil need to fix the utf8 issue and some modules...

  • Property mode set to 100644
File size: 4.9 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 <nrpe/packet.hpp>
25
26
27class NRPEClient : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin {
28private:
29        typedef enum {
30                inject, script, script_dir,
31        } command_type;
32        struct nrpe_connection_data {
33                std::wstring host;
34                std::wstring command;
35                std::wstring arguments;
36                std::wstring command_line;
37                std::vector<std::wstring> argument_vector;
38                int port;
39                int timeout;
40                unsigned int buffer_length;
41                bool no_ssl;
42                nrpe_connection_data(unsigned int buffer_length_ = 1024)
43                        : host(_T("127.0.0.1")),
44                        port(5666),
45                        timeout(10),
46                        no_ssl(false),
47                        buffer_length(buffer_length_)
48                {}
49                void parse_arguments() {
50                        for (std::vector<std::wstring>::const_iterator cit = argument_vector.begin(); cit != argument_vector.end(); ++cit) {
51                                if (!arguments.empty())
52                                        arguments += _T("!");
53                                arguments += *cit;
54                        }
55                }
56                std::wstring get_cli(std::wstring arguments_) {
57                        if (command_line.empty()) {
58                                command_line = command;
59                                if (command_line.empty())
60                                        command_line = _T("_NRPE_CHECK");
61                                if (!arguments_.empty())
62                                        command_line += _T("!") + arguments_;
63                                else if (!arguments.empty())
64                                        command_line += _T("!") + arguments;
65                        }
66                        return command_line;
67                }
68                std::wstring toString() {
69                        std::wstringstream ss;
70                        ss << _T("host: ") << host;
71                        ss << _T(", port: ") << port;
72                        ss << _T(", timeout: ") << timeout;
73                        ss << _T(", no_ssl: ") << no_ssl;
74                        ss << _T(", buffer_length: ") << buffer_length;
75                        ss << _T(", command: ") << command;
76                        ss << _T(", argument: ") << arguments;
77                        return ss.str();
78                }
79        };
80        struct nrpe_result_data {
81                nrpe_result_data() {}
82                nrpe_result_data(int result_, std::wstring text_) : result(result_), text(text_) {}
83                std::wstring text;
84                int result;
85        };
86        typedef std::map<strEx::blindstr, nrpe_connection_data> command_list;
87        command_list commands;
88        unsigned int buffer_length_;
89        std::wstring cert_;
90
91public:
92        NRPEClient();
93        virtual ~NRPEClient();
94        // Module calls
95        bool loadModule();
96        bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode);
97        bool unloadModule();
98
99
100        std::wstring getModuleName() {
101#ifdef USE_SSL
102                return _T("NRPE client (w/ SSL)");
103#else
104                return _T("NRPE client");
105#endif
106        }
107        nscapi::plugin_wrapper::module_version getModuleVersion() {
108                nscapi::plugin_wrapper::module_version version = {0, 0, 1 };
109                return version;
110        }
111        std::wstring getModuleDescription() {
112                return _T("A simple client for checking remote NRPE servers (think proxy).\n")
113#ifndef USE_BOOST
114                _T("BOOST support is missing (this is probably very bad)!\n")
115#endif
116#ifndef USE_SSL
117                _T("SSL support is missing (so you cant use encryption)!")
118#endif
119        ;
120        }
121
122        bool hasCommandHandler();
123        bool hasMessageHandler();
124        NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);
125        int commandLineExec(const unsigned int argLen,wchar_t** args);
126        std::wstring getConfigurationMeta();
127
128private:
129        nrpe_result_data  execute_nrpe_command(nrpe_connection_data con, std::wstring arguments);
130        nrpe::packet send_nossl(std::wstring host, int port, int timeout, nrpe::packet packet);
131        nrpe::packet send_ssl(std::wstring host, int port, int timeout, nrpe::packet packet);
132        void add_options(po::options_description &desc, nrpe_connection_data &command_data);
133
134private:
135        void addCommand(std::wstring key, std::wstring args);
136
137};
138
Note: See TracBrowser for help on using the repository browser.