Commit 9a431adc authored by Micha Mueller's avatar Micha Mueller
Browse files

Implement infrastructure to print config

parent 4361e22d
......@@ -24,6 +24,7 @@ Configuration::Configuration(const std::string& cfgFilePath) :
}
//set default values for global variables
_global.validateConfig = false;
_global.qosLevel = 1;
_global.daemonize = 0;
_global.hierarchy = "";
......@@ -104,6 +105,10 @@ bool Configuration::readGlobal() {
if (global.second.data() == "true") {
_global.daemonize = 1;
}
} else if (boost::iequals(global.first, "validateConfig")) {
if (global.second.data() == "true") {
_global.validateConfig = true;
}
} else if (boost::iequals(global.first, "verbosity")) {
_global.logLevelFile = translateLogLevel(stoi(global.second.data()));
} else if (boost::iequals(global.first, "cacheInterval")) {
......
......@@ -16,6 +16,7 @@
#include "includes/PluginDefinitions.h"
typedef struct {
bool validateConfig;
int daemonize;
int brokerPort;
int qosLevel;
......
......@@ -147,7 +147,7 @@ void printSyntax()
012345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
cout << "Usage:" << endl;
cout << " dcdbpusher [-d] [-a<string>] [-b<host>] [-p<port>] [-m<string>] [-t<number>] <path/to/configfiles/>" << endl;
cout << " dcdbpusher [-d] [-x] [-a<string>] [-b<host>] [-p<port>] [-m<string>] [-t<number>] <path/to/configfiles/>" << endl;
cout << " dcdbpusher -h" << endl;
cout << endl;
......@@ -164,6 +164,7 @@ void printSyntax()
<< " Default level is 3 (info)" << endl;
cout << endl;
cout << " -d Daemonize" << endl;
cout << " -x Parse and print the config but do not actually start dcdbpusher" << endl;
cout << " -h This help page" << endl;
cout << endl;
}
......@@ -180,7 +181,7 @@ int main(int argc, char** argv) {
}
//define allowed command-line options once
const char opts[] = "a:b:p:m:t:v:w:c:dh";
const char opts[] = "a:b:p:m:t:v:w:c:dxh";
//check if help flag specified
char c;
......@@ -255,6 +256,9 @@ int main(int argc, char** argv) {
case 'd':
globalSettings.daemonize = 1;
break;
case 'x':
globalSettings.validateConfig = true;
break;
case 'w':
pluginSettings.tempdir = optarg;
if (pluginSettings.tempdir[pluginSettings.tempdir.length()-1] != '/') {
......@@ -304,7 +308,15 @@ int main(int argc, char** argv) {
return 1;
}
//give some feedback
//print configuration to give some feedback
//config of plugins is only printed if the config shall be validated or to debug level otherwise
LOG_LEVEL vLogLevel = LOG_LEVEL::debug;
if (globalSettings.validateConfig) {
vLogLevel = boost::log::trivial::info;
}
LOG_VAR(vLogLevel) << "----- Configuration: -----";
//print global settings in either case
LOG(info) << "Global Settings:";
LOG(info) << " Broker: " << globalSettings.brokerHost << ":" << globalSettings.brokerPort;
LOG(info) << " Threads: " << globalSettings.threads;
......@@ -328,6 +340,22 @@ int main(int argc, char** argv) {
#else
LOG(info) << " Certificate, private key and DH-param file not printed.";
#endif
if(globalSettings.validateConfig) {
LOG(info) << " Only validating config files.";
} else {
LOG(info) << " validateConfig: Disabled";
}
for(auto& p : _configuration->getPlugins()) {
LOG_VAR(vLogLevel) << "Plugin \"" << p.id << "\"";
p.configurator->printConfig(vLogLevel);
}
LOG_VAR(vLogLevel) << "----- End Config -----";
if (globalSettings.validateConfig) {
return 0;
}
//MQTTPusher and Https server get their own threads
_analyticsManager = new AnalyticsManager();
......
......@@ -31,6 +31,7 @@ public:
virtual std::string getVersion() = 0;
virtual bool readConfig(std::string cfgPath) = 0;
virtual bool reReadConfig() = 0;
virtual void printConfig(LOG_LEVEL ll) = 0;
virtual void setGlobalSettings(const pluginSettings_t& pluginSettings) = 0;
virtual std::vector<SGroupPtr>& getSensorGroups() = 0;
......
......@@ -32,6 +32,8 @@
#define ATTRIBUTE(name,setter) do { if (boost::iequals(val.first, name)) { s.setter(val.second.data()); } } while(0)
#define SETTING(name) if (boost::iequals(val.first, name))
#define DEFAULT_CACHE_INTERVAL 900000
/**
* Non-virtual interface template for the configurators.
*/
......@@ -65,7 +67,7 @@ public:
_cfgPath(""),
_mqttPrefix(""),
_sensorPattern(""),
_cacheInterval(900000) {}
_cacheInterval(DEFAULT_CACHE_INTERVAL) {}
ConfiguratorTemplate(const ConfiguratorTemplate&) = delete;
......@@ -302,6 +304,42 @@ public:
return readConfig(_cfgPath);
}
void printConfig(LOG_LEVEL ll) final {
LOG_VAR(ll) << " General: ";
std::string _mqttPrefix;
std::string _sensorPattern;
unsigned int _cacheInterval;
if (_mqttPrefix != "") {
LOG_VAR(ll) << " MQTT-Prefix: " << _mqttPrefix;
} else {
LOG_VAR(ll) << " MQTT-Prefix: DEFAULT";
}
if (_sensorPattern != "") {
LOG_VAR(ll) << " Sensor Pattern: " << _sensorPattern;
}
if (_cacheInterval != DEFAULT_CACHE_INTERVAL) {
LOG_VAR(ll) << " Cache interval: " << _cacheInterval;
} else {
LOG_VAR(ll) << " Cache interval: DEFAULT";
}
printConfiguratorConfig(ll);
LOG_VAR(ll) << " Entities (" << _entityName << "):";
if (_sensorEntitys.size() != 0) {
for(auto e : _sensorEntitys) {
e->printConfig();
}
} else {
LOG_VAR(ll) << " No entities for this plugin";
}
LOG_VAR(ll) << " Groups:";
for(auto g : _sensorGroups) {
g->printConfig();
}
}
/**
* Sets internal variables with the ones provided by pluginSettings.
* This method should be called once after constructing a configurator
......@@ -681,6 +719,16 @@ protected:
LOG(warning) << "Method finalizeEntityGroup called, but was not overwritten! Either you have unwanted entitys in your config file or forgot to overwrite this method";
}
/**
* Print information about configurable configurator attributes (or nothing if no such attributes are required)
*
* @param ll Severity level to log with
*/
virtual void printConfiguratorConfig(LOG_LEVEL ll) {
//Overwrite if necessary
LOG_VAR(ll) << " No other plugin specific general parameters";
}
/**
* Virtual interface method, responsible for reading plugin-specific global values.
*
......
......@@ -18,8 +18,15 @@
#include <boost/log/trivial.hpp>
#include <boost/log/sources/severity_logger.hpp>
#define LOG_LEVEL boost::log::trivial::severity_level
#define LOGGER boost::log::sources::severity_logger<LOG_LEVEL>
//further abbreviate the boost shortcut-macro
//to use it, only a boost severity-logger named lg is required
#define LOG(sev) BOOST_LOG_SEV(lg, boost::log::trivial::sev)
//another shortcut which can take the severity level as variable
#define LOG_VAR(var) BOOST_LOG_SEV(lg, var)
#endif /* LOGGING_H_ */
......@@ -13,6 +13,7 @@
#include <string>
#include <limits.h>
#include <boost/lockfree/spsc_queue.hpp>
#include <Logging.h>
typedef struct {
int64_t value;
......@@ -286,6 +287,23 @@ public:
static std::string formatName(const std::string& name, int cpuID=-1) {return cpuID<0 ? name : "cpu" + std::to_string(cpuID) + "." + name;}
virtual void printConfig(LOG_LEVEL ll, LOGGER& lg) {
LOG_VAR(ll) << " Sensor " << _name;
LOG_VAR(ll) << " MQTT Topic: " << _mqtt;
if(_skipConstVal) {
LOG_VAR(ll) << " Skipping constant values";
} else {
LOG_VAR(ll) << " No skipping of constant values";
}
if(_delta) {
LOG_VAR(ll) << " Storing delta readings";
} else {
LOG_VAR(ll) << " Storing absolute readings";
}
}
protected:
std::string _name;
......
......@@ -80,6 +80,21 @@ public:
_timer.reset(new boost::asio::deadline_timer(io, boost::posix_time::seconds(0)));
}
virtual void printConfig(LOG_LEVEL ll) {
if (_mqttPart != "") {
LOG_VAR(ll) << " MQTT part: " << _mqttPart;
}
if (_sync) {
LOG_VAR(ll) << " Synchronized readings enabled";
} else {
LOG_VAR(ll) << " Synchronized readings disabled";
}
LOG_VAR(ll) << " minValues: " << _minValues;
LOG_VAR(ll) << " interval: " << _interval;
}
//have to be overwritten
virtual void start() = 0;
virtual void stop() = 0;
......@@ -99,7 +114,7 @@ protected:
unsigned int _interval;
std::atomic_uint _pendingTasks;
std::unique_ptr<boost::asio::deadline_timer> _timer;
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
LOGGER lg;
};
//for better readability
......
......@@ -75,6 +75,15 @@ public:
}
}
virtual void printConfig(LOG_LEVEL ll) override {
SensorGroupInterface::printConfig(ll);
for(auto s : _sensors) {
s->SensorBase::printConfig(ll, lg);
s->printConfig(ll, lg);
}
}
protected:
/** Calculate timestamp for the next reading
* @return Timestamp in the future to wait for
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment