Commit 62aea5ef authored by Micha Mueller's avatar Micha Mueller
Browse files

Improve readability in Configurators:

  -introduce STRCMP macro
  -remove "Value not recognized" messages
Move logger instance from ConfiguratorTemplate to ConfiguratorInterface
parent 6f1ac25b
......@@ -34,6 +34,8 @@ public:
virtual std::vector<Sensor*>& getSensors() = 0;
virtual std::vector<SensorGroup*>& getSensorGroups() = 0;
protected:
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
};
//typedef for more readable usage of create()- and destroy()-methods, required for dynamic libraries
......
......@@ -17,6 +17,8 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#define STRCMP(node,str) boost::iequals(node.first,str)
/**
* Non-virtual interface template for the configurators.
*/
......@@ -54,18 +56,16 @@ public:
boost::optional<boost::property_tree::iptree&> globalVals = cfg.get_child_optional("global");
if (globalVals) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "mqttprefix")) {
if (STRCMP(global, "mqttprefix")) {
_mqttPrefix = global.second.data();
if (_mqttPrefix[_mqttPrefix.length()-1] != '/') {
_mqttPrefix.append("/");
}
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
} else if (boost::iequals(global.first, "cacheInterval")) {
} else if (STRCMP(global, "cacheInterval")) {
_cacheInterval = stoul(global.second.data());
LOG(debug) << " Using own caching interval " << _cacheInterval << " [s]";
_cacheInterval *= 1000;
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting for the moment";
}
}
}
......@@ -74,7 +74,7 @@ public:
boost::optional<boost::property_tree::iptree&> tempSens = cfg.get_child_optional("sensorTemplates");
if (tempSens) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensorVal, cfg.get_child("sensorTemplates")) {
if (boost::iequals(sensorVal.first, "sensor")) {
if (STRCMP(sensorVal, "sensor")) {
LOG(debug) << "Template Sensor \"" << sensorVal.second.data() << "\"";
if (!sensorVal.second.empty()) {
S sensor(sensorVal.second.data());
......@@ -179,12 +179,10 @@ protected:
bool readSensor(S& sensor, boost::property_tree::iptree& config) {
//read in base values
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
if (STRCMP(val, "interval")) {
sensor.setInterval(stoull(val.second.data()));
} else if (boost::iequals(val.first, "minValues")) {
} else if (STRCMP(val, "minValues")) {
sensor.setMinValues(stoull(val.second.data()));
} else {
//do nothing. Derived function should read in other values
}
}
sensor.setCacheInterval(_cacheInterval);
......@@ -236,7 +234,6 @@ protected:
std::vector<Sensor*> _sensors;
std::vector<SensorGroup*> _sensorGroups;
sensorMap_t _templateSensors;
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
};
#endif /* SRC_CONFIGURATORTEMPLATE_H_ */
......@@ -29,30 +29,24 @@ bool BACnetConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read global variables (if present overwrite those from global.conf)
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "address_cache")) {
if (STRCMP(global, "address_cache")) {
address_cache = global.second.data();
LOG(debug) << " Address Cache: " << address_cache;
} else if (boost::iequals(global.first, "interface")) {
} else if (STRCMP(global, "interface")) {
interface = global.second.data();
LOG(debug) << " Interface " << interface;
} else if (boost::iequals(global.first, "port")) {
} else if (STRCMP(global, "port")) {
port = stoul(global.second.data());
LOG(debug) << " Port " << port;
} else if (boost::iequals(global.first, "timeout")) {
} else if (STRCMP(global, "timeout")) {
timeout = stoul(global.second.data());
LOG(debug) << " Timeout " << timeout;
} else if (boost::iequals(global.first, "apdu_timeout")) {
} else if (STRCMP(global, "apdu_timeout")) {
apdu_timeout = stoul(global.second.data());
LOG(debug) << " apdu_timeout " << apdu_timeout;
} else if (boost::iequals(global.first, "apdu_retries")) {
} else if (STRCMP(global, "apdu_retries")) {
apdu_retries = stoul(global.second.data());
LOG(debug) << " apdu_retries " << apdu_retries;
} else if (boost::iequals(global.first, "mqttprefix")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(global.first, "cacheInterval")) {
//avoid unnecessary "Value not recognized" messages
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
}
......@@ -64,31 +58,31 @@ bool BACnetConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
}
BOOST_FOREACH(boost::property_tree::iptree::value_type &device, cfg.get_child("devices")) {
if (boost::iequals(device.first, ("device"))) {
if (STRCMP(device, "device")) {
LOG(debug) << "Device " << device.second.data();
if (!device.second.empty()) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &d, device.second) {
if (boost::iequals(d.first, "instance")) {
if (STRCMP(d, "instance")) {
deviceInstance = stoul(d.second.data());
} else if (boost::iequals(d.first, "mqttPart")) {
} else if (STRCMP(d, "mqttPart")) {
mqttPartDevice = d.second.data();
if (mqttPartDevice[mqttPartDevice.length()-1] != '/') {
mqttPartDevice.append("/");
}
} else if (boost::iequals(d.first, "object")) {
} else if (STRCMP(d, "object")) {
LOG(debug) << "Object \"" << d.second.data() << "\"";
if (!d.second.empty()) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &object, d.second) {
if (boost::iequals(object.first, "type")) {
if (STRCMP(object, "type")) {
objType = static_cast<BACNET_OBJECT_TYPE>(stoul(object.second.data()));
} else if (boost::iequals(object.first, "instance")) {
} else if (STRCMP(object, "instance")) {
objInstance = stoul(object.second.data());
} else if (boost::iequals(object.first, "mqttPart")) {
} else if (STRCMP(object, "mqttPart")) {
mqttPartObject = object.second.data();
if (mqttPartObject[mqttPartObject.length()-1] != '/') {
mqttPartObject.append("/");
}
} else if (boost::iequals(object.first, "property")) {
} else if (STRCMP(object, "property")) {
LOG(debug) << "Property \"" << object.second.data() << "\"";
if (!object.second.empty()) {
std::string name = device.second.data() + "_" + d.second.data() + "_" + object.second.data();
......@@ -139,18 +133,12 @@ void BACnetConfigurator::derivedReReadConfig() {
bool BACnetConfigurator::derivedReadSensor(BACnetSensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (STRCMP(val, "mqttsuffix")) {
sensor.setMqtt(sensor.getMqtt() + val.second.data());
} else if (boost::iequals(val.first, ("factor"))) {
} else if (STRCMP(val, "factor")) {
sensor.setFactor(std::stod(val.second.data()));
} else if (boost::iequals(val.first, ("id"))) {
} else if (STRCMP(val, "id")) {
sensor.setPropertyId(static_cast<BACNET_PROPERTY_ID>(stoul(val.second.data())));
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
......
......@@ -22,23 +22,17 @@ IPMIConfigurator::~IPMIConfigurator() {}
bool IPMIConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read global variables (if present overwrite those from global.conf)
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "SessionTimeout")) {
if (STRCMP(global, "SessionTimeout")) {
_globalHost.sessionTimeout = stoi(global.second.data());
LOG(debug)<< " SessionTimeout " << _globalHost.sessionTimeout;
} else if (boost::iequals(global.first, "RetransmissionTimeout")) {
} else if (STRCMP(global, "RetransmissionTimeout")) {
_globalHost.retransmissionTimeout = stoi(global.second.data());
LOG(debug) << " RetransmissionTimeout " << _globalHost.retransmissionTimeout;
} else if (boost::iequals(global.first, "mqttprefix")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(global.first, "cacheInterval")) {
//avoid unnecessary "Value not recognized" messages
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
}
BOOST_FOREACH(boost::property_tree::iptree::value_type &host, cfg.get_child("hosts")) {
if (boost::iequals(host.first, ("host"))) {
if (STRCMP(host, "host")) {
LOG(debug)<< "Host " << host.second.data();
_hosts.push_back(DCDB::IPMIHost(host.second.data(), _globalHost.retransmissionTimeout, _globalHost.sessionTimeout));
DCDB::IPMIHost &ipmiHost = _hosts.back();
......@@ -46,16 +40,16 @@ bool IPMIConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
ipmiHost.setCache(_tempdir);
if (!host.second.empty()) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &h, host.second) {
if (boost::iequals(h.first, "username")) {
if (STRCMP(h, "username")) {
ipmiHost.setUserName(h.second.data());
LOG(debug) << " Username " << ipmiHost.getUserName();
} else if (boost::iequals(h.first, "password")) {
} else if (STRCMP(h, "password")) {
ipmiHost.setPassword(h.second.data());
LOG(debug) << " Password " << ipmiHost.getPassword();
} else if (boost::iequals(h.first, "mqttprefix")) {
} else if (STRCMP(h, "mqttprefix")) {
ipmiHost.setMqttPrefix(h.second.data());
LOG(debug) << " MQTTPrefix " << ipmiHost.getMqttPrefix();
} else if (boost::iequals(h.first, "sensors")) {
} else if (STRCMP(h, "sensors")) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, h.second) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
......@@ -96,11 +90,7 @@ bool IPMIConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
bool IPMIConfigurator::derivedReadSensor(DCDB::IPMISensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (STRCMP(val, "mqttsuffix")) {
if (sensor.getHost() != NULL) {
// only workaround so that every host can define own prefix
// not guaranteed, but should actually work as long as prefix is defined before the sensors within a host
......@@ -110,18 +100,16 @@ bool IPMIConfigurator::derivedReadSensor(DCDB::IPMISensor& sensor, boost::proper
} else {
sensor.setMqtt(_mqttPrefix + val.second.data());
}
} else if (boost::iequals(val.first, ("cmd"))) {
} else if (STRCMP(val, "cmd")) {
sensor.setRawCmd(val.second.data());
} else if (boost::iequals(val.first, "start")) {
} else if (STRCMP(val, "start")) {
sensor.setStart(stoi(val.second.data()));
} else if (boost::iequals(val.first, "stop")) {
} else if (STRCMP(val, "stop")) {
sensor.setStop(stoi(val.second.data()));
} else if (boost::iequals(val.first, ("recordId"))) {
} else if (STRCMP(val, "recordId")) {
sensor.setRecordId(stoul(val.second.data()));
} else if (boost::iequals(val.first, ("factor"))) {
} else if (STRCMP(val, "factor")) {
sensor.setFactor(std::stod(val.second.data()));
} else {
LOG(warning)<<" Value \"" << val.first << "\" not recognized. Omitting...";
}
}
......
......@@ -19,7 +19,7 @@ PDUConfigurator::~PDUConfigurator() {}
bool PDUConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read one pdu at a time
BOOST_FOREACH(boost::property_tree::iptree::value_type &pdu, cfg.get_child("pdus")) {
if (boost::iequals(pdu.first, "pdu")) {
if (STRCMP(pdu, "pdu")) {
LOG(debug) << "PDU \"" << pdu.second.data() << "\"";
if (!pdu.second.empty()) {
//create PDU at end of list
......@@ -28,10 +28,10 @@ bool PDUConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read PDU-values
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, pdu.second) {
if (boost::iequals(val.first, "TTL")) {
if (STRCMP(val, "TTL")) {
pduUnit.setTTL(stoull(val.second.data()));
LOG(debug) << " TTL " << pduUnit.getTTL();
} else if (boost::iequals(val.first, "host")) {
} else if (STRCMP(val, "host")) {
std::string host = val.second.data();
size_t pos = host.find(':');
if (pos != string::npos) {
......@@ -40,10 +40,10 @@ bool PDUConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
pduUnit.setHost(host + ":443");
}
LOG(debug) << " Host " << pduUnit.getHost();
} else if (boost::iequals(val.first, "request")) {
} else if (STRCMP(val, "request")) {
pduUnit.setRequest(val.second.data());
LOG(debug) << " Request: \n" << pduUnit.getRequest();
} else if (boost::iequals(val.first, "sensors")) {
} else if (STRCMP(val, "sensors")) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, val.second) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
......@@ -83,16 +83,10 @@ bool PDUConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
bool PDUConfigurator::derivedReadSensor(PDUSensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (STRCMP(val, "mqttsuffix")) {
sensor.setMqtt(_mqttPrefix + val.second.data());
} else if (boost::iequals(val.first, "path")) {
} else if (STRCMP(val, "path")) {
parsePathString(sensor, val.second.data());
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
......
......@@ -58,7 +58,7 @@ PerfeventConfigurator::~PerfeventConfigurator() {}
bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read cpu-lists for template sensors
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensorTemplates")) {
if (boost::iequals(sensor.first, "sensor")) {
if (STRCMP(sensor, "sensor")) {
LOG(debug) << "Reading CPUs for \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
//check if cpus-list is given for this template sensor
......@@ -73,7 +73,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
//read one sensor at a time
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensors")) {
if (boost::iequals(sensor.first, "sensor")) {
if (STRCMP(sensor, "sensor")) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
PerfCounter perfCounter(sensor.second.data());
......@@ -135,7 +135,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
//read counter groups
BOOST_FOREACH(boost::property_tree::iptree::value_type &group, cfg.get_child("groups")) {
if (boost::iequals(group.first, "group")) {
if (STRCMP(group, "group")) {
LOG(debug) << "Group \"" << group.second.data() << "\"";
if (!group.second.empty()) {
PerfCounterGroup perfGroup(group.second.data());
......@@ -160,9 +160,9 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
//read remaining values
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, group.second) {
if (boost::iequals(val.first, "interval")) {
if (STRCMP(val, "interval")) {
perfGroup.setInterval(stoull(val.second.data()));
} else if (boost::iequals(val.first, "minValues")) {
} else if (STRCMP(val, "minValues")) {
perfGroup.setMinValues(stoull(val.second.data()));
}
}
......@@ -176,7 +176,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
//read counters
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, group.second) {
if (boost::iequals(val.first, "sensor")) {
if (STRCMP(val, "sensor")) {
LOG(debug) << "Sensor \"" << val.second.data() << "\"";
PerfCounter* perfCounter = new PerfCounter(val.second.data() + std::to_string(i));
perfCounter->setInterval(perfGroup.getInterval());
......@@ -201,14 +201,9 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
bool PerfeventConfigurator::derivedReadSensor(PerfCounter& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "cpus")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (STRCMP(val, "mqttsuffix")) {
sensor.setMqtt(val.second.data());
} else if (boost::iequals(val.first, "type")) {
} else if (STRCMP(val, "type")) {
enumMap_t::iterator it = _enumType.find(val.second.data());
if(it != _enumType.end()) {
sensor.setType(it->second);
......@@ -217,7 +212,7 @@ bool PerfeventConfigurator::derivedReadSensor(PerfCounter& sensor, boost::proper
LOG(warning) << " Type \"" << val.second.data() << "\" not known.";
return false;
}
} else if (boost::iequals(val.first, "config")) {
} else if (STRCMP(val, "config")) {
if (sensor.getType() == PERF_TYPE_BREAKPOINT) {
//leave config zero
} else if (sensor.getType() == PERF_TYPE_RAW) {
......@@ -235,8 +230,6 @@ bool PerfeventConfigurator::derivedReadSensor(PerfCounter& sensor, boost::proper
return false;
}
}
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
......
......@@ -18,29 +18,29 @@ bool SNMPConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
std::string mqttPartConnection;
BOOST_FOREACH(boost::property_tree::iptree::value_type &connection, cfg.get_child("connections")) {
if (boost::iequals(connection.first, ("connection"))) {
if (STRCMP(connection, ("connection"))) {
LOG(debug) << "Connection " << connection.second.data();
_connections.push_back(SNMPConnection());
SNMPConnection &conn = _connections.back();
if (!connection.second.empty()) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &c, connection.second) {
if (boost::iequals(c.first, "Type")) {
if (STRCMP(c, "Type")) {
//TODO would be relevant if we would support more than just agent mode...
// at the moment we just ignore it, as it can be only "Agent" anyways
} else if (boost::iequals(c.first, "Host")) {
} else if (STRCMP(c, "Host")) {
conn.setHost(c.second.data());
LOG(debug) << " Host " << conn.getHost();
} else if (boost::iequals(c.first, "Port")) {
} else if (STRCMP(c, "Port")) {
conn.setPort(stoi(c.second.data()));
LOG(debug) << " Port " << conn.getPort();
} else if (boost::iequals(c.first, "Community")) {
} else if (STRCMP(c, "Community")) {
conn.setSNMPCommunity(c.second.data());
LOG(debug) << " Community " << conn.getSNMPCommunity();
} else if (boost::iequals(c.first, "OIDPrefix")) {
} else if (STRCMP(c, "OIDPrefix")) {
conn.setOIDPrefix(c.second.data());
LOG(debug) << " OID-prefix " << conn.getOIDPrefix();
} else if (boost::iequals(c.first, "Version")) {
} else if (STRCMP(c, "Version")) {
int version = stoi(c.second.data());
switch (version) {
case 1:
......@@ -59,10 +59,10 @@ bool SNMPConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
conn.setVersion(-1);
LOG(warning) << "Invalid SNMP Version " << version << "!";
}
} else if (boost::iequals(c.first, "Username")) {
} else if (STRCMP(c, "Username")) {
conn.setUsername(c.second.data());
LOG(debug) << " Username " << conn.getUsername();
} else if (boost::iequals(c.first, "SecLevel")) {
} else if (STRCMP(c, "SecLevel")) {
std::string secLvl = c.second.data();
if (boost::iequals(secLvl, "noAuthNoPriv")) {
conn.setSecurityLevel(SNMP_SEC_LEVEL_NOAUTH);
......@@ -74,7 +74,7 @@ bool SNMPConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
conn.setSecurityLevel(SNMP_SEC_LEVEL_AUTHPRIV);
LOG(debug) << " Security Level AuthPriv";
}
} else if (boost::iequals(c.first, "AuthProto")) {
} else if (STRCMP(c, "AuthProto")) {
std::string authProto = c.second.data();
if (boost::iequals(authProto, "MD5")) {
conn.setAuthProto(usmHMACMD5AuthProtocol);
......@@ -85,7 +85,7 @@ bool SNMPConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
conn.setAuthProtoLen(USM_AUTH_PROTO_SHA_LEN);
LOG(debug) << " Authentication protocol SHA1";
}
} else if (boost::iequals(c.first, "PrivProto")) {
} else if (STRCMP(c, "PrivProto")) {
std::string privProto = c.second.data();
if (boost::iequals(privProto, "DES")) {
conn.setPrivProto(snmp_duplicate_objid(usmDESPrivProtocol, USM_PRIV_PROTO_DES_LEN));
......@@ -96,19 +96,19 @@ bool SNMPConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
conn.setPrivProtoLen(USM_PRIV_PROTO_AES_LEN);
LOG(debug) << " Privacy protocol AES";
}
} else if (boost::iequals(c.first, "AuthKey")) {
} else if (STRCMP(c, "AuthKey")) {
conn.setAuthKey(c.second.data());
LOG(debug) << " Authkey " << conn.getAuthKey();
} else if (boost::iequals(c.first, "PrivKey")) {
} else if (STRCMP(c, "PrivKey")) {
conn.setPrivKey(c.second.data());
LOG(debug) << " Privkey " << conn.getPrivKey();
} else if (boost::iequals(c.first, "mqttPart")) {
} else if (STRCMP(c, "mqttPart")) {
mqttPartConnection = c.second.data();
if (mqttPartConnection[mqttPartConnection.length()-1] != '/') {
mqttPartConnection.append("/");
}
LOG(debug) << " MQTTPart " << mqttPartConnection;
} else if (boost::iequals(c.first, "sensor")) {
} else if (STRCMP(c, "sensor")) {
LOG(debug) << "Sensor \"" << c.second.data() << "\"";
if (!c.second.empty()) {
std::string name = connection.second.data() + "_" + c.second.data();
......@@ -148,16 +148,10 @@ bool SNMPConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
bool SNMPConfigurator::derivedReadSensor(SNMPSensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (STRCMP(val, "mqttsuffix")) {
sensor.setMqtt(sensor.getMqtt() + val.second.data());
} else if (boost::iequals(val.first, "OID")) {
} else if (STRCMP(val, "OID")) {
sensor.setOID(sensor.getConnection()->getOIDPrefix() + "." + val.second.data());
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
......
......@@ -18,7 +18,7 @@ SysfsConfigurator::~SysfsConfigurator() {}
bool SysfsConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read one sensor at a time
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensors")) {
if (boost::iequals(sensor.first, "sensor")) {
if (STRCMP(sensor, "sensor")) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
SysfsSensor* sysfsSensor = new SysfsSensor(sensor.second.data());
......@@ -49,15 +49,11 @@ bool SysfsConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
bool SysfsConfigurator::derivedReadSensor(SysfsSensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (STRCMP(val, "mqttsuffix")) {
sensor.setMqtt(_mqttPrefix + val.second.data());
} else if (boost::iequals(val.first, ("path"))) {
} else if (STRCMP(val, ("path"))) {
sensor.setPath(val.second.data());
} else if (boost::iequals(val.first, "filter")) {
} else if (STRCMP(val, "filter")) {
sensor.setFilter(true);
string input = val.second.data();
......@@ -77,8 +73,6 @@ bool SysfsConfigurator::derivedReadSensor(SysfsSensor& sensor, boost::property_t
sensor.setRegex(regex(input, regex_constants::extended));
sensor.setSubstitution("&");
}
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
......
Markdown is supported
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