2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2016-04-19 13:54:41 +02:00
|
|
|
|
|
|
|
#include "perfdata/influxdbwriter.hpp"
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "perfdata/influxdbwriter-ti.cpp"
|
2021-04-14 18:52:36 +02:00
|
|
|
#include "base/base64.hpp"
|
2016-04-19 13:54:41 +02:00
|
|
|
#include "remote/url.hpp"
|
|
|
|
#include "base/configtype.hpp"
|
2017-05-15 15:51:39 +02:00
|
|
|
#include "base/perfdatavalue.hpp"
|
2016-04-19 13:54:41 +02:00
|
|
|
#include "base/statsfunction.hpp"
|
2019-04-23 11:25:52 +02:00
|
|
|
#include <boost/beast/http/message.hpp>
|
|
|
|
#include <boost/beast/http/string_body.hpp>
|
2018-01-04 08:54:18 +01:00
|
|
|
#include <utility>
|
2016-04-19 13:54:41 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
REGISTER_TYPE(InfluxdbWriter);
|
|
|
|
|
|
|
|
REGISTER_STATSFUNCTION(InfluxdbWriter, &InfluxdbWriter::StatsFunc);
|
|
|
|
|
2017-05-26 17:03:49 +02:00
|
|
|
void InfluxdbWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
|
2016-04-19 13:54:41 +02:00
|
|
|
{
|
2021-04-14 18:52:36 +02:00
|
|
|
InfluxdbCommonWriter::StatsFunc<InfluxdbWriter>(status, perfdata);
|
2016-06-07 14:35:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 18:52:36 +02:00
|
|
|
boost::beast::http::request<boost::beast::http::string_body> InfluxdbWriter::AssembleRequest(String body)
|
2016-06-07 14:35:16 +02:00
|
|
|
{
|
2021-04-14 18:52:36 +02:00
|
|
|
auto request (AssembleBaseRequest(std::move(body)));
|
|
|
|
Dictionary::Ptr basicAuth = GetBasicAuth();
|
2016-06-07 14:35:16 +02:00
|
|
|
|
2021-04-14 18:52:36 +02:00
|
|
|
if (basicAuth) {
|
|
|
|
request.set(
|
|
|
|
boost::beast::http::field::authorization,
|
|
|
|
"Basic " + Base64::Encode(basicAuth->Get("username") + ":" + basicAuth->Get("password"))
|
|
|
|
);
|
2016-04-19 13:54:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 18:52:36 +02:00
|
|
|
return std::move(request);
|
2016-04-19 13:54:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 18:52:36 +02:00
|
|
|
Url::Ptr InfluxdbWriter::AssembleUrl()
|
2016-04-19 13:54:41 +02:00
|
|
|
{
|
2021-04-14 18:52:36 +02:00
|
|
|
auto url (AssembleBaseUrl());
|
2016-04-19 13:54:41 +02:00
|
|
|
|
|
|
|
std::vector<String> path;
|
2018-01-04 09:14:55 +01:00
|
|
|
path.emplace_back("write");
|
2016-04-19 13:54:41 +02:00
|
|
|
url->SetPath(path);
|
|
|
|
|
|
|
|
url->AddQueryElement("db", GetDatabase());
|
2021-04-14 18:52:36 +02:00
|
|
|
|
2016-04-19 13:54:41 +02:00
|
|
|
if (!GetUsername().IsEmpty())
|
|
|
|
url->AddQueryElement("u", GetUsername());
|
|
|
|
if (!GetPassword().IsEmpty())
|
|
|
|
url->AddQueryElement("p", GetPassword());
|
|
|
|
|
2021-04-14 18:52:36 +02:00
|
|
|
return std::move(url);
|
2016-04-19 13:54:41 +02:00
|
|
|
}
|