2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-11-05 22:00:44 +01:00
|
|
|
|
|
|
|
#ifndef GELFWRITER_H
|
|
|
|
#define GELFWRITER_H
|
|
|
|
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "perfdata/gelfwriter-ti.hpp"
|
2014-11-05 22:00:44 +01:00
|
|
|
#include "icinga/service.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configobject.hpp"
|
2014-11-05 22:00:44 +01:00
|
|
|
#include "base/tcpsocket.hpp"
|
|
|
|
#include "base/timer.hpp"
|
2017-06-06 19:48:23 +02:00
|
|
|
#include "base/workqueue.hpp"
|
2014-11-05 22:00:44 +01:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2017-06-06 19:48:23 +02:00
|
|
|
* An Icinga Gelf writer for Graylog.
|
2014-11-05 22:00:44 +01:00
|
|
|
*
|
|
|
|
* @ingroup perfdata
|
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class GelfWriter final : public ObjectImpl<GelfWriter>
|
2014-11-05 22:00:44 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DECLARE_OBJECT(GelfWriter);
|
|
|
|
DECLARE_OBJECTNAME(GelfWriter);
|
|
|
|
|
2017-06-06 19:48:23 +02:00
|
|
|
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
|
|
|
|
|
2014-11-05 22:00:44 +01:00
|
|
|
protected:
|
2018-01-04 05:12:56 +01:00
|
|
|
void OnConfigLoaded() override;
|
2018-10-24 13:43:38 +02:00
|
|
|
void Resume() override;
|
|
|
|
void Pause() override;
|
2014-11-05 22:00:44 +01:00
|
|
|
|
|
|
|
private:
|
2019-05-16 19:39:06 +02:00
|
|
|
OptionalTlsStream m_Stream;
|
2018-01-04 09:43:49 +01:00
|
|
|
WorkQueue m_WorkQueue{10000000, 1};
|
2015-02-07 22:36:17 +01:00
|
|
|
|
2014-11-05 22:00:44 +01:00
|
|
|
Timer::Ptr m_ReconnectTimer;
|
|
|
|
|
|
|
|
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
2017-06-06 19:48:23 +02:00
|
|
|
void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
2015-02-07 22:36:17 +01:00
|
|
|
void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
|
2020-01-07 14:20:59 +01:00
|
|
|
const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String& author, const String& commentText, const String& commandName);
|
2017-06-06 19:48:23 +02:00
|
|
|
void NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
|
2020-01-07 14:20:59 +01:00
|
|
|
const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String& author, const String& comment_text, const String& command_name);
|
2015-02-07 22:36:17 +01:00
|
|
|
void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
|
2017-06-06 19:48:23 +02:00
|
|
|
void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
|
|
|
|
|
|
|
|
String ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts);
|
2019-03-19 09:32:02 +01:00
|
|
|
void SendLogMessage(const Checkable::Ptr& checkable, const String& gelfMessage);
|
2014-11-05 22:00:44 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void ReconnectTimerHandler();
|
2017-06-06 19:48:23 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Disconnect();
|
2019-02-20 17:18:24 +01:00
|
|
|
void DisconnectInternal();
|
2018-01-04 04:25:35 +01:00
|
|
|
void Reconnect();
|
2019-02-20 17:18:24 +01:00
|
|
|
void ReconnectInternal();
|
2017-06-06 19:48:23 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void AssertOnWorkQueue();
|
2017-06-06 19:48:23 +02:00
|
|
|
|
|
|
|
void ExceptionHandler(boost::exception_ptr exp);
|
2014-11-05 22:00:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GELFWRITER_H */
|