2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2017-09-07 15:11:57 +02:00
|
|
|
|
2017-11-09 14:05:10 +01:00
|
|
|
#ifndef ELASTICSEARCHWRITER_H
|
|
|
|
#define ELASTICSEARCHWRITER_H
|
2017-09-07 15:11:57 +02:00
|
|
|
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "perfdata/elasticsearchwriter-ti.hpp"
|
2017-09-07 15:11:57 +02:00
|
|
|
#include "icinga/service.hpp"
|
|
|
|
#include "base/configobject.hpp"
|
|
|
|
#include "base/workqueue.hpp"
|
|
|
|
#include "base/timer.hpp"
|
2019-04-23 13:15:38 +02:00
|
|
|
#include "base/tlsstream.hpp"
|
2017-09-07 15:11:57 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2018-01-04 06:11:04 +01:00
|
|
|
class ElasticsearchWriter final : public ObjectImpl<ElasticsearchWriter>
|
2017-09-07 15:11:57 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-11-09 14:05:10 +01:00
|
|
|
DECLARE_OBJECT(ElasticsearchWriter);
|
|
|
|
DECLARE_OBJECTNAME(ElasticsearchWriter);
|
2017-09-07 15:11:57 +02:00
|
|
|
|
|
|
|
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
|
|
|
|
|
|
|
|
static String FormatTimestamp(double ts);
|
|
|
|
|
|
|
|
protected:
|
2018-01-04 05:12:56 +01:00
|
|
|
void OnConfigLoaded() override;
|
2018-10-24 13:20:03 +02:00
|
|
|
void Resume() override;
|
|
|
|
void Pause() override;
|
2017-09-07 15:11:57 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
String m_EventPrefix;
|
2018-01-04 09:43:49 +01:00
|
|
|
WorkQueue m_WorkQueue{10000000, 1};
|
2022-04-06 13:01:18 +02:00
|
|
|
boost::signals2::connection m_HandleCheckResults, m_HandleStateChanges, m_HandleNotifications;
|
2017-09-07 15:11:57 +02:00
|
|
|
Timer::Ptr m_FlushTimer;
|
|
|
|
std::vector<String> m_DataBuffer;
|
2021-02-02 10:16:04 +01:00
|
|
|
std::mutex m_DataBufferMutex;
|
2017-09-07 15:11:57 +02:00
|
|
|
|
|
|
|
void AddCheckResult(const Dictionary::Ptr& fields, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
|
|
|
|
|
|
|
void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
|
|
|
|
void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
|
|
|
|
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
|
|
|
void InternalCheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
|
|
|
void NotificationSentToAllUsersHandler(const Notification::Ptr& notification,
|
2017-12-19 15:50:05 +01:00
|
|
|
const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
|
|
|
|
const CheckResult::Ptr& cr, const String& author, const String& text);
|
2017-09-07 15:11:57 +02:00
|
|
|
void NotificationSentToAllUsersHandlerInternal(const Notification::Ptr& notification,
|
2017-12-19 15:50:05 +01:00
|
|
|
const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
|
|
|
|
const CheckResult::Ptr& cr, const String& author, const String& text);
|
2017-09-07 15:11:57 +02:00
|
|
|
|
2019-03-19 09:01:12 +01:00
|
|
|
void Enqueue(const Checkable::Ptr& checkable, const String& type,
|
|
|
|
const Dictionary::Ptr& fields, double ts);
|
2017-09-07 15:11:57 +02:00
|
|
|
|
2019-04-23 13:15:38 +02:00
|
|
|
OptionalTlsStream Connect();
|
2018-01-04 04:25:35 +01:00
|
|
|
void AssertOnWorkQueue();
|
2017-09-07 15:11:57 +02:00
|
|
|
void ExceptionHandler(boost::exception_ptr exp);
|
2018-01-04 04:25:35 +01:00
|
|
|
void FlushTimeout();
|
|
|
|
void Flush();
|
2017-09-07 15:11:57 +02:00
|
|
|
void SendRequest(const String& body);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-09 14:05:10 +01:00
|
|
|
#endif /* ELASTICSEARCHWRITER_H */
|