#ifdef HAVE_NET_SNMP
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+
#define DNSDIST_OID 1, 3, 6, 1, 4, 1, 43315, 3
#define DNSDIST_STATS_OID DNSDIST_OID, 1
#define DNSDIST_STATS_TABLE_OID DNSDIST_OID, 2
const string backendStatus = dss.getStatus();
netsnmp_variable_list* varList = nullptr;
- snmp_varlist_add_variable(&varList,
- snmpTrapOID.data(),
- snmpTrapOID.size(),
- ASN_OBJECT_ID,
- backendStatusChangeTrapOID.data(),
- backendStatusChangeTrapOID.size() * sizeof(oid));
+ addSNMPTrapOID(&varList,
+ backendStatusChangeTrapOID.data(),
+ backendStatusChangeTrapOID.size() * sizeof(oid));
snmp_varlist_add_variable(&varList,
backendNameOID.data(),
#ifdef HAVE_NET_SNMP
netsnmp_variable_list* varList = nullptr;
- snmp_varlist_add_variable(&varList,
- snmpTrapOID.data(),
- snmpTrapOID.size(),
- ASN_OBJECT_ID,
- customTrapOID.data(),
- customTrapOID.size() * sizeof(oid));
+ addSNMPTrapOID(&varList,
+ customTrapOID.data(),
+ customTrapOID.size() * sizeof(oid));
snmp_varlist_add_variable(&varList,
trapReasonOID.data(),
netsnmp_variable_list* varList = nullptr;
- snmp_varlist_add_variable(&varList,
- snmpTrapOID.data(),
- snmpTrapOID.size(),
- ASN_OBJECT_ID,
- actionTrapOID.data(),
- actionTrapOID.size() * sizeof(oid));
+ addSNMPTrapOID(&varList,
+ actionTrapOID.data(),
+ actionTrapOID.size() * sizeof(oid));
snmp_varlist_add_variable(&varList,
socketFamilyOID.data(),
#ifdef HAVE_NET_SNMP
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+
#define RECURSOR_OID 1, 3, 6, 1, 4, 1, 43315, 2
#define RECURSOR_STATS_OID RECURSOR_OID, 1
#define RECURSOR_TRAPS_OID RECURSOR_OID, 10, 0
#ifdef HAVE_NET_SNMP
netsnmp_variable_list* varList = nullptr;
- snmp_varlist_add_variable(&varList,
- snmpTrapOID.data(),
- snmpTrapOID.size(),
- ASN_OBJECT_ID,
- customTrapOID.data(),
- customTrapOID.size() * sizeof(oid));
+ addSNMPTrapOID(&varList,
+ customTrapOID.data(),
+ customTrapOID.size() * sizeof(oid));
snmp_varlist_add_variable(&varList,
trapReasonOID.data(),
#ifdef HAVE_NET_SNMP
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+
#ifndef HAVE_SNMP_SELECT_INFO2
/* that's terrible, because it means we are going to have trouble with large
FD numbers at some point.. */
# include <net-snmp/library/large_fd_set.h>
#endif
-const std::array<oid, 11> SNMPAgent::snmpTrapOID = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
+static const std::array<oid, 11> s_snmpTrapOID = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
int SNMPAgent::setCounter64Value(netsnmp_request_info* request,
uint64_t value)
return SNMP_ERR_NOERROR;
}
+void SNMPAgent::addSNMPTrapOID(netsnmp_variable_list** varList, const void* value, size_t len)
+{
+ snmp_varlist_add_variable(varList,
+ s_snmpTrapOID.data(),
+ s_snmpTrapOID.size(),
+ ASN_OBJECT_ID,
+ value,
+ len);
+}
+
bool SNMPAgent::sendTrap(pdns::channel::Sender<netsnmp_variable_list, void(*)(netsnmp_variable_list*)>& sender,
netsnmp_variable_list* varList)
{
#include <thread>
#include <unistd.h>
-#ifdef HAVE_NET_SNMP
-#include <net-snmp/net-snmp-config.h>
-#include <net-snmp/definitions.h>
-#include <net-snmp/types.h>
-#include <net-snmp/utilities.h>
-#include <net-snmp/config_api.h>
-#include <net-snmp/agent/net-snmp-agent-includes.h>
-#undef INET6 /* SRSLY? */
-#endif /* HAVE_NET_SNMP */
-
#include "mplexer.hh"
#include "channel.hh"
+typedef struct netsnmp_request_info_s netsnmp_request_info;
+typedef struct variable_list netsnmp_variable_list;
+
class SNMPAgent
{
public:
#endif /* HAVE_NET_SNMP */
protected:
#ifdef HAVE_NET_SNMP
- /* OID for snmpTrapOID.0 */
- static const std::array<oid, 11> snmpTrapOID;
+ static void addSNMPTrapOID(netsnmp_variable_list** varList, const void* value, size_t len);
static bool sendTrap(pdns::channel::Sender<netsnmp_variable_list, void(*)(netsnmp_variable_list*)>& sender,
netsnmp_variable_list* varList);