source: nscp/modules/NSCAClient/NSCAClient.h @ 98113da

0.4.00.4.10.4.2
Last change on this file since 98113da was 98113da, checked in by Michael Medin <michael@…>, 21 months ago
  • Real-time CheckEventLog working (still only for one, and I think application log)
  • Added python tests to validfate that Real-time eventlog is working.
  • Fixed som defects here and there (now builds on Linux again)
  • Fixed so it builds in "debug mode"
  • Fixed issue in grammar which caused infiniate loop in som cases
  • Fixed so error rendering in eventlog works with "infininate number of argumnets"
  • Added support for targeting execs (in API)
  • Fixed some invalid return messages
  • Streamlined submissions wrappers to be more inline with "other wrappers"
  • Fixed a myrriad of minor python script bugs
  • Added sleep command (which sometimes causes issues so use with care)
  • Property mode set to 100644
File size: 5.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#pragma once
22
23
24#include <client/command_line_parser.hpp>
25#include <boost/program_options.hpp>
26
27#include <nsca/nsca_packet.hpp>
28
29NSC_WRAPPERS_MAIN();
30NSC_WRAPPERS_CHANNELS();
31
32class NSCAAgent : public nscapi::impl::simple_plugin {
33private:
34
35        std::string hostname_;
36        std::wstring nscahost_;
37        unsigned int nscaport_;
38        unsigned int payload_length_;
39        bool cacheNscaHost_;
40        std::string password_;
41        int encryption_method_;
42        unsigned int timeout_;
43        std::wstring channel_;
44        int time_delta_;
45
46
47        struct sender_information {
48                sender_information(nscapi::functions::destination_container &src) {
49                        net::url u = src.get_url(5667);
50                        host = u.host;
51                        port = u.port;
52                        password = src.data["password"];
53                        encryption = src.data["encryption"];
54                }
55                std::string password;
56                std::string encryption;
57                std::string host;
58                unsigned int timeout;
59                int port;
60                unsigned int get_encryption() {
61                        return nsca::nsca_encrypt::helpers::encryption_to_int(encryption);
62                }
63        };
64
65        struct nscp_connection_data : public client::nscp_cli_data {
66                unsigned int payload_length;
67                int time_delta;
68                std::string encryption;
69                std::wstring cert;
70                nscp_connection_data(unsigned int payload_length, int time_delta) : payload_length(payload_length), time_delta(time_delta) {}
71
72                std::string parse_encryption() {
73
74                }
75                std::string get_encryption_string() {
76
77                        if (encryption.size() > 1 && std::isalnum(encryption[0]))
78                                encryption = parse_encryption();
79                        return encryption;
80                }
81
82                std::wstring to_wstring() {
83                        std::wstringstream ss;
84                        ss << _T(", cert: ") << cert;
85                        ss << _T(", no_ssl: ") << utf8::cvt<std::wstring>(get_encryption_string());
86                        return ss.str();
87                }
88        };
89
90        struct clp_handler_impl : public client::clp_handler {
91
92                NSCAAgent *instance;
93                clp_handler_impl(NSCAAgent *instance, unsigned int payload_length, int time_delta) : instance(instance), local_data(payload_length, time_delta) {}
94                nscp_connection_data local_data;
95
96                int query(client::configuration::data_type data, std::string request, std::string &reply);
97                int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &response);
98                int exec(client::configuration::data_type data, std::string request, std::string &reply);
99        };
100
101public:
102        NSCAAgent();
103        virtual ~NSCAAgent();
104        // Module calls
105        bool loadModule();
106        bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode);
107        bool unloadModule();
108
109        /**
110        * Return the module name.
111        * @return The module name
112        */
113        static std::wstring getModuleName() {
114#ifdef HAVE_LIBCRYPTOPP
115                return _T("NSCAAgent (w/ encryption)");
116#else
117                return _T("NSCAAgent");
118#endif
119        }
120        /**
121        * Module version
122        * @return module version
123        */
124        static nscapi::plugin_wrapper::module_version getModuleVersion() {
125                nscapi::plugin_wrapper::module_version version = {0, 3, 0 };
126                return version;
127        }
128        static std::wstring getModuleDescription() {
129                return std::wstring(_T("Passive check support (needs NSCA on nagios server).\nAvalible crypto are: ")) + getCryptos();
130        }
131        bool hasNotificationHandler() { return true; }
132
133        static std::wstring getCryptos();
134
135        NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
136        //NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf);
137        NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
138        int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
139
140        NSCAPI::nagiosReturn send(sender_information &data, const std::list<nsca::packet> packets);
141
142
143        std::wstring setup(client::configuration &config, const std::wstring &command);
144        void add_local_options(boost::program_options::options_description &desc, nscp_connection_data &command_data);
145
146        void set_delay(std::wstring key) {
147                time_delta_ = strEx::stol_as_time_sec(key, 1);
148        }
149
150};
Note: See TracBrowser for help on using the repository browser.