blob: f7a4685f2303cca035792023f18626a1f3aaa22c [file] [log] [blame]
Marri Devender Rao70aafbb2018-04-12 01:11:48 -05001#include "snmp_trap.hpp"
Patrick Venture3d6d3182018-08-31 09:33:09 -07002
3#include <phosphor-logging/elog-errors.hpp>
4#include <phosphor-logging/elog.hpp>
George Liu13e3df62022-06-22 15:03:06 +08005#include <phosphor-logging/lg2.hpp>
Marri Devender Raoe88df9c2018-05-02 00:16:06 -05006#include <snmp.hpp>
7#include <snmp_notification.hpp>
Marri Devender Raoe88df9c2018-05-02 00:16:06 -05008#include <xyz/openbmc_project/Common/error.hpp>
Patrick Venture3d6d3182018-08-31 09:33:09 -07009#include <xyz/openbmc_project/Logging/Entry/server.hpp>
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050010namespace phosphor
11{
12namespace dbus
13{
14namespace monitoring
15{
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050016using namespace sdbusplus::xyz::openbmc_project::Logging::server;
17using namespace phosphor::network::snmp;
18using InternalFailure =
19 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
20
21static constexpr auto entry = "xyz.openbmc_project.Logging.Entry";
22
Patrick Williams413a4852022-07-22 19:26:52 -050023void ErrorTrap::trap(sdbusplus::message_t& msg) const
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050024{
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050025 sdbusplus::message::object_path path;
26 msg.read(path);
27 PathInterfacesAdded intfs;
28 msg.read(intfs);
29 auto it = intfs.find(entry);
30 if (it == intfs.end())
31 {
32 return;
33 }
34 auto& propMap = it->second;
Patrick Williams34ef1e52020-05-13 11:07:43 -050035 auto errorID = std::get<uint32_t>(propMap.at("Id"));
36 auto timestamp = std::get<uint64_t>(propMap.at("Timestamp"));
Paul Fertser74dc24a2022-01-10 11:28:20 +000037 auto sev = std::get<Entry::Level>(propMap.at("Severity"));
38 auto isev = static_cast<uint8_t>(sev);
Patrick Williams34ef1e52020-05-13 11:07:43 -050039 auto message = std::get<std::string>(propMap.at("Message"));
Paul Fertser74dc24a2022-01-10 11:28:20 +000040 auto additionalData =
41 std::get<std::vector<std::string>>(propMap.at("AdditionalData"));
42 for (auto& s : additionalData)
43 {
George Liuecef1192022-07-07 08:59:12 +080044 message.append(" ");
45 message.append(s);
Paul Fertser74dc24a2022-01-10 11:28:20 +000046 }
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050047 try
48 {
49 sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message);
50 }
51 catch (const InternalFailure& e)
52 {
George Liu13e3df62022-06-22 15:03:06 +080053 lg2::error(
54 "Failed to send SNMP trap: {ERROR}, ERROR_ID = {EID}, TIMESTAMP = {TSP}, SEVERITY = {SEVERITY}, MESSAGE = {MSG}",
55 "ERROR", e, "EID", errorID, "TSP", timestamp, "SEVERITY",
56 convertForMessage(sev), "MSG", message);
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050057 }
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050058}
59} // namespace monitoring
60} // namespace dbus
61} // namespace phosphor