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