]> granicus.if.org Git - icinga2/blob - lib/perfdata/gelfwriter.hpp
Merge pull request #7527 from Icinga/bugfix/checkable-command-endpoint-zone
[icinga2] / lib / perfdata / gelfwriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef GELFWRITER_H
4 #define GELFWRITER_H
5
6 #include "perfdata/gelfwriter-ti.hpp"
7 #include "icinga/service.hpp"
8 #include "base/configobject.hpp"
9 #include "base/tcpsocket.hpp"
10 #include "base/timer.hpp"
11 #include "base/workqueue.hpp"
12 #include <fstream>
13
14 namespace icinga
15 {
16
17 /**
18  * An Icinga Gelf writer for Graylog.
19  *
20  * @ingroup perfdata
21  */
22 class GelfWriter final : public ObjectImpl<GelfWriter>
23 {
24 public:
25         DECLARE_OBJECT(GelfWriter);
26         DECLARE_OBJECTNAME(GelfWriter);
27
28         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
29
30 protected:
31         void OnConfigLoaded() override;
32         void Resume() override;
33         void Pause() override;
34
35 private:
36         OptionalTlsStream m_Stream;
37         WorkQueue m_WorkQueue{10000000, 1};
38
39         Timer::Ptr m_ReconnectTimer;
40
41         void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
42         void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
43         void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
44                 const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
45                 const String& author, const String& commentText, const String& commandName);
46         void NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
47                 const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
48                 const String& author, const String& comment_text, const String& command_name);
49         void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
50         void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
51
52         String ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts);
53         void SendLogMessage(const Checkable::Ptr& checkable, const String& gelfMessage);
54
55         void ReconnectTimerHandler();
56
57         void Disconnect();
58         void DisconnectInternal();
59         void Reconnect();
60         void ReconnectInternal();
61
62         void AssertOnWorkQueue();
63
64         void ExceptionHandler(boost::exception_ptr exp);
65 };
66
67 }
68
69 #endif /* GELFWRITER_H */