]> granicus.if.org Git - icinga2/blob - lib/perfdata/elasticsearchwriter.hpp
Merge pull request #7527 from Icinga/bugfix/checkable-command-endpoint-zone
[icinga2] / lib / perfdata / elasticsearchwriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef ELASTICSEARCHWRITER_H
4 #define ELASTICSEARCHWRITER_H
5
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"
12
13 namespace icinga
14 {
15
16 class ElasticsearchWriter final : public ObjectImpl<ElasticsearchWriter>
17 {
18 public:
19         DECLARE_OBJECT(ElasticsearchWriter);
20         DECLARE_OBJECTNAME(ElasticsearchWriter);
21
22         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
23
24         static String FormatTimestamp(double ts);
25
26 protected:
27         void OnConfigLoaded() override;
28         void Resume() override;
29         void Pause() override;
30
31 private:
32         String m_EventPrefix;
33         WorkQueue m_WorkQueue{10000000, 1};
34         Timer::Ptr m_FlushTimer;
35         std::vector<String> m_DataBuffer;
36         boost::mutex m_DataBufferMutex;
37
38         void AddCheckResult(const Dictionary::Ptr& fields, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
39
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);
50
51         void Enqueue(const Checkable::Ptr& checkable, const String& type,
52                 const Dictionary::Ptr& fields, double ts);
53
54         OptionalTlsStream Connect();
55         void AssertOnWorkQueue();
56         void ExceptionHandler(boost::exception_ptr exp);
57         void FlushTimeout();
58         void Flush();
59         void SendRequest(const String& body);
60 };
61
62 }
63
64 #endif /* ELASTICSEARCHWRITER_H */