From e88df9cfcb1ab27413c0591202b5deb918c85c60 Mon Sep 17 00:00:00 2001 From: Marri Devender Rao Date: Wed, 2 May 2018 00:16:06 -0500 Subject: Raise SNMP trap by reading error entry properties dbus-monitor is notified for any new error entry created. dbus-monitor parses the error entry and constructs ErrorNotification object and sends SNMP trap. Change-Id: I25916b087c5513916c90266278ccafc5db3c41a0 Signed-off-by: Marri Devender Rao --- configure.ac | 1 + src/Makefile.am | 4 +++- src/snmp_trap.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index d0adf4e..7ec92de 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,7 @@ AM_PATH_PYTHON([2.7], PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, AC_MSG_ERROR(["Requires sdbusplus package."])) PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],, AC_MSG_ERROR(["Requires phosphor-dbus-interfaces package."])) PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],, AC_MSG_ERROR(["Requires phosphor-logging."])) +PKG_CHECK_MODULES([PHOSPHOR_SNMP], [phosphor-snmp],, AC_MSG_ERROR(["Requires phosphor-snmp."])) # Check for sdbus++ AC_PATH_PROG([SDBUSPLUSPLUS], [sdbus++]) diff --git a/src/Makefile.am b/src/Makefile.am index 583e533..55a2d06 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,11 +20,13 @@ phosphor_dbus_monitor_LDADD = \ $(SDBUSPLUS_LIBS) \ $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ $(PHOSPHOR_LOGGING_LIBS) \ + $(PHOSPHOR_SNMP_LIBS) \ -lstdc++fs phosphor_dbus_monitor_CXXFLAGS = \ $(SDBUSPLUS_CFLAGS) \ $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \ - $(PHOSPHOR_LOGGING_CFLAGS) + $(PHOSPHOR_LOGGING_CFLAGS) \ + $(PHOSPHOR_SNMP_CFLAGS) BUILT_SOURCES = generated.hpp CLEANFILES = generated.hpp diff --git a/src/snmp_trap.cpp b/src/snmp_trap.cpp index 06e8b18..27b8133 100644 --- a/src/snmp_trap.cpp +++ b/src/snmp_trap.cpp @@ -1,14 +1,55 @@ #include "snmp_trap.hpp" +#include +#include +#include +#include +#include +#include +#include namespace phosphor { namespace dbus { namespace monitoring { +using namespace phosphor::logging; +using namespace sdbusplus::xyz::openbmc_project::Logging::server; +using namespace phosphor::network::snmp; +using InternalFailure = + sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; + +static constexpr auto entry = "xyz.openbmc_project.Logging.Entry"; + void ErrorTrap::trap(sdbusplus::message::message& msg) const { - // TODO openbmc/openbmc#3059 - // TODO: Send trap to SNMP to be added after phoshpor-snmp is merged + sdbusplus::message::object_path path; + msg.read(path); + PathInterfacesAdded intfs; + msg.read(intfs); + auto it = intfs.find(entry); + if (it == intfs.end()) + { + return; + } + auto& propMap = it->second; + auto errorID = propMap.at("Id").get(); + auto timestamp = propMap.at("Timestamp").get(); + auto sev = propMap.at("Severity").get(); + auto isev = static_cast(Entry::convertLevelFromString(sev)); + auto message = propMap.at("Message").get(); + try + { + sendTrap(errorID, timestamp, isev, message); + } + catch (const InternalFailure& e) + { + log( + "Failed to send SNMP trap", + phosphor::logging::entry("ERROR_ID=%d", errorID), + phosphor::logging::entry("TIMESTAMP=%llu", timestamp), + phosphor::logging::entry("SEVERITY=%s", sev.c_str()), + phosphor::logging::entry("MESSAGE=%s", message.c_str())); + } } } // namespace monitoring } // namespace dbus -- cgit v1.2.1