Add the Sysuptime in SNMP trap
As per the rfc3416 https://tools.ietf.org/search/rfc3416#page-22
The first two variable bindings in the variable binding list
of an SNMPv2-Trap-PDU are sysUpTime.0 [RFC3418] and snmpTrapOID.0
[RFC3418].
This commit adds the sysUpTime.0 [RFC3418] in the SNMP trap.
Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
Change-Id: Ie1a28ac2bbf30e05f0be498c278d866e9bf9c8a2
diff --git a/snmp_notification.cpp b/snmp_notification.cpp
index 420cc01..db19ecc 100644
--- a/snmp_notification.cpp
+++ b/snmp_notification.cpp
@@ -102,10 +102,25 @@
elog<InternalFailure>();
}
+ // https://tools.ietf.org/search/rfc3416#page-22
+ // add the sysUpTime.0 [RFC3418]
+ auto sysuptime = get_uptime();
+ std::string sysuptimeStr = std::to_string(sysuptime);
+
+ if (snmp_add_var(pdu, sysuptimeOID, sizeof(sysuptimeOID) / sizeof(oid),
+ 't', sysuptimeStr.c_str()))
+
+ {
+ log<level::ERR>("Failed to add the SNMP var(systime)");
+ snmp_free_pdu(pdu);
+ elog<InternalFailure>();
+ }
+
pdu->trap_type = SNMP_TRAP_ENTERPRISESPECIFIC;
auto trapInfo = getTrapOID();
+ // add the snmpTrapOID.0 [RFC3418]
if (!snmp_pdu_add_variable(pdu, SNMPTrapOID,
sizeof(SNMPTrapOID) / sizeof(oid),
ASN_OBJECT_ID, trapInfo.first.data(),