]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/snmp-agent.hh
Merge pull request #14195 from rgacogne/ddist-no-assertions
[thirdparty/pdns.git] / pdns / snmp-agent.hh
1 #pragma once
2 #include "config.h"
3
4 #include <string>
5 #include <thread>
6 #include <unistd.h>
7
8 #ifdef HAVE_NET_SNMP
9 #include <net-snmp/net-snmp-config.h>
10 #include <net-snmp/definitions.h>
11 #include <net-snmp/types.h>
12 #include <net-snmp/utilities.h>
13 #include <net-snmp/config_api.h>
14 #include <net-snmp/agent/net-snmp-agent-includes.h>
15 #undef INET6 /* SRSLY? */
16 #endif /* HAVE_NET_SNMP */
17
18 #include "mplexer.hh"
19 #include "channel.hh"
20
21 class SNMPAgent
22 {
23 public:
24 SNMPAgent(const std::string& name, const std::string& daemonSocket);
25 virtual ~SNMPAgent()
26 {
27 }
28
29 void run()
30 {
31 #ifdef HAVE_NET_SNMP
32 d_thread = std::thread(&SNMPAgent::worker, this);
33 d_thread.detach();
34 #endif /* HAVE_NET_SNMP */
35 }
36
37 #ifdef HAVE_NET_SNMP
38 static int setCounter64Value(netsnmp_request_info* request,
39 uint64_t value);
40 #endif /* HAVE_NET_SNMP */
41 protected:
42 #ifdef HAVE_NET_SNMP
43 /* OID for snmpTrapOID.0 */
44 static const std::array<oid, 11> snmpTrapOID;
45
46 static bool sendTrap(pdns::channel::Sender<netsnmp_variable_list, void(*)(netsnmp_variable_list*)>& sender,
47 netsnmp_variable_list* varList);
48
49 pdns::channel::Sender<netsnmp_variable_list, void(*)(netsnmp_variable_list*)> d_sender;
50 pdns::channel::Receiver<netsnmp_variable_list, void(*)(netsnmp_variable_list*)> d_receiver;
51 #endif /* HAVE_NET_SNMP */
52 private:
53 void worker();
54 static void handleTrapsCB(int fd, FDMultiplexer::funcparam_t& var);
55 static void handleSNMPQueryCB(int fd, FDMultiplexer::funcparam_t& var);
56 void handleTrapsEvent();
57 void handleSNMPQueryEvent(int fd);
58
59 std::thread d_thread;
60 };