Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
6eacc129
Commit
6eacc129
authored
Jul 05, 2018
by
Micha Mueller
Browse files
Add code skeleton for upcoming SNMP plugin
parent
2e77b9be
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/sensors/snmp/SNMPConfigurator.cpp
0 → 100644
View file @
6eacc129
/*
* SNMPConfigurator.cpp
*
* Created on: 05.07.2018
* Author: Axel Auweter (original), Micha Mueller
*/
#include
"SNMPConfigurator.h"
#include
<boost/foreach.hpp>
#include
<boost/property_tree/info_parser.hpp>
SNMPConfigurator
::
SNMPConfigurator
()
{
// TODO Auto-generated constructor stub
}
SNMPConfigurator
::~
SNMPConfigurator
()
{
// TODO Auto-generated destructor stub
}
bool
SNMPConfigurator
::
readConfig
(
std
::
string
cfgPath
)
{
//TODO
return
true
;
}
bool
SNMPConfigurator
::
readSensor
(
SNMPSensor
&
sensor
,
boost
::
property_tree
::
iptree
&
config
)
{
//TODO
return
true
;
}
src/sensors/snmp/SNMPConfigurator.h
0 → 100644
View file @
6eacc129
/*
* SNMPConfigurator.h
*
* Created on: 05.07.2018
* Author: Axel Auweter (original), Micha Mueller
*/
#ifndef SNMPCONFIGURATOR_H_
#define SNMPCONFIGURATOR_H_
#include
"../../Configurator.h"
#include
"SNMPSensor.h"
#include
"SNMPConnection.h"
#include
<string>
#include
<vector>
#include
<map>
#include
<boost/property_tree/ptree.hpp>
class
SNMPConfigurator
:
public
Configurator
{
typedef
std
::
map
<
std
::
string
,
SNMPSensor
>
sensorMap_t
;
public:
SNMPConfigurator
();
virtual
~
SNMPConfigurator
();
/**
* Read in the configuration for snmp-connections and sensors.
* @param cfgPath Path + name of the config-file
* @return true on success, false otherwise
*/
bool
readConfig
(
std
::
string
cfgPath
);
//Overwrite from Configurator
bool
reReadConfig
()
{
//TODO
_templateSensors
.
clear
();
return
Configurator
::
reReadConfig
();
}
private:
/**
* Set the variables of sensor according to the values specified in config.
* @param sensor The sensor to be configured
* @param config A property(sub)tree containing the values
*/
bool
readSensor
(
SNMPSensor
&
sensor
,
boost
::
property_tree
::
iptree
&
config
);
sensorMap_t
_templateSensors
;
};
extern
"C"
Configurator
*
create
()
{
return
new
SNMPConfigurator
;
}
extern
"C"
void
destroy
(
Configurator
*
c
)
{
delete
c
;
}
#endif
/* SNMPCONFIGURATOR_H_ */
src/sensors/snmp/SNMPConnection.cpp
0 → 100644
View file @
6eacc129
/*
* SNMPConnection.cpp
*
* Created on: 05.07.2018
* Author: Axel Auweter (original), Micha Mueller
*/
#include
"SNMPConnection.h"
SNMPConnection
::
SNMPConnection
()
{
// TODO Auto-generated constructor stub
}
SNMPConnection
::~
SNMPConnection
()
{
// TODO Auto-generated destructor stub
}
void
SNMPConnection
::
initializeStrand
(
boost
::
asio
::
io_service
&
io
)
{
if
(
!
_strand
)
{
_strand
=
new
boost
::
asio
::
io_service
::
strand
(
io
);
}
}
src/sensors/snmp/SNMPConnection.h
0 → 100644
View file @
6eacc129
/*
* SNMPConnection.h
*
* Created on: 05.07.2018
* Author: Axel Auweter (original), Micha Mueller
*/
#ifndef SNMPCONNECTION_H_
#define SNMPCONNECTION_H_
#include
"../../Logging.h"
#include
<net-snmp/net-snmp-config.h>
#include
<net-snmp/net-snmp-includes.h>
class
SNMPConnection
{
public:
SNMPConnection
();
virtual
~
SNMPConnection
();
void
initializeStrand
(
boost
::
asio
::
io_service
&
io
);
boost
::
asio
::
io_service
::
strand
*
getStrand
()
const
{
return
_strand
;
}
private:
boost
::
asio
::
io_service
::
strand
*
_strand
;
boost
::
log
::
sources
::
severity_logger
<
boost
::
log
::
trivial
::
severity_level
>
lg
;
};
#endif
/* SNMPCONNECTION_H_ */
src/sensors/snmp/SNMPSensor.cpp
0 → 100644
View file @
6eacc129
/*
* SNMPSensor.cpp
*
* Created on: 05.07.2018
* Author: Axel Auweter (original), Micha Mueller
*/
#include
"SNMPSensor.h"
#include
"timestamp.h"
SNMPSensor
::
SNMPSensor
(
const
std
::
string
&
name
)
:
Sensor
(
name
)
{
// TODO Auto-generated constructor stub
_connection
=
NULL
;
}
SNMPSensor
::~
SNMPSensor
()
{
// TODO Auto-generated destructor stub
}
void
SNMPSensor
::
read
()
{
reading_t
reading
;
char
buf
[
1024
];
reading
.
timestamp
=
getTimestamp
();
//TODO
#ifdef DEBUG
LOG
(
debug
)
<<
_name
<<
":
\"
"
<<
reading
.
value
<<
"
\"
"
;
#endif
}
storeReading
(
reading
);
}
void
SNMPSensor
::
readAsync
()
{
uint64_t
now
=
getTimestamp
();
read
();
if
(
_timer
!=
NULL
&&
_keepRunning
)
{
uint64_t
next
=
now
+
MS_TO_NS
(
_interval
);
_timer
->
expires_at
(
timestamp2ptime
(
next
));
_timer
->
async_wait
(
_connection
->
getStrand
()
->
wrap
(
std
::
bind
(
&
SNMPSensor
::
readAsync
,
this
)));
}
}
void
SNMPSensor
::
init
(
boost
::
asio
::
io_service
&
io
)
{
if
(
_connection
)
{
_connection
->
initializeStrand
(
io
);
}
else
{
LOG
(
error
)
<<
"No host set for sensor "
<<
_name
<<
"! Cannot initialize sensor."
;
}
Sensor
::
init
(
io
);
}
void
SNMPSensor
::
startPolling
()
{
if
(
_keepRunning
)
{
//we have been started already
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" already running."
;
return
;
}
//TODO
if
(
_connection
)
{
_keepRunning
=
1
;
_timer
->
async_wait
(
_connection
->
getStrand
()
->
wrap
(
std
::
bind
(
&
SNMPSensor
::
readAsync
,
this
)));
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" started."
;
}
else
{
LOG
(
error
)
<<
"No connection set for sensor "
<<
_name
<<
"! Cannot start polling."
;
return
;
}
}
void
SNMPSensor
::
stopPolling
()
{
_keepRunning
=
0
;
//cancel any outstanding readAsync()
_timer
->
cancel
();
//wait until read() finished before closing _file
_timer
->
wait
();
//TODO
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" stopped."
;
}
src/sensors/snmp/SNMPSensor.h
0 → 100644
View file @
6eacc129
/*
* SNMPSensor.h
*
* Created on: 05.07.2018
* Author: Axel Auweter (original), Micha Mueller
*/
#ifndef SNMPSENSOR_H_
#define SNMPSENSOR_H_
#include
"../../Sensor.h"
#include
<net-snmp/net-snmp-config.h>
#include
<net-snmp/net-snmp-includes.h>
class
SNMPSensor
:
public
Sensor
{
public:
SNMPSensor
(
const
std
::
string
&
name
);
virtual
~
SNMPSensor
();
void
init
(
boost
::
asio
::
io_service
&
io
);
void
read
();
void
readAsync
();
void
startPolling
();
void
stopPolling
();
private:
oid
_oidName
[
MAX_OID_LEN
];
size_t
_oidNameLen
;
SNMPConnection
*
_connection
;
};
#endif
/* SNMPSENSOR_H_ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment