]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/snmp-agent.hh
Merge pull request #4692 from cmouse/ssql-unique-ptr
[thirdparty/pdns.git] / pdns / snmp-agent.hh
1 #ifndef SNMP_AGENT_HH
2 #define SNMP_AGENT_HH
3
4 #include "config.h"
5
6 #include <string>
7 #include <thread>
8 #include <unistd.h>
9
10 #ifdef HAVE_NET_SNMP
11 #include <net-snmp/net-snmp-config.h>
12 #include <net-snmp/definitions.h>
13 #include <net-snmp/types.h>
14 #include <net-snmp/utilities.h>
15 #include <net-snmp/config_api.h>
16 #include <net-snmp/agent/net-snmp-agent-includes.h>
17 #undef INET6 /* SRSLY? */
18 #endif /* HAVE_NET_SNMP */
19
20 class SNMPAgent
21 {
22 public:
23 SNMPAgent(const std::string& name, const std::string& masterSocket);
24 virtual ~SNMPAgent()
25 {
26 #ifdef HAVE_NET_SNMP
27 close(d_trapPipe[0]);
28 close(d_trapPipe[1]);
29 #endif /* HAVE_NET_SNMP */
30 }
31
32 void run()
33 {
34 #ifdef HAVE_NET_SNMP
35 d_thread = std::thread(&SNMPAgent::worker, this);
36 #endif /* HAVE_NET_SNMP */
37 }
38
39 #ifdef HAVE_NET_SNMP
40 static int setCounter64Value(netsnmp_request_info* request,
41 uint64_t value);
42 #endif /* HAVE_NET_SNMP */
43 protected:
44 #ifdef HAVE_NET_SNMP
45 /* OID for snmpTrapOID.0 */
46 static const oid snmpTrapOID[];
47 static const size_t snmpTrapOIDLen;
48
49 static bool sendTrap(int fd,
50 netsnmp_variable_list* varList);
51
52 void handleTraps();
53
54 int d_trapPipe[2] = { -1, -1};
55 #endif /* HAVE_NET_SNMP */
56 private:
57 void worker();
58
59 std::thread d_thread;
60 };
61
62 #endif /* SNMP_AGENT_HH */