Commit fbb2bf9e authored by Micha Mueller's avatar Micha Mueller
Browse files

Minor improvements: replace cout by proper logging where not yet done

parent eee0a51f
......@@ -204,8 +204,8 @@ bool Configuration::readSensorVals(Sensor& sensor, boost::property_tree::iptree&
}
}
cout << " Interval : " << sensor.getInterval() << endl;
cout << " minValues: " << sensor.getMinValues() << endl;
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
return true;
}*/
......
......@@ -34,26 +34,30 @@ std::vector<Sensor*>& IPMIConfigurator::readConfig(std::string cfgPath) {
//read global variables (if present overwrite those from global.conf)
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
std::cout << global.first << " " << global.second.data() << std::endl;
if (boost::iequals(global.first, "SessionTimeout")) {
_globalHost.sessionTimeout = stoi(global.second.data());
LOG(debug) << " SessionTimeout " << _globalHost.sessionTimeout;
} else if (boost::iequals(global.first, "RetransmissionTimeout")) {
_globalHost.retransmissionTimeout = stoi(global.second.data());
LOG(debug) << " RetransmissionTimeout " << _globalHost.retransmissionTimeout;
} else if (boost::iequals(global.first, "mqttprefix")) {
_mqttPrefix = global.second.data();
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
}
//read template sensors
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("templateSensors")) {
if (boost::iequals(sensor.first, "sensor")) {
std::cout << "Template Sensor \"" << sensor.second.data() << "\"" << std::endl;
LOG(debug) << "Template Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
DCDB::IPMISensor ipmiSensor(sensor.second.data());
if(readSensor(ipmiSensor, sensor.second)) {
_templateSensors.insert(sensorMap_t::value_type(ipmiSensor.getName(), ipmiSensor));
} else {
std::cout << "Template sensor \"" << sensor.second.data() << "\" has bad values! Ignoring..." << std::endl;
LOG(warning) << "Template sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
}
}
}
......@@ -61,36 +65,38 @@ std::vector<Sensor*>& IPMIConfigurator::readConfig(std::string cfgPath) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &host, cfg.get_child("hosts")) {
if (boost::iequals(host.first, ("host"))) {
std::cout << "Host " << host.second.data() << std::endl;
LOG(debug) << "Host " << host.second.data();
_hosts.push_back(DCDB::IPMIHost(host.second.data(), _globalHost.retransmissionTimeout, _globalHost.sessionTimeout));
DCDB::IPMIHost &ipmiHost = _hosts.back();
ipmiHost.setMqttPrefix(_mqttPrefix);
if (!host.second.empty()) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &h, host.second) {
std::cout << " " << h.first << " " << h.second.data() << std::endl;
if (boost::iequals(h.first, "username")) {
ipmiHost.setUserName(h.second.data());
LOG(debug) << " Username " << ipmiHost.getUserName();
} else if (boost::iequals(h.first, "password")) {
ipmiHost.setPassword(h.second.data());
LOG(debug) << " Password " << ipmiHost.getPassword();
} else if (boost::iequals(h.first, "mqttprefix")) {
ipmiHost.setMqttPrefix(h.second.data());
LOG(debug) << " MQTTPrefix " << ipmiHost.getMqttPrefix();
} else if (boost::iequals(h.first, "sensors")) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, h.second) {
std::cout << "Sensor \"" << sensor.second.data() << "\"" << std::endl;
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
DCDB::IPMISensor* ipmiSensor = new DCDB::IPMISensor(sensor.second.data());
//first check if default sensor is given
boost::optional<boost::property_tree::iptree&> defaultC = sensor.second.get_child_optional("default");
if(defaultC) {
std::cout << " Using \"" << defaultC.get().data() << "\" as default." << std::endl;
LOG(debug) << " Using \"" << defaultC.get().data() << "\" as default.";
sensorMap_t::iterator it = _templateSensors.find(defaultC.get().data());
if(it != _templateSensors.end()) {
*ipmiSensor = it->second;
ipmiSensor->setName(sensor.second.data());
} else {
std::cout << " Template sensor \"" << defaultC.get().data() << "\" not found! Using standard values." << std::endl;
LOG(warning) << " Template sensor \"" << defaultC.get().data() << "\" not found! Using standard values.";
}
}
......@@ -100,7 +106,7 @@ std::vector<Sensor*>& IPMIConfigurator::readConfig(std::string cfgPath) {
if(readSensor(*ipmiSensor, sensor.second)) {
_sensors.push_back(ipmiSensor);
} else {
std::cout << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring..." << std::endl;
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring..." << std::endl;
}
}
}
......@@ -139,20 +145,19 @@ bool IPMIConfigurator::readSensor(DCDB::IPMISensor& sensor, boost::property_tree
} else if (boost::iequals(val.first, "default")) {
//avoid unnecessary "Value not recognized" message
} else {
std::cout << " Value \"" << val.first
<< "\" not recognized. Omitting..." << std::endl;
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
std::cout << " MQTTSuffix:" << sensor.getMqtt() << std::endl;
std::cout << " Interval : " << sensor.getInterval() << std::endl;
std::cout << " minValues: " << sensor.getMinValues() << std::endl;
LOG(debug) << " MQTTSuffix:" << sensor.getMqtt();
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
if (sensor.getRecordId() != 0) {
std::cout << " RecordID : " << sensor.getRecordId() << std::endl;
LOG(debug) << " RecordID : " << sensor.getRecordId();
} else {
std::cout << " Using raw command" << std::endl;
std::cout << " Start : " << unsigned(sensor.getStart()) << std::endl;
std::cout << " Stop : " << unsigned(sensor.getStop()) << std::endl;
LOG(debug) << " Using raw command";
LOG(debug) << " Start : " << unsigned(sensor.getStart());
LOG(debug) << " Stop : " << unsigned(sensor.getStop());
}
return true;
}
......
......@@ -126,7 +126,7 @@ uint64_t IPMIHost::sendRawCmd(const std::vector<uint8_t>& rawCmd,
int i;
if (!IPMI_NET_FN_RQ_VALID(rawCmd[1])) {
std::cout << "Invalid netfn value" << std::endl;
LOG(error) << "IPMI: Invalid netfn value";
return 0;
}
......
......@@ -8,12 +8,12 @@
#ifndef IPMIHOST_H_
#define IPMIHOST_H_
#include "../../Sensor.h" //only for logging
#include <string>
#include <list>
#include <freeipmi/freeipmi.h>
#include "IPMISensor.h"
namespace DCDB {
class IPMIHost {
......@@ -69,8 +69,6 @@ namespace DCDB {
_userName = userName;
}
void addSensor(const DCDB::IPMISensor& sensor);
const std::string& getMqttPrefix() const {
return _mqttPrefix;
}
......@@ -122,6 +120,7 @@ namespace DCDB {
uint32_t _sessionTimeout;
uint32_t _retransmissionTimeout;
boost::asio::io_service::strand* _strand;
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
uint32_t _errorCount;
volatile uint64_t _delayNextReadUntil;
};
......
......@@ -48,12 +48,12 @@ namespace DCDB {
}
catch (const std::exception& e) {
#ifdef DEBUG
std::cout << prettyPrintTimestamp(reading.timestamp) << " " << _host->getHostName() << "::" << _name << " " << _host->getMqttPrefix() << _mqtt << " => " << e.what() << std::endl;
LOG(debug) << _host->getHostName() << "::" << _name << " " << _mqtt << " => " << e.what();
#endif
return;
}
#ifdef DEBUG
std::cout << prettyPrintTimestamp(reading.timestamp) << " " << _host->getHostName() << "::" << _name << " " << _host->getMqttPrefix() << _mqtt << " (" << _readingQueue->read_available() << "/" << _readingQueue->write_available() << ") => " << reading.value << std::endl;
LOG(debug) << _host->getHostName() << "::" << _name << " " << _mqtt << " (" << _readingQueue->read_available() << "/" << _readingQueue->write_available() << ") => " << reading.value;
#endif
_readingQueue->push(reading);
// }
......
......@@ -76,11 +76,13 @@ std::vector<Sensor*>& PDUConfigurator::readConfig(std::string cfgPath) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, pdu.second) {
if (boost::iequals(val.first, "TTL")) {
pduUnit.setTTL(stoull(val.second.data()));
LOG(debug) << " TTL " << pduUnit.getTTL();
} else if (boost::iequals(val.first, "host")) {
pduUnit.setHost(val.second.data() + ":443");
LOG(debug) << " Host "; //TODO
} else if (boost::iequals(val.first, "sensors")) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, val.second) {
LOG(debug) << "sensor \"" << sensor.second.data() << "\"";
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
PDUSensor* pduSensor = new PDUSensor(sensor.second.data());
......@@ -140,7 +142,7 @@ bool PDUConfigurator::readSensor(PDUSensor& sensor, boost::property_tree::iptree
}
void PDUConfigurator::parsePathString(PDUSensor& sensor, const std::string& pathString) {
cout << " Using " << pathString << " as XML search path" << endl;
LOG(debug) << " Using " << pathString << " as XML search path";
std::vector<std::string> subStrings;
......@@ -182,11 +184,9 @@ void PDUConfigurator::parsePathString(PDUSensor& sensor, const std::string& path
std::getline(attStream, attVal);
attrs.push_back(std::make_pair(attName, attVal));
#ifdef DEBUG
cout << " Attribute: " << attName << "=" << attVal << endl;
#endif
LOG(debug) << " Attribute: " << attName << "=" << attVal;
} else { //should not happen. If it does the path was malformed
cout << " Could not parse XML-path!" << endl;
LOG(error) << " Could not parse XML-path!";
return;
}
}
......@@ -196,23 +196,17 @@ void PDUConfigurator::parsePathString(PDUSensor& sensor, const std::string& path
std::string subPathChild(subPath.substr(++index));
subPath.erase(--index);
sensor._xmlPath.push_back(std::make_tuple(subPath, subPathChild, attrs));
#ifdef DEBUG
cout << " Subpath: " << subPath << " ; Child: " << subPathChild << endl;
#endif
LOG(debug) << " Subpath: " << subPath << " ; Child: " << subPathChild;
} else {//the path contained only one node
sensor._xmlPath.push_back(std::make_tuple("", subPath, attrs));
#ifdef DEBUG
cout << " Child: " << subPath << endl;
#endif
LOG(debug) << " Child: " << subPath;
}
} else { //no attributes specified. Last (sub)path
if (subStr.front() == '.') {
subStr.erase(0, 1);
}
sensor._xmlPath.push_back(std::make_tuple(subStr, "", attributesVector_t()));
#ifdef DEBUG
cout << " (Sub)path: " << subStr << endl;
#endif
LOG(debug) << " (Sub)path: " << subStr;
break;
}
}
......
......@@ -74,12 +74,12 @@ uint64_t PDUUnit::readValue(const xmlPathVector_t& xmlPath) {
if (reading == "") {
#ifdef DEBUG
std::cout << "PDU: Value not found!" << std::endl;
LOG(debug) << "PDU: Value not found!";
#endif
return 0;
}
#ifdef DEBUG
std::cout << "Read: " << reading << std::endl;
LOG(debug) << "Read: " << reading;
#endif
return stoul(reading);
}
......@@ -102,13 +102,13 @@ void PDUUnit::refresh() {
ctx = SSL_CTX_new(SSLv23_method());
if (!ctx) {
std::cerr << "OpenSSL: Could not create context: " << ERR_reason_error_string(ERR_get_error()) << std::endl;
LOG(error) << "OpenSSL: Could not create context: " << ERR_reason_error_string(ERR_get_error());
return;
}
/*
if (!SSL_CTX_load_verify_locations(ctx, "/home/micha/LRZ/dcdbOwnFork/deps/openssl-1.0.2l/certs/demo/ca-cert.pem", NULL)) {
std::cerr << "OpenSSL: Could not load certificate: " << ERR_reason_error_string(ERR_get_error()) << std::endl;
LOG(error) << "OpenSSL: Could not load certificate: " << ERR_reason_error_string(ERR_get_error());
SSL_CTX_free(ctx);
return;
}
......@@ -120,7 +120,7 @@ void PDUUnit::refresh() {
if(BIO_do_connect(bio) <= 0)
{
std::cerr << "OpenSSL: Could not connect: " << ERR_reason_error_string(ERR_get_error()) << std::endl;
LOG(error) << "OpenSSL: Could not connect: " << ERR_reason_error_string(ERR_get_error());
BIO_free_all(bio);
SSL_CTX_free(ctx);
return;
......@@ -141,7 +141,7 @@ void PDUUnit::refresh() {
// send request
if (BIO_write(bio, buf, len) <= 0) {
std::cerr << "OpenSSL: Could not send request: " << ERR_reason_error_string(ERR_get_error()) << std::endl;
LOG(error) << "OpenSSL: Could not send request: " << ERR_reason_error_string(ERR_get_error());
BIO_free_all(bio);
SSL_CTX_free(ctx);
return;
......@@ -151,7 +151,7 @@ void PDUUnit::refresh() {
// read reply
if (BIO_read(bio, buf, sizeof(buf)) <= 0) {
std::cerr << "OpenSSL: Could not read response: " << ERR_reason_error_string(ERR_get_error()) << std::endl;
LOG(error) << "OpenSSL: Could not read response: " << ERR_reason_error_string(ERR_get_error());
BIO_free_all(bio);
SSL_CTX_free(ctx);
return;
......
......@@ -203,6 +203,8 @@ bool PerfeventConfigurator::readCounter(PerfCounter& counter, boost::property_tr
return false;
}
}
} else if (boost::iequals(val.first, "cpus")) {
//avoid unncecessary "Value not recognized" message. cpus are handled in readConfig()
} else if (boost::iequals(val.first, "default")) {
//avoid unnecessary "Value not recognized" message
} else {
......@@ -253,9 +255,7 @@ std::set<int> PerfeventConfigurator::parseCpuString(const std::string& cpuString
}
}
} catch (const std::exception& e) {
#ifdef DEBUG
cout << "Could not parse values \"" << min << "-" << max << "\"" << endl;
#endif
LOG(debug) << "Could not parse values \"" << min << "-" << max << "\"";
}
} else { //single value
try {
......@@ -264,21 +264,23 @@ std::set<int> PerfeventConfigurator::parseCpuString(const std::string& cpuString
cpus.insert(val);
}
} catch (const std::exception& e) {
#ifdef DEBUG
cout << "Could not parse value \"" << s << "\"" << endl;
#endif
LOG(debug) << "Could not parse value \"" << s << "\"";
}
}
}
if (cpus.empty()) {
cout << " CPUs could not be parsed!" << endl;
LOG(warning) << " CPUs could not be parsed!";
} else {
cout << " CPUs: ";
std::stringstream sstream;
sstream << " CPUS: ";
for (auto i : cpus) {
cout << i << ", ";
sstream << i << ", ";
}
cout << endl;
std::string msg = sstream.str();
msg.pop_back();
msg.pop_back();
LOG(debug) << msg;
}
return cpus;
}
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