snmp_trap: send AdditionalData contents
The log messages often contain essential diagnostics information in a
key-value list in AdditionalData. Add it in space-separated form to the
SNMP trap.
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Change-Id: I72a49a59e6f3f9fcc24a69b0752cbb7b122be940
diff --git a/src/data_types.hpp b/src/data_types.hpp
index 81bb8cb..cffbd99 100644
--- a/src/data_types.hpp
+++ b/src/data_types.hpp
@@ -4,7 +4,11 @@
#include <experimental/any>
#include <sdbusplus/message.hpp>
+#include <sdbusplus/utility/merge_variants.hpp>
#include <string>
+#include <xyz/openbmc_project/Association/Definitions/server.hpp>
+#include <xyz/openbmc_project/Logging/Entry/server.hpp>
+#include <xyz/openbmc_project/Software/Version/server.hpp>
namespace any_ns = std::experimental;
@@ -63,9 +67,12 @@
template <typename T>
using InterfacesAdded =
std::map<std::string, std::map<std::string, std::variant<T>>>;
-using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
- int64_t, uint64_t, std::string>;
-
+using Value = sdbusplus::utility::merge_variants_t<
+ sdbusplus::xyz::openbmc_project::Association::server::Definitions::
+ PropertiesVariant,
+ sdbusplus::xyz::openbmc_project::Logging::server::Entry::PropertiesVariant,
+ sdbusplus::xyz::openbmc_project::Software::server::Version::
+ PropertiesVariant>;
/** @brief ObjectManager.InterfacesAdded signal signature alias. */
using Interface = std::string;
using Property = std::string;
diff --git a/src/snmp_trap.cpp b/src/snmp_trap.cpp
index 309b22e..6b4e808 100644
--- a/src/snmp_trap.cpp
+++ b/src/snmp_trap.cpp
@@ -35,9 +35,15 @@
auto& propMap = it->second;
auto errorID = std::get<uint32_t>(propMap.at("Id"));
auto timestamp = std::get<uint64_t>(propMap.at("Timestamp"));
- auto sev = std::get<std::string>(propMap.at("Severity"));
- auto isev = static_cast<uint8_t>(Entry::convertLevelFromString(sev));
+ auto sev = std::get<Entry::Level>(propMap.at("Severity"));
+ auto isev = static_cast<uint8_t>(sev);
auto message = std::get<std::string>(propMap.at("Message"));
+ auto additionalData =
+ std::get<std::vector<std::string>>(propMap.at("AdditionalData"));
+ for (auto& s : additionalData)
+ {
+ message += " " + s;
+ }
try
{
sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message);
@@ -48,7 +54,8 @@
"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("SEVERITY=%s",
+ convertForMessage(sev).c_str()),
phosphor::logging::entry("MESSAGE=%s", message.c_str()));
}
}