1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
23 #include "perfdata/gelfwriter-ti.hpp"
24 #include "icinga/service.hpp"
25 #include "base/configobject.hpp"
26 #include "base/tcpsocket.hpp"
27 #include "base/timer.hpp"
28 #include "base/workqueue.hpp"
35 * An Icinga Gelf writer for Graylog.
39 class GelfWriter final : public ObjectImpl<GelfWriter>
42 DECLARE_OBJECT(GelfWriter);
43 DECLARE_OBJECTNAME(GelfWriter);
45 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
48 void OnConfigLoaded() override;
49 void Resume() override;
50 void Pause() override;
54 WorkQueue m_WorkQueue{10000000, 1};
56 Timer::Ptr m_ReconnectTimer;
58 void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
59 void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
60 void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
61 const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr,
62 const String& author, const String& commentText, const String& commandName);
63 void NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
64 const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr,
65 const String& author, const String& comment_text, const String& command_name);
66 void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
67 void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
69 String ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts);
70 void SendLogMessage(const String& gelfMessage);
72 void ReconnectTimerHandler();
77 void AssertOnWorkQueue();
79 void ExceptionHandler(boost::exception_ptr exp);
84 #endif /* GELFWRITER_H */