source: nscp/modules/CheckEventLog/CheckEventLog.h @ 465866c

0.4.10.4.2
Last change on this file since 465866c was 465866c, checked in by Michael Medin <michael@…>, 12 months ago

2012-06-05 MickeM

  • Tweaked all servers to use the new internals and added first testcase for NSCP socket

2012-05-24 MickeM

  • Reworked real time event log support to be a lot more flexible You can now specify all options on a "filter" level.
  • WARNING* Old syntax NOT supported (and will not upgrade) but hopefully not to many will be affected.
  • Added support for ipv6 allowed hosts validation

2012-05-21 MickeM

  • Sofia Born (My second daughter)
  • Property mode set to 100644
File size: 5.0 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***************************************************************************/
21NSC_WRAPPERS_MAIN();
22NSC_WRAPPERS_CLI();
23
24#include <settings/macros.h>
25#include <strEx.h>
26#include <utils.h>
27#include <checkHelpers.hpp>
28
29#include "eventlog_wrapper.hpp"
30#include "eventlog_record.hpp"
31
32#include "filters.hpp"
33
34struct real_time_thread {
35        bool enabled_;
36        //std::wstring destination_;
37        unsigned long long start_age_;
38        unsigned long long max_age_;
39        //std::wstring syntax_;
40        //std::list<filter_container> filters_;
41        boost::shared_ptr<boost::thread> thread_;
42        HANDLE stop_event_;
43        std::list<std::wstring> lists_;
44        std::list<std::wstring> hit_cache_;
45        boost::timed_mutex cache_mutex_;
46        filters::filter_config_handler filters_;
47
48        bool cache_;
49        bool debug_;
50        std::wstring filters_path_;
51
52        real_time_thread() : enabled_(false), start_age_(0), max_age_(0), debug_(false), cache_(false) {
53                set_start_age(_T("30m"));
54                set_max_age(_T("5m"));
55        }
56
57        void add_realtime_filter(boost::shared_ptr<nscapi::settings_proxy> proxy, std::wstring key, std::wstring query);
58        void set_enabled(bool flag) { enabled_ = flag; }
59        void set_start_age(std::wstring age) {
60                start_age_ = strEx::stoi64_as_time(age);
61        }
62        void set_max_age(std::wstring age) {
63                if (age == _T("none") || age == _T("infinite") || age == _T("false"))
64                        max_age_ = 0;
65                else
66                        max_age_ = strEx::stoi64_as_time(age);
67        }
68        void set_eventlog(std::wstring log) {
69                lists_ = strEx::splitEx(log, _T(","));
70        }
71
72        void set_language(std::string lang);
73        void set_filter(boost::shared_ptr<nscapi::settings_proxy> proxy, std::wstring flt) {
74                if (!flt.empty())
75                        add_realtime_filter(proxy, _T("default"), flt);
76        }
77        bool has_filters() {
78                return !filters_.has_objects();
79        }
80        bool start();
81        bool stop();
82
83        bool check_cache(unsigned long &count, std::wstring &messages);
84
85        void thread_proc();
86//      void process_events(eventlog_filter::filter_engine engine, eventlog_wrapper &eventlog);
87        void process_no_events(const filters::filter_config_object &object);
88        void process_record(const filters::filter_config_object &object, const EventLogRecord &record);
89        void debug_miss(const EventLogRecord &record);
90//      void process_event(eventlog_filter::filter_engine engine, const EVENTLOGRECORD* record);
91};
92
93class CheckEventLog : public nscapi::impl::simple_command_handler, public nscapi::impl::simple_plugin {
94private:
95        bool debug_;
96        std::wstring syntax_;
97        int buffer_length_;
98        bool lookup_names_;
99        real_time_thread thread_;
100
101public:
102        CheckEventLog();
103        virtual ~CheckEventLog();
104        // Module calls
105        bool loadModule();
106        bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode);
107        bool unloadModule();
108
109        static std::wstring getModuleName() {
110                return _T("Event log Checker.");
111        }
112        static nscapi::plugin_wrapper::module_version getModuleVersion() {
113                nscapi::plugin_wrapper::module_version version = {0, 0, 1 };
114                return version;
115        }
116        static std::wstring getModuleDescription() {
117                return _T("Check for errors and warnings in the event log.\nThis is only supported through NRPE so if you plan to use only NSClient this wont help you at all.");
118        }
119
120        void parse(std::wstring expr);
121
122        bool hasCommandHandler();
123        bool hasMessageHandler();
124        NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
125        NSCAPI::nagiosReturn checkCache(std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
126        NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
127        NSCAPI::nagiosReturn insert_eventlog(std::vector<std::wstring> arguments, std::wstring &message);
128
129};
Note: See TracBrowser for help on using the repository browser.