]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/snmp-agent.hh
dnsdist: Add HTTPStatusAction to return a specific HTTP response
[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 #include "mplexer.hh"
21
22 class SNMPAgent
23 {
24 public:
25 SNMPAgent(const std::string& name, const std::string& masterSocket);
26 virtual ~SNMPAgent()
27 {
28 #ifdef HAVE_NET_SNMP
29 close(d_trapPipe[0]);
30 close(d_trapPipe[1]);
31 #endif /* HAVE_NET_SNMP */
32 }
33
34 void run()
35 {
36 #ifdef HAVE_NET_SNMP
37 d_thread = std::thread(&SNMPAgent::worker, this);
38 #endif /* HAVE_NET_SNMP */
39 }
40
41 #ifdef HAVE_NET_SNMP
42 static int setCounter64Value(netsnmp_request_info* request,
43 uint64_t value);
44 #endif /* HAVE_NET_SNMP */
45 protected:
46 #ifdef HAVE_NET_SNMP
47 /* OID for snmpTrapOID.0 */
48 static const oid snmpTrapOID[];
49 static const size_t snmpTrapOIDLen;
50
51 static bool sendTrap(int fd,
52 netsnmp_variable_list* varList);
53
54 int d_trapPipe[2] = { -1, -1};
55 #endif /* HAVE_NET_SNMP */
56 private:
57 void worker();
58 static void handleTrapsCB(int fd, FDMultiplexer::funcparam_t& var);
59 static void handleSNMPQueryCB(int fd, FDMultiplexer::funcparam_t& var);
60 void handleTrapsEvent();
61 void handleSNMPQueryEvent(int fd);
62
63 std::thread d_thread;
64 };
65
66 #endif /* SNMP_AGENT_HH */