Review LogstashWriter feature implementation

refs #4054
This commit is contained in:
Michael Friedrich 2017-01-24 12:10:37 +01:00
parent f5a971f5b0
commit bd5ff814f2
10 changed files with 244 additions and 300 deletions

View File

@ -8,6 +8,5 @@ library "perfdata"
object LogstashWriter "logstash" { object LogstashWriter "logstash" {
//host = "127.0.0.1" //host = "127.0.0.1"
//port = 9201 //port = 9201
/* default is tcp */ //socket_type = "udp"
//defaultProtocol = true
} }

View File

@ -38,7 +38,14 @@ using namespace icinga;
* Constructor for the Socket class. * Constructor for the Socket class.
*/ */
Socket::Socket(void) Socket::Socket(void)
: m_FD(INVALID_SOCKET) : m_FD(INVALID_SOCKET), m_SocketType(SOCK_STREAM), m_Protocol(IPPROTO_TCP)
{ }
/**
* Constructor for the Socket class.
*/
Socket::Socket(int socketType, int protocol)
: m_FD(INVALID_SOCKET), m_SocketType(socketType), m_Protocol(protocol)
{ } { }
/** /**
@ -330,6 +337,9 @@ size_t Socket::Read(void *buffer, size_t count)
*/ */
Socket::Ptr Socket::Accept(void) Socket::Ptr Socket::Accept(void)
{ {
if (m_Protocol == IPPROTO_UDP)
BOOST_THROW_EXCEPTION(std::runtime_error("Accept cannot be used for UDP sockets."));
int fd; int fd;
sockaddr_storage addr; sockaddr_storage addr;
socklen_t addrlen = sizeof(addr); socklen_t addrlen = sizeof(addr);
@ -428,7 +438,6 @@ void Socket::SocketPair(SOCKET s[2])
* *
* @param node The node. * @param node The node.
* @param service The service. * @param service The service.
* @param protocol The protocol
*/ */
void Socket::Connect(const String& node, const String& service) void Socket::Connect(const String& node, const String& service)
{ {
@ -437,15 +446,15 @@ void Socket::Connect(const String& node, const String& service)
int error; int error;
const char *func; const char *func;
SocketType();
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = socktype; hints.ai_socktype = m_SocketType;
hints.ai_protocol = protocol; hints.ai_protocol = m_Protocol;
int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result); int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result);
if (rc != 0) { if (rc != 0) {
Log(LogCritical, protocol+"Socket") Log(LogCritical, "Socket")
<< "getaddrinfo() failed with error code " << rc << ", \"" << gai_strerror(rc) << "\""; << "getaddrinfo() failed with error code " << rc << ", \"" << gai_strerror(rc) << "\"";
BOOST_THROW_EXCEPTION(socket_error() BOOST_THROW_EXCEPTION(socket_error()
@ -492,7 +501,7 @@ void Socket::Connect(const String& node, const String& service)
freeaddrinfo(result); freeaddrinfo(result);
if (GetFD() == INVALID_SOCKET) { if (GetFD() == INVALID_SOCKET) {
Log(LogCritical, "UdpSocket") Log(LogCritical, "Socket")
<< "Invalid socket: " << Utility::FormatErrorNumber(error); << "Invalid socket: " << Utility::FormatErrorNumber(error);
#ifndef _WIN32 #ifndef _WIN32

View File

@ -61,18 +61,17 @@ public:
static void SocketPair(SOCKET s[2]); static void SocketPair(SOCKET s[2]);
protected: protected:
Socket(int socketType, int protocol);
void SetFD(SOCKET fd); void SetFD(SOCKET fd);
int GetError(void) const; int GetError(void) const;
int socktype;
int protocol;
virtual void SocketType(){};
mutable boost::mutex m_SocketMutex; mutable boost::mutex m_SocketMutex;
private: private:
SOCKET m_FD; /**< The socket descriptor. */ SOCKET m_FD; /**< The socket descriptor. */
int m_SocketType;
int m_Protocol;
static String GetAddressFromSockaddr(sockaddr *address, socklen_t len); static String GetAddressFromSockaddr(sockaddr *address, socklen_t len);
}; };

View File

@ -27,10 +27,12 @@
using namespace icinga; using namespace icinga;
void TcpSocket::SocketType(){ /**
socktype = SOCK_STREAM; * Constructor for the TcpSocket class.
protocol = IPPROTO_TCP; */
} TcpSocket::TcpSocket(void)
: Socket(SOCK_STREAM, IPPROTO_TCP)
{ }
/** /**
* Creates a socket and binds it to the specified service. * Creates a socket and binds it to the specified service.
@ -136,97 +138,3 @@ void TcpSocket::Bind(const String& node, const String& service, int family)
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
} }
/**
* Creates a socket and connects to the specified node and service.
*
* @param node The node.
* @param service The service.
*/
void TcpSocket::Connect(const String& node, const String& service)
{
addrinfo hints;
addrinfo *result;
int error;
const char *func;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result);
if (rc != 0) {
Log(LogCritical, "TcpSocket")
<< "getaddrinfo() failed with error code " << rc << ", \"" << gai_strerror(rc) << "\"";
BOOST_THROW_EXCEPTION(socket_error()
<< boost::errinfo_api_function("getaddrinfo")
<< errinfo_getaddrinfo_error(rc));
}
int fd = INVALID_SOCKET;
for (addrinfo *info = result; info != NULL; info = info->ai_next) {
fd = socket(info->ai_family, info->ai_socktype, info->ai_protocol);
if (fd == INVALID_SOCKET) {
#ifdef _WIN32
error = WSAGetLastError();
#else /* _WIN32 */
error = errno;
#endif /* _WIN32 */
func = "socket";
continue;
}
const int optTrue = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<const char *>(&optTrue), sizeof(optTrue)) != 0) {
#ifdef _WIN32
error = WSAGetLastError();
#else /* _WIN32 */
error = errno;
#endif /* _WIN32 */
Log(LogWarning, "TcpSocket")
<< "setsockopt() unable to enable TCP keep-alives with error code " << rc;
}
rc = connect(fd, info->ai_addr, info->ai_addrlen);
if (rc < 0) {
#ifdef _WIN32
error = WSAGetLastError();
#else /* _WIN32 */
error = errno;
#endif /* _WIN32 */
func = "connect";
closesocket(fd);
continue;
}
SetFD(fd);
break;
}
freeaddrinfo(result);
if (GetFD() == INVALID_SOCKET) {
Log(LogCritical, "TcpSocket")
<< "Invalid socket: " << Utility::FormatErrorNumber(error);
#ifndef _WIN32
BOOST_THROW_EXCEPTION(socket_error()
<< boost::errinfo_api_function(func)
<< boost::errinfo_errno(error));
#else /* _WIN32 */
BOOST_THROW_EXCEPTION(socket_error()
<< boost::errinfo_api_function(func)
<< errinfo_win32_error(error));
#endif /* _WIN32 */
}
}

View File

@ -36,11 +36,10 @@ class I2_BASE_API TcpSocket : public Socket
public: public:
DECLARE_PTR_TYPEDEFS(TcpSocket); DECLARE_PTR_TYPEDEFS(TcpSocket);
TcpSocket(void);
void Bind(const String& service, int family); void Bind(const String& service, int family);
void Bind(const String& node, const String& service, int family); void Bind(const String& node, const String& service, int family);
private:
void SocketType();
}; };
} }

View File

@ -27,7 +27,10 @@
using namespace icinga; using namespace icinga;
void UdpSocket::SocketType(){ /**
socktype = SOCK_DGRAM; * Constructor for the UdpSocket class.
protocol = IPPROTO_UDP; */
} UdpSocket::UdpSocket(void)
: Socket(SOCK_DGRAM, IPPROTO_UDP)
{ }

View File

@ -1,6 +1,6 @@
/****************************************************************************** /******************************************************************************
* Icinga 2 * * Icinga 2 *
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) * * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
@ -36,9 +36,9 @@ class I2_BASE_API UdpSocket : public Socket
public: public:
DECLARE_PTR_TYPEDEFS(UdpSocket); DECLARE_PTR_TYPEDEFS(UdpSocket);
private: UdpSocket(void);
void SocketType();
}; };
} }
#endif /* UDPSOCKET_H */ #endif /* UDPSOCKET_H */

View File

@ -1,6 +1,6 @@
/****************************************************************************** /******************************************************************************
* Icinga 2 * * Icinga 2 *
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) * * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
@ -23,7 +23,6 @@
#include "icinga/macroprocessor.hpp" #include "icinga/macroprocessor.hpp"
#include "icinga/compatutility.hpp" #include "icinga/compatutility.hpp"
#include "icinga/perfdatavalue.hpp" #include "icinga/perfdatavalue.hpp"
#include "icinga/notification.hpp" #include "icinga/notification.hpp"
#include "base/configtype.hpp" #include "base/configtype.hpp"
#include "base/objectlock.hpp" #include "base/objectlock.hpp"
@ -31,7 +30,6 @@
#include "base/utility.hpp" #include "base/utility.hpp"
#include "base/stream.hpp" #include "base/stream.hpp"
#include "base/networkstream.hpp" #include "base/networkstream.hpp"
#include "base/json.hpp" #include "base/json.hpp"
#include "base/context.hpp" #include "base/context.hpp"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
@ -42,7 +40,6 @@ using namespace icinga;
REGISTER_TYPE(LogstashWriter); REGISTER_TYPE(LogstashWriter);
void LogstashWriter::Start(bool runtimeCreated) void LogstashWriter::Start(bool runtimeCreated)
{ {
ObjectImpl<LogstashWriter>::Start(runtimeCreated); ObjectImpl<LogstashWriter>::Start(runtimeCreated);
@ -61,13 +58,14 @@ void LogstashWriter::Start(bool runtimeCreated)
Service::OnStateChange.connect(boost::bind(&LogstashWriter::StateChangeHandler, this, _1, _2, _3)); Service::OnStateChange.connect(boost::bind(&LogstashWriter::StateChangeHandler, this, _1, _2, _3));
} }
void LogstashWriter::ReconnectTimerHandler(void) void LogstashWriter::ReconnectTimerHandler(void)
{ {
if (m_Stream) if (m_Stream)
return; return;
Socket::Ptr socket; Socket::Ptr socket;
if(GetDefaultProtocol() == true)
if (GetSocketType() == "tcp")
socket = new TcpSocket(); socket = new TcpSocket();
else else
socket = new UdpSocket(); socket = new UdpSocket();
@ -88,14 +86,14 @@ void LogstashWriter::ReconnectTimerHandler(void)
void LogstashWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr) void LogstashWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{ {
CONTEXT("LOGSTASGH Processing check result for '" + checkable->GetName() + "'"); CONTEXT("LOGSTASH Processing check result for '" + checkable->GetName() + "'");
Log(LogDebug, "LogstashWriter")<< "Logstash Processing check result for '" << checkable->GetName() << "'"; Log(LogDebug, "LogstashWriter")
<< "Processing check result for '" << checkable->GetName() << "'";
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
double ts = cr->GetExecutionEnd();
Dictionary::Ptr fields = new Dictionary(); Dictionary::Ptr fields = new Dictionary();
@ -109,8 +107,8 @@ void LogstashWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
fields->Set("last_hard_state", host->GetLastHardState()); fields->Set("last_hard_state", host->GetLastHardState());
} }
fields->Set("hostname", host->GetName()); fields->Set("host_name", host->GetName());
fields->Set("type", "CHECK RESULT"); fields->Set("type", "CheckResult");
fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState())); fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
fields->Set("current_check_attempt", checkable->GetCheckAttempt()); fields->Set("current_check_attempt", checkable->GetCheckAttempt());
@ -120,18 +118,21 @@ void LogstashWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
fields->Set("execution_time", cr->CalculateExecutionTime()); fields->Set("execution_time", cr->CalculateExecutionTime());
fields->Set("reachable", checkable->IsReachable()); fields->Set("reachable", checkable->IsReachable());
double ts = Utility::GetTime();
if (cr) { if (cr) {
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr)); fields->Set("plugin_output", cr->GetOutput());
fields->Set("full_message", CompatUtility::GetCheckResultLongOutput(cr));
fields->Set("check_source", cr->GetCheckSource()); fields->Set("check_source", cr->GetCheckSource());
ts = cr->GetExecutionEnd();
} }
if (GetEnableSendPerfdata()) {
Array::Ptr perfdata = cr->GetPerformanceData(); Array::Ptr perfdata = cr->GetPerformanceData();
if (perfdata) { if (perfdata) {
Dictionary::Ptr perfdataItems = new Dictionary();
ObjectLock olock(perfdata); ObjectLock olock(perfdata);
BOOST_FOREACH(const Value& val, perfdata) { for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv; PerfdataValue::Ptr pdv;
if (val.IsObjectType<PerfdataValue>()) if (val.IsObjectType<PerfdataValue>())
@ -139,29 +140,32 @@ void LogstashWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
else { else {
try { try {
pdv = PerfdataValue::Parse(val); pdv = PerfdataValue::Parse(val);
String escaped_key = pdv->GetLabel();
boost::replace_all(escaped_key, " ", "_");
boost::replace_all(escaped_key, ".", "_");
boost::replace_all(escaped_key, "\\", "_");
boost::algorithm::replace_all(escaped_key, "::", ".");
fields->Set(escaped_key, pdv->GetValue());
if (pdv->GetMin())
fields->Set(escaped_key + "_min", pdv->GetMin());
if (pdv->GetMax())
fields->Set(escaped_key + "_max", pdv->GetMax());
if (pdv->GetWarn())
fields->Set(escaped_key + "_warn", pdv->GetWarn());
if (pdv->GetCrit())
fields->Set(escaped_key + "_crit", pdv->GetCrit());
} catch (const std::exception&) { } catch (const std::exception&) {
Log(LogWarning, "LogstashWriter") Log(LogWarning, "LogstashWriter")
<< "Ignoring invalid perfdata value: '" << val << "' for object '" << "Ignoring invalid perfdata value: '" << val << "' for object '"
<< checkable-GetName() << "'."; << checkable->GetName() << "'.";
} continue;
} }
} }
Dictionary::Ptr perfdataItem = new Dictionary();
perfdataItem->Set("value", pdv->GetValue());
if (pdv->GetMin())
perfdataItem->Set("min", pdv->GetMin());
if (pdv->GetMax())
perfdataItem->Set("max", pdv->GetMax());
if (pdv->GetWarn())
perfdataItem->Set("warn", pdv->GetWarn());
if (pdv->GetCrit())
perfdataItem->Set("crit", pdv->GetCrit());
String escaped_key = EscapeMetricLabel(pdv->GetLabel());
perfdataItems->Set(escaped_key, perfdataItem);
} }
fields->Set("performance_data", perfdataItems);
} }
SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts)); SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts));
@ -175,12 +179,11 @@ void LogstashWriter::NotificationToUserHandler(const Notification::Ptr& notifica
CONTEXT("Logstash Processing notification to all users '" + checkable->GetName() + "'"); CONTEXT("Logstash Processing notification to all users '" + checkable->GetName() + "'");
Log(LogDebug, "LogstashWriter") Log(LogDebug, "LogstashWriter")
<< "Logstash Processing notification for '" << checkable->GetName() << "'"; << "Processing notification for '" << checkable->GetName() << "'";
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
double ts = cr->GetExecutionEnd();
String notification_type_str = Notification::NotificationTypeToString(notification_type); String notification_type_str = Notification::NotificationTypeToString(notification_type);
@ -190,24 +193,25 @@ void LogstashWriter::NotificationToUserHandler(const Notification::Ptr& notifica
author_comment = author + ";" + comment_text; author_comment = author + ";" + comment_text;
} }
String output; double ts = Utility::GetTime();
if (cr)
output = CompatUtility::GetCheckResultOutput(cr);
Dictionary::Ptr fields = new Dictionary(); Dictionary::Ptr fields = new Dictionary();
if (service) { if (service) {
fields->Set("type", "SERVICE NOTIFICATION"); fields->Set("type", "SERVICE NOTIFICATION");
fields->Set("service", service->GetShortName()); fields->Set("service_name", service->GetShortName());
fields->Set("short_message", output);
} else { } else {
fields->Set("type", "HOST NOTIFICATION"); fields->Set("type", "HOST NOTIFICATION");
fields->Set("short_message", CompatUtility::GetHostStateString(host)+ ")"); }
if (cr) {
fields->Set("plugin_output", cr->GetOutput());
ts = cr->GetExecutionEnd();
} }
fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState())); fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
fields->Set("hostname", host->GetName()); fields->Set("host_name", host->GetName());
fields->Set("command", command_name); fields->Set("command", command_name);
fields->Set("notification_type", notification_type_str); fields->Set("notification_type", notification_type_str);
fields->Set("comment", author_comment); fields->Set("comment", author_comment);
@ -220,17 +224,16 @@ void LogstashWriter::StateChangeHandler(const Checkable::Ptr& checkable, const C
CONTEXT("Logstash Processing state change '" + checkable->GetName() + "'"); CONTEXT("Logstash Processing state change '" + checkable->GetName() + "'");
Log(LogDebug, "LogstashWriter") Log(LogDebug, "LogstashWriter")
<< "Logstash Processing state change for '" << checkable->GetName() << "'"; << "Processing state change for '" << checkable->GetName() << "'";
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
double ts = cr->GetExecutionEnd();
Dictionary::Ptr fields = new Dictionary(); Dictionary::Ptr fields = new Dictionary();
fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState())); fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
fields->Set("type", "STATE CHANGE"); fields->Set("type", "StateChange");
fields->Set("current_check_attempt", checkable->GetCheckAttempt()); fields->Set("current_check_attempt", checkable->GetCheckAttempt());
fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts()); fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
fields->Set("hostname", host->GetName()); fields->Set("hostname", host->GetName());
@ -245,11 +248,14 @@ void LogstashWriter::StateChangeHandler(const Checkable::Ptr& checkable, const C
fields->Set("last_hard_state", host->GetLastHardState()); fields->Set("last_hard_state", host->GetLastHardState());
} }
double ts = Utility::GetTime();
if (cr) { if (cr) {
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr)); fields->Set("plugin_output", cr->GetOutput());
fields->Set("full_message", CompatUtility::GetCheckResultLongOutput(cr));
fields->Set("check_source", cr->GetCheckSource()); fields->Set("check_source", cr->GetCheckSource());
ts = cr->GetExecutionEnd();
} }
SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts)); SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts));
} }
@ -258,8 +264,8 @@ String LogstashWriter::ComposeLogstashMessage(const Dictionary::Ptr& fields, con
fields->Set("version", "1.1"); fields->Set("version", "1.1");
fields->Set("host", source); fields->Set("host", source);
fields->Set("timestamp", ts); fields->Set("timestamp", ts);
String logstashObj= JsonEncode(fields);
return logstashObj+ "\n"; return JsonEncode(fields) + "\n";
} }
void LogstashWriter::SendLogMessage(const String& message) void LogstashWriter::SendLogMessage(const String& message)
@ -272,10 +278,30 @@ void LogstashWriter::SendLogMessage(const String& message)
try { try {
m_Stream->Write(&message[0], message.GetLength()); m_Stream->Write(&message[0], message.GetLength());
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Log(LogCritical, "LogstashWriter") << "Cannot write to " << Log(LogCritical, "LogstashWriter")
((GetDefaultProtocol()==true) ? "tcp" : "udp") << " socket on host '" << GetHost() << "' port '" << GetPort() << "'."; << "Cannot write to " << GetSocketType()
<< " socket on host '" << GetHost() << "' port '" << GetPort() << "'.";
m_Stream.reset(); m_Stream.reset();
} }
} }
String LogstashWriter::EscapeMetricLabel(const String& str)
{
String result = str;
boost::replace_all(result, " ", "_");
boost::replace_all(result, ".", "_");
boost::replace_all(result, "\\", "_");
boost::replace_all(result, "::", ".");
return result;
}
void LogstashWriter::ValidateSocketType(const String& value, const ValidationUtils& utils)
{
ObjectImpl<LogstashWriter>::ValidateSocketType(value, utils);
if (value != "udp" && value != "tcp")
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("socket_type"), "Socket type '" + value + "' is invalid."));
}

View File

@ -1,6 +1,6 @@
/****************************************************************************** /******************************************************************************
* Icinga 2 * * Icinga 2 *
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) * * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
@ -39,10 +39,13 @@ namespace icinga
*/ */
class LogstashWriter : public ObjectImpl<LogstashWriter> class LogstashWriter : public ObjectImpl<LogstashWriter>
{ {
public: public:
DECLARE_OBJECT(LogstashWriter); DECLARE_OBJECT(LogstashWriter);
DECLARE_OBJECTNAME(LogstashWriter); DECLARE_OBJECTNAME(LogstashWriter);
virtual void ValidateSocketType(const String& value, const ValidationUtils& utils) override;
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
@ -59,6 +62,8 @@ private:
void SendLogMessage(const String& message); void SendLogMessage(const String& message);
String ComposeLogstashMessage(const Dictionary::Ptr& fields, const String& source, double ts); String ComposeLogstashMessage(const Dictionary::Ptr& fields, const String& source, double ts);
static String EscapeMetricLabel(const String& str);
void ReconnectTimerHandler(void); void ReconnectTimerHandler(void);
}; };

View File

@ -34,17 +34,13 @@ class LogstashWriter : ConfigObject
default {{{ return "9201"; }}} default {{{ return "9201"; }}}
}; };
[config] bool defaultProtocol { [config] String socket_type {
default {{{ return "true"; }}} default {{{ return "udp"; }}}
}; };
[config] String source { [config] String source {
default {{{ return "icinga2"; }}} default {{{ return "icinga2"; }}}
}; };
[config] bool enable_send_perfdata {
default {{{ return false; }}}
};
}; };
} }