summaryrefslogtreecommitdiffstats
path: root/snmp-agent.hh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:34:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:34:30 +0000
commit4fc2f55f761d71aae1f145d5aa94ba929cc39676 (patch)
tree5c1e1db3b46dd4edbe11f612d93cb94b96891ce3 /snmp-agent.hh
parentInitial commit. (diff)
downloaddnsdist-4fc2f55f761d71aae1f145d5aa94ba929cc39676.tar.xz
dnsdist-4fc2f55f761d71aae1f145d5aa94ba929cc39676.zip
Adding upstream version 1.7.3.upstream/1.7.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'snmp-agent.hh')
-rw-r--r--snmp-agent.hh64
1 files changed, 64 insertions, 0 deletions
diff --git a/snmp-agent.hh b/snmp-agent.hh
new file mode 100644
index 0000000..e4ba134
--- /dev/null
+++ b/snmp-agent.hh
@@ -0,0 +1,64 @@
+#pragma once
+#include "config.h"
+
+#include <string>
+#include <thread>
+#include <unistd.h>
+
+#ifdef HAVE_NET_SNMP
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+#endif /* HAVE_NET_SNMP */
+
+#include "mplexer.hh"
+
+class SNMPAgent
+{
+public:
+ SNMPAgent(const std::string& name, const std::string& daemonSocket);
+ virtual ~SNMPAgent()
+ {
+#ifdef HAVE_NET_SNMP
+
+ close(d_trapPipe[0]);
+ close(d_trapPipe[1]);
+#endif /* HAVE_NET_SNMP */
+ }
+
+ void run()
+ {
+#ifdef HAVE_NET_SNMP
+ d_thread = std::thread(&SNMPAgent::worker, this);
+ d_thread.detach();
+#endif /* HAVE_NET_SNMP */
+ }
+
+#ifdef HAVE_NET_SNMP
+ static int setCounter64Value(netsnmp_request_info* request,
+ uint64_t value);
+#endif /* HAVE_NET_SNMP */
+protected:
+#ifdef HAVE_NET_SNMP
+ /* OID for snmpTrapOID.0 */
+ static const oid snmpTrapOID[];
+ static const size_t snmpTrapOIDLen;
+
+ static bool sendTrap(int fd,
+ netsnmp_variable_list* varList);
+
+ int d_trapPipe[2] = { -1, -1};
+#endif /* HAVE_NET_SNMP */
+private:
+ void worker();
+ static void handleTrapsCB(int fd, FDMultiplexer::funcparam_t& var);
+ static void handleSNMPQueryCB(int fd, FDMultiplexer::funcparam_t& var);
+ void handleTrapsEvent();
+ void handleSNMPQueryEvent(int fd);
+
+ std::thread d_thread;
+};