Commit 3f801a2e authored by Micha Mueller's avatar Micha Mueller
Browse files

Adapt SNMP plugin to new printConfig infrastructure

parent 9c92d372
......@@ -63,3 +63,16 @@ void SNMPConfigurator::finalizeGroup(SNMPSensorGroup& g) {
g.setOIDPrefix(g.getConnection()->getOIDPrefix());
g.getConnection()->init();
}
void SNMPConfigurator::printConfiguratorConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << " No other plugin specific general attributes";
LOG_VAR(ll) << " Connections:";
if (_sensorEntitys.size() != 0) {
for(auto e : _sensorEntitys) {
e->printConfig(ll);
}
} else {
LOG_VAR(ll) << " No connections present!";
}
}
......@@ -28,6 +28,8 @@ protected:
bool isEntityOfGroup(SNMPConnection& e, SNMPSensorGroup& g) override;
void setEntityForGroup(SNMPConnection& e, SNMPSensorGroup& g) override;
void finalizeGroup(SNMPSensorGroup& g) override;
void printConfiguratorConfig(LOG_LEVEL ll) override;
};
extern "C" ConfiguratorInterface* create() {
......
......@@ -179,10 +179,11 @@ int64_t SNMPConnection::issueGet(const oid* const OID, size_t OIDLen) {
return ret;
}
void SNMPConnection::printConfig() {
LOG(debug) << " Host: " << getHost();
LOG(debug) << " Port: " << getPort();
LOG(debug) << " OIDPrefix: " << getOIDPrefix();
void SNMPConnection::printConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << " Connection:";
LOG_VAR(ll) << " Host: " << getHost();
LOG_VAR(ll) << " Port: " << getPort();
LOG_VAR(ll) << " OIDPrefix: " << getOIDPrefix();
std::string version("unknown");
switch(getVersion()) {
case SNMP_VERSION_1:
......@@ -195,21 +196,21 @@ void SNMPConnection::printConfig() {
version = "3";
break;
}
LOG(debug) << " Version: " << version;
LOG_VAR(ll) << " Version: " << version;
if (getVersion() < SNMP_VERSION_3) {
LOG(debug) << " Community: " << getSNMPCommunity();
LOG_VAR(ll) << " Community: " << getSNMPCommunity();
} else {
LOG(debug) << " Username: " << getUsername();
LOG(debug) << " SecLevel: " << getSecurityLevelString();
LOG_VAR(ll) << " Username: " << getUsername();
LOG_VAR(ll) << " SecLevel: " << getSecurityLevelString();
if (_securityLevel != SNMP_SEC_LEVEL_NOAUTH) {
LOG(debug) << " AuthProto: " << getAuthProtoString();
LOG(debug) << " AuthKey: " << getAuthKey();
LOG_VAR(ll) << " AuthProto: " << getAuthProtoString();
LOG_VAR(ll) << " AuthKey: " << getAuthKey();
}
if (_securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
LOG(debug) << " PrivProto: " << getPrivProtoString();
LOG(debug) << " PrivKey: " << getPrivKey();
LOG_VAR(ll) << " PrivProto: " << getPrivProtoString();
LOG_VAR(ll)<< " PrivKey: " << getPrivKey();
}
}
LOG(debug) << " MqttPart: " << getMqttPart();
LOG_VAR(ll) << " MqttPart: " << getMqttPart();
}
......@@ -140,7 +140,7 @@ public:
long int getVersion() const { return _version; }
boost::asio::io_service::strand* getStrand() const { return _strand; }
void printConfig();
void printConfig(LOG_LEVEL ll);
/**
* Initializes the connection. Must be called once before the connection can be used
......
......@@ -13,8 +13,6 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include "../../includes/SensorBase.h"
#include "../../includes/Logging.h"
class SNMPSensorBase : public SensorBase {
public:
......@@ -69,14 +67,8 @@ public:
}
const std::string getOIDSuffix() const { return _oidSuffix; }
void printConfig() {
LOG(debug) << " Sensor " << getName() << ":";
LOG(debug) << " mqtt: " << getMqtt();
LOG(debug) << " skipConstVal: " << getSkipConstVal();
LOG(debug) << " delta: " << isDelta();
LOG(debug) << " sink: " << getSinkPath();
LOG(debug) << " subSampling: " << getSubsampling();
LOG(debug) << " OID: " << getOIDString();
void printConfig(LOG_LEVEL ll, LOGGER& lg) {
LOG_VAR(ll) << " OID: " << getOIDString();
}
......@@ -84,8 +76,6 @@ protected:
oid _oid[MAX_OID_LEN];
size_t _oidLen;
std::string _oidSuffix;
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
};
#endif /* SNMP_SNMPSENSORBASE_H_ */
......@@ -28,7 +28,6 @@ SNMPSensorGroup& SNMPSensorGroup::operator=(const SNMPSensorGroup& other) {
void SNMPSensorGroup::init(boost::asio::io_service& io) {
SensorGroupTemplate::init(io);
printConfig();
if (_connection) {
_connection->initializeStrand(io);
} else {
......@@ -59,17 +58,6 @@ void SNMPSensorGroup::stop() {
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
void SNMPSensorGroup::printConfig() {
LOG(debug) << "Sensorgroup " << _groupName << ":";
LOG(debug) << " Connection: ";
getConnection()->printConfig();
for(const auto& s : _sensors) {
s->printConfig();
}
}
void SNMPSensorGroup::read() {
reading_t reading;
reading.timestamp = getTimestamp();
......@@ -97,3 +85,11 @@ void SNMPSensorGroup::readAsync() {
}
_pendingTasks--;
}
void SNMPSensorGroup::printConfig(LOG_LEVEL ll) {
if (_connection) {
LOG_VAR(ll) << " Connection: " << _connection->getHost();
} else {
LOG_VAR(ll) << " No Connection set!";
}
}
......@@ -22,7 +22,6 @@ public:
void init(boost::asio::io_service& io) override;
void start() override;
void stop() override;
void printConfig();
void setOIDPrefix(const std::string& oidPrefix) {
for(auto s : _sensors) {
......@@ -32,6 +31,8 @@ public:
void setConnection(SNMPConnection* connection) { _connection = connection; }
SNMPConnection* const getConnection() const { return _connection; }
void printConfig(LOG_LEVEL ll) override;
private:
void read() override;
void readAsync() override;
......
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