1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/*
* Copyright (c) 2024 Axoflow
* Copyright (c) 2024 Attila Szakacs <attila.szakacs@axoflow.com>
* Copyright (c) 2023 László Várady
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef LOKI_DEST_HPP
#define LOKI_DEST_HPP
#include "loki-dest.h"
#include "compat/cpp-start.h"
#include "template/templates.h"
#include "stats/stats-cluster-key-builder.h"
#include "logmsg/logmsg.h"
#include "compat/cpp-end.h"
#include "credentials/grpc-credentials-builder.hpp"
#include "metrics/grpc-metrics.hpp"
#include <string>
#include <vector>
#include <memory>
namespace syslogng {
namespace grpc {
namespace loki {
struct Label
{
std::string name;
LogTemplate *value;
Label(std::string name_, LogTemplate *value_)
: name(name_), value(log_template_ref(value_)) {}
Label(const Label &a)
: name(a.name), value(log_template_ref(a.value)) {}
Label &operator=(const Label &a)
{
name = a.name;
log_template_unref(value);
value = log_template_ref(a.value);
return *this;
}
~Label()
{
log_template_unref(value);
}
};
class DestinationDriver final
{
public:
DestinationDriver(LokiDestDriver *s);
~DestinationDriver();
bool init();
bool deinit();
const gchar *format_persist_name();
const gchar *format_stats_key(StatsClusterKeyBuilder *kb);
GrpcClientCredentialsBuilderW *get_credentials_builder_wrapper();
void add_label(std::string name, LogTemplate *value);
LogTemplateOptions &get_template_options()
{
return this->template_options;
}
void set_url(std::string u)
{
this->url = u;
}
void set_message_template_ref(LogTemplate *msg)
{
log_template_unref(this->message);
this->message = msg;
}
bool set_timestamp(const char *t)
{
if (strcasecmp(t, "current") == 0)
this->timestamp = LM_TS_PROCESSED;
else if (strcasecmp(t, "received") == 0)
this->timestamp = LM_TS_RECVD;
else if (strcasecmp(t, "msg") == 0)
this->timestamp = LM_TS_STAMP;
else
return false;
return true;
}
void set_keepalive_time(int t)
{
this->keepalive_time = t;
}
void set_keepalive_timeout(int t)
{
this->keepalive_timeout = t;
}
void set_keepalive_max_pings(int p)
{
this->keepalive_max_pings_without_data = p;
}
void set_tenant_id(std::string tid)
{
this->tenant_id = tid;
}
void add_extra_channel_arg(std::string name, long value)
{
this->int_extra_channel_args.push_back(std::pair<std::string, long> {name, value});
}
void add_extra_channel_arg(std::string name, std::string value)
{
this->string_extra_channel_args.push_back(std::pair<std::string, std::string> {name, value});
}
void add_header(std::string name, std::string value)
{
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
this->headers.push_back(std::pair<std::string, std::string> {name, value});
}
const std::string &get_url()
{
return this->url;
}
private:
friend class DestinationWorker;
private:
LokiDestDriver *super;
LogTemplateOptions template_options;
std::string url;
std::string tenant_id;
LogTemplate *message = nullptr;
std::vector<Label> labels;
LogMessageTimeStamp timestamp;
syslogng::grpc::ClientCredentialsBuilder credentials_builder;
GrpcClientCredentialsBuilderW credentials_builder_wrapper;
int keepalive_time;
int keepalive_timeout;
int keepalive_max_pings_without_data;
std::list<std::pair<std::string, long>> int_extra_channel_args;
std::list<std::pair<std::string, std::string>> string_extra_channel_args;
std::list<std::pair<std::string, std::string>> headers;
DestDriverMetrics metrics;
};
}
}
}
syslogng::grpc::loki::DestinationDriver *loki_dd_get_cpp(LokiDestDriver *self);
#endif
|