]> granicus.if.org Git - icinga2/blob - lib/perfdata/gelfwriter.hpp
Implement ScheduledDowntime::AllConfigIsLoaded()
[icinga2] / lib / perfdata / gelfwriter.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://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 GELFWRITER_H
21 #define GELFWRITER_H
22
23 #include "perfdata/gelfwriter-ti.hpp"
24 #include "icinga/service.hpp"
25 #include "base/configobject.hpp"
26 #include "base/tcpsocket.hpp"
27 #include "base/timer.hpp"
28 #include "base/workqueue.hpp"
29 #include <fstream>
30
31 namespace icinga
32 {
33
34 /**
35  * An Icinga Gelf writer for Graylog.
36  *
37  * @ingroup perfdata
38  */
39 class GelfWriter final : public ObjectImpl<GelfWriter>
40 {
41 public:
42         DECLARE_OBJECT(GelfWriter);
43         DECLARE_OBJECTNAME(GelfWriter);
44
45         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
46
47 protected:
48         void OnConfigLoaded() override;
49         void Resume() override;
50         void Pause() override;
51
52 private:
53         Stream::Ptr m_Stream;
54         WorkQueue m_WorkQueue{10000000, 1};
55
56         Timer::Ptr m_ReconnectTimer;
57
58         void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
59         void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
60         void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
61                 const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr,
62                 const String& author, const String& commentText, const String& commandName);
63         void NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
64                 const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr,
65                 const String& author, const String& comment_text, const String& command_name);
66         void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
67         void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
68
69         String ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts);
70         void SendLogMessage(const String& gelfMessage);
71
72         void ReconnectTimerHandler();
73
74         void Disconnect();
75         void Reconnect();
76
77         void AssertOnWorkQueue();
78
79         void ExceptionHandler(boost::exception_ptr exp);
80 };
81
82 }
83
84 #endif /* GELFWRITER_H */