]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/snmp-agent.hh
Merge pull request #9073 from pieterlexis/runtime-dirs-virtual-hosting
[thirdparty/pdns.git] / pdns / snmp-agent.hh
CommitLineData
e8c59f2d 1#pragma once
9f4eb5cc
RG
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>
aa731909
RG
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>
9f4eb5cc
RG
14#include <net-snmp/agent/net-snmp-agent-includes.h>
15#undef INET6 /* SRSLY? */
16#endif /* HAVE_NET_SNMP */
17
0e663c3b
RG
18#include "mplexer.hh"
19
9f4eb5cc
RG
20class SNMPAgent
21{
22public:
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
06815c91 35 d_thread = std::thread(&SNMPAgent::worker, this);
9f4eb5cc
RG
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 */
43protected:
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
9f4eb5cc
RG
52 int d_trapPipe[2] = { -1, -1};
53#endif /* HAVE_NET_SNMP */
54private:
55 void worker();
0e663c3b
RG
56 static void handleTrapsCB(int fd, FDMultiplexer::funcparam_t& var);
57 static void handleSNMPQueryCB(int fd, FDMultiplexer::funcparam_t& var);
58 void handleTrapsEvent();
59 void handleSNMPQueryEvent(int fd);
9f4eb5cc
RG
60
61 std::thread d_thread;
62};