]> granicus.if.org Git - icinga2/blob - lib/compat/compatlogger.hpp
Merge pull request #5995 from Icinga/fix/influxdb-requests
[icinga2] / lib / compat / compatlogger.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef COMPATLOGGER_H
21 #define COMPATLOGGER_H
22
23 #include "compat/compatlogger.thpp"
24 #include "icinga/service.hpp"
25 #include "base/timer.hpp"
26 #include <fstream>
27
28 namespace icinga
29 {
30
31 /**
32  * An Icinga compat log writer.
33  *
34  * @ingroup compat
35  */
36 class CompatLogger final : public ObjectImpl<CompatLogger>
37 {
38 public:
39         DECLARE_OBJECT(CompatLogger);
40         DECLARE_OBJECTNAME(CompatLogger);
41
42         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
43
44         void ValidateRotationMethod(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
45
46 protected:
47         void Start(bool runtimeCreated) override;
48         void Stop(bool runtimeRemoved) override;
49
50 private:
51         void WriteLine(const String& line);
52         void Flush();
53
54         void CheckResultHandler(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
55         void NotificationSentHandler(const Notification::Ptr& notification, const Checkable::Ptr& service,
56                 const User::Ptr& user, NotificationType notification_type, CheckResult::Ptr const& cr,
57                 const String& author, const String& comment_text, const String& command_name);
58         void FlappingChangedHandler(const Checkable::Ptr& checkable);
59         void EnableFlappingChangedHandler(const Checkable::Ptr& checkable);
60         void TriggerDowntimeHandler(const Downtime::Ptr& downtime);
61         void RemoveDowntimeHandler(const Downtime::Ptr& downtime);
62         void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
63         void EventCommandHandler(const Checkable::Ptr& service);
64
65         static String GetHostStateString(const Host::Ptr& host);
66
67         Timer::Ptr m_RotationTimer;
68         void RotationTimerHandler();
69         void ScheduleNextRotation();
70
71         std::ofstream m_OutputFile;
72         void ReopenFile(bool rotate);
73 };
74
75 }
76
77 #endif /* COMPATLOGGER_H */