#pragma once #include "config.h" #include #include #include #ifdef HAVE_NET_SNMP #include #include #include #include #include #include #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; };