1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef ELASTICSEARCHWRITER_H
4 #define ELASTICSEARCHWRITER_H
6 #include "perfdata/elasticsearchwriter-ti.hpp"
7 #include "icinga/service.hpp"
8 #include "base/configobject.hpp"
9 #include "base/workqueue.hpp"
10 #include "base/timer.hpp"
11 #include "base/tlsstream.hpp"
16 class ElasticsearchWriter final : public ObjectImpl<ElasticsearchWriter>
19 DECLARE_OBJECT(ElasticsearchWriter);
20 DECLARE_OBJECTNAME(ElasticsearchWriter);
22 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
24 static String FormatTimestamp(double ts);
27 void OnConfigLoaded() override;
28 void Resume() override;
29 void Pause() override;
33 WorkQueue m_WorkQueue{10000000, 1};
34 Timer::Ptr m_FlushTimer;
35 std::vector<String> m_DataBuffer;
36 boost::mutex m_DataBufferMutex;
38 void AddCheckResult(const Dictionary::Ptr& fields, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
40 void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
41 void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
42 void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
43 void InternalCheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
44 void NotificationSentToAllUsersHandler(const Notification::Ptr& notification,
45 const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
46 const CheckResult::Ptr& cr, const String& author, const String& text);
47 void NotificationSentToAllUsersHandlerInternal(const Notification::Ptr& notification,
48 const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
49 const CheckResult::Ptr& cr, const String& author, const String& text);
51 void Enqueue(const Checkable::Ptr& checkable, const String& type,
52 const Dictionary::Ptr& fields, double ts);
54 OptionalTlsStream Connect();
55 void AssertOnWorkQueue();
56 void ExceptionHandler(boost::exception_ptr exp);
59 void SendRequest(const String& body);
64 #endif /* ELASTICSEARCHWRITER_H */