Skip to content

Commit

Permalink
Add ssl_verify_peer option for Influx DB CURL (#381)
Browse files Browse the repository at this point in the history
* Insecure SSL added for Influx DB CURL

* Add option for disabling uuids for influx db

Increased precision of numbers sent to influx db.

* Refactored according to request of mbehr1

* Add ssl_verifypeer option for InfluxDB

ssl_verifypeer defaults to true. For self signed certificates you can
set this option to false in order to allow a SSL connection to InfluxDB.

* Add new InfluxDB options to vzlogger.conf.InfluxDB
  • Loading branch information
andremueller authored and andig committed Aug 17, 2019
1 parent 328311f commit 793a843
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions etc/vzlogger.conf.InfluxDB
Expand Up @@ -31,6 +31,8 @@
//"max_batch_inserts": 4500, // Optional: Max number of measurements per request. No need to change this
//"max_buffer_size": 450000, // Optional: Max number of measurements to be cached when InfluxDB is not available
//"timeout": 30, // Optional: Time in seconds after which requests to InfluxDB time out
//"send_uuid": false, // Optional: Disables the sending of the UUID to the InfluxDB server
//"ssl_verifypeer": false, // Optional: Disables the certificate verification for https connections
}]
},
]
Expand Down
2 changes: 2 additions & 0 deletions include/api/InfluxDB.hpp
Expand Up @@ -64,6 +64,8 @@ namespace vz {
int _max_batch_inserts;
int _max_buffer_size;
unsigned int _curl_timeout;
bool _send_uuid;
bool _ssl_verifypeer;
std::list<Reading> _values;
CurlResponse::Ptr _response;

Expand Down
38 changes: 33 additions & 5 deletions src/api/InfluxDB.cpp
Expand Up @@ -35,6 +35,8 @@
#include "CurlSessionProvider.hpp"
#include <api/CurlCallback.hpp>
#include <api/CurlResponse.hpp>
#include <iomanip>
#include <sstream>

extern Config_Options options;

Expand Down Expand Up @@ -151,6 +153,28 @@ vz::api::InfluxDB::InfluxDB(
throw;
}

try {
_send_uuid = optlist.lookup_bool(pOptions, "send_uuid");
print(log_finest, "api InfluxDB using send_uuid: %s", ch->name(), _send_uuid ? "true" : "false");
} catch (vz::OptionNotFoundException &e) {
_send_uuid = true;
print(log_finest, "api InfluxDB will use default send_uuid %s", ch->name(), _send_uuid ? "true" : "false");
} catch (vz::VZException &e) {
print(log_alert, "api InfluxDB requires parameter \"send_uuid\" as bool!", ch->name());
throw;
}

try {
_ssl_verifypeer = optlist.lookup_bool(pOptions, "ssl_verifypeer");
print(log_finest, "api InfluxDB using ssl_verifypeer: %s", ch->name(), _ssl_verifypeer ? "true" : "false");
} catch (vz::OptionNotFoundException &e) {
_ssl_verifypeer = true;
print(log_finest, "api InfluxDB will use default ssl_verifypeer %s", ch->name(), _ssl_verifypeer ? "true" : "false");
} catch (vz::VZException &e) {
print(log_alert, "api InfluxDB requires parameter \"_ssl_verifypeer\" as bool!", ch->name());
throw;
}

CURL *curlhelper = curl_easy_init();
if(!curlhelper) {
throw vz::VZException("CURL: cannot create handle for urlencode.");
Expand Down Expand Up @@ -216,14 +240,17 @@ void vz::api::InfluxDB::send()
}
print(log_finest, "Reading buffer: timestamp %lld value %f", channel()->name(), it->time_ms(), it->value());
request_body.append(_measurement_name);
request_body.append(",uuid=");
request_body.append(channel()->uuid());
if (_send_uuid) {
request_body.append(",uuid=");
request_body.append(channel()->uuid());
}
if (!_tags.empty()) {
request_body.append(",");
request_body.append(_tags);
}
request_body.append(" value=");
request_body.append(std::to_string(it->value()));
std::stringstream value_str;
value_str << " value=" << std::fixed << std::setprecision(6) << it->value();
request_body.append(value_str.str());
request_body.append(" ");
request_body.append(std::to_string(it->time_ms()));
request_body.append("\n"); // each measurement on new line
Expand All @@ -245,7 +272,8 @@ void vz::api::InfluxDB::send()
curl_easy_setopt(_api.curl, CURLOPT_PASSWORD, _password.c_str());
}
curl_easy_setopt(_api.curl, CURLOPT_URL, _url.c_str());
curl_easy_setopt(_api.curl, CURLOPT_VERBOSE, options.verbosity());
curl_easy_setopt(_api.curl, CURLOPT_VERBOSE, options.verbosity() > 0);
curl_easy_setopt(_api.curl, CURLOPT_SSL_VERIFYPEER, _ssl_verifypeer);

curl_easy_setopt(_api.curl, CURLOPT_DEBUGFUNCTION, &(vz::api::CurlCallback::debug_callback));
curl_easy_setopt(_api.curl, CURLOPT_DEBUGDATA, response());
Expand Down

0 comments on commit 793a843

Please sign in to comment.