Commit 15b8d98d authored by Carla Guillen Carias's avatar Carla Guillen Carias
Browse files

starting plugin gpfsmon

parent 755c388c
......@@ -18,6 +18,8 @@ LIBS = -L../deps/mosquitto_build/lib -L$(DCDBDEPLOYPATH)/lib/ -ldl -lmosquitto -
OBJS = src/dcdbpusher.o src/Configuration.o src/MQTTPusher.o src/HttpsServer.o
PLUGINS = procfs pdu sysfs ipmi bacnet snmp
#gpfsmon
ifeq ($(OS),Darwin)
BACNET_PORT = bsd
LIBEXT = dylib
......@@ -96,5 +98,9 @@ libdcdbplugin_snmp.$(LIBEXT): src/sensors/snmp/SNMPSensorGroup.o src/sensors/snm
libdcdbplugin_procfs.$(LIBEXT): src/sensors/procfs/ProcfsSensorGroup.o src/sensors/procfs/ProcfsParser.o src/sensors/procfs/ProcfsConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lboost_regex
#libdcdbplugin_gpfsmon.$(LIBEXT): src/sensors/gpfsmon/gpfsmonSensorGroup.o src/sensors/gpfsmon/gpfsmonConfigurator.o
# $(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
#libdcdbplugin_opa.$(LIBEXT): src/sensors/opa/OpaSensorGroup.o src/sensors/opa/OpaConfigurator.o
# $(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lopamgt -libverbs -libumad -lssl
;comments in config files are indicated by a semicolon
global {
mqttPrefix /FF112233445566778899AABBFFFF
;add here other global attributes for your plugin
}
template_group def1 {
;define template groups by appending "template_"
interval 1000
minValues 3
groupAtt 1234
;add other attributes your plugin requires for a sensor group
;define sensors belonging to the group below
sensor temp1 {
sensorAtt 5678
;add other attributes your plugin requires for a sensor
}
}
single_sensor sens1 {
;if you want a group with only one sensor you can use a single_sensor
default temp1
mqttsuffix 0001
;add other attributes your plugin requires for a sensor
}
group g1 {
interval 1000
mqttprefix 01
default def1
;sensor temp1 is took over from def1 and does not need to be redefined
sensor gSens {
mqttsuffix 00
}
}
/*
* gpfsmonConfigurator.cpp
*
* Created on: 26.11.2018
* Author: Your name goes here!
*/
#include "gpfsmonConfigurator.h"
gpfsmonConfigurator::gpfsmonConfigurator() {
/*
* TODO
* If you want sensor, group or entity to be named differently in the config file, you can change it here
*/
_groupName = "group";
_baseName = "sensor";
}
gpfsmonConfigurator::~gpfsmonConfigurator() {}
void gpfsmonConfigurator::sensorBase(gpfsmonSensorBase& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for sensorBase attributes
*/
//ATTRIBUTE("attributeName", attributeSetter);
}
}
void gpfsmonConfigurator::sensorGroup(gpfsmonSensorGroup& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for sensorGroup attributes
*/
}
}
/*
* gpfsmonConfigurator.h
*
* Created on: 26.11.2018
* Author: Your name goes here!
*/
#ifndef GPFSMON_GPFSMONCONFIGURATOR_H_
#define GPFSMON_GPFSMONCONFIGURATOR_H_
#include "../../includes/ConfiguratorTemplate.h"
#include "gpfsmonSensorGroup.h"
class gpfsmonConfigurator : public ConfiguratorTemplate<gpfsmonSensorBase, gpfsmonSensorGroup> {
public:
gpfsmonConfigurator();
virtual ~gpfsmonConfigurator();
protected:
/* Overwritten from ConfiguratorTemplate */
void sensorBase(gpfsmonSensorBase& s, CFG_VAL config) override;
void sensorGroup(gpfsmonSensorGroup& s, CFG_VAL config) override;
};
extern "C" ConfiguratorInterface* create() {
return new gpfsmonConfigurator;
}
extern "C" void destroy(ConfiguratorInterface* c) {
delete c;
}
#endif /* GPFSMON_GPFSMONCONFIGURATOR_H_ */
/*
* gpfsmonSensorBase.h
*
* Created on: 26.11.2018
* Author: Your name goes here!
*/
#ifndef GPFSMON_GPFSMONSENSORBASE_H_
#define GPFSMON_GPFSMONSENSORBASE_H_
#include "../../includes/SensorBase.h"
/*
* TODO
* Add plugin specific includes
*/
class gpfsmonSensorBase : public SensorBase {
public:
gpfsmonSensorBase(const std::string& name) :
SensorBase(name) {
/*
* TODO
* Initialize plugin specific attributes
*/
}
virtual ~gpfsmonSensorBase() {
/*
* TODO
* If necessary, deconstruct plugin specific attributes
*/
}
/*
* TODO
* Getters and Setters for plugin specific attributes
*/
protected:
/*
* TODO
* Add plugin specific attributes here
*/
};
#endif /* GPFSMON_GPFSMONSENSORBASE_H_ */
/*
* gpfsmonSensorGroup.cpp
*
* Created on: 26.11.2018
* Author: Your name goes here!
*/
#include "gpfsmonSensorGroup.h"
#include "timestamp.h"
gpfsmonSensorGroup::gpfsmonSensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
/*
* TODO
* Init attributes
*/
}
gpfsmonSensorGroup::~gpfsmonSensorGroup() {
/*
* TODO
* Tear down attributes
*/
}
void gpfsmonSensorGroup::start() {
if (_keepRunning) {
//we have been started already
LOG(info) << "Sensorgroup " << _groupName << " already running.";
return;
}
/*
* TODO
* Start plugin specific stuff
*/
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&gpfsmonSensorGroup::readAsync, this));
LOG(info) << "Sensorgroup " << _groupName << " started.";
}
void gpfsmonSensorGroup::stop() {
_keepRunning = 0;
/*
* TODO
* Stop plugin specific stuff
*/
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
void gpfsmonSensorGroup::read() {
reading_t reading;
reading.timestamp = getTimestamp();
try {
for(auto s : _sensors) {
reading.value = /*
* TODO
* Read a value for every sensor affiliated with this group and store
* it with the appropriate sensor.
*/ 0;
s->storeReading(reading, _cacheSize);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
}
} catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
}
}
void gpfsmonSensorGroup::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next));
_pendingTasks++;
_timer->async_wait(std::bind(&gpfsmonSensorGroup::readAsync, this));
}
_pendingTasks--;
}
/*
* gpfsmonSensorGroup.h
*
* Created on: 26.11.2018
* Author: Your name goes here!
*/
#ifndef GPFSMON_GPFSMONSENSORGROUP_H_
#define GPFSMON_GPFSMONSENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "gpfsmonSensorBase.h"
class gpfsmonSensorGroup : public SensorGroupTemplate<gpfsmonSensorBase> {
public:
gpfsmonSensorGroup(const std::string& name);
virtual ~gpfsmonSensorGroup();
void init(boost::asio::io_service& io) override;
void start() override;
void stop() override;
/*
* TODO
* Add getter and setters for group attributes if required
*/
private:
void read() override;
void readAsync() override;
/*
* TODO
* Add group internal attributes
*/
};
#endif /* GPFSMON_GPFSMONSENSORGROUP_H_ */
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