1 #include "snmp_trap.hpp"
2 #include <snmp.hpp>
3 #include <snmp_notification.hpp>
4 #include <phosphor-logging/log.hpp>
5 #include <phosphor-logging/elog.hpp>
6 #include <phosphor-logging/elog-errors.hpp>
7 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
8 #include <xyz/openbmc_project/Common/error.hpp>
9 namespace phosphor
10 {
11 namespace dbus
12 {
13 namespace monitoring
14 {
15 using namespace phosphor::logging;
16 using namespace sdbusplus::xyz::openbmc_project::Logging::server;
17 using namespace phosphor::network::snmp;
18 using InternalFailure =
19     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
20 
21 static constexpr auto entry = "xyz.openbmc_project.Logging.Entry";
22 
23 void ErrorTrap::trap(sdbusplus::message::message& msg) const
24 {
25     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;
35     auto errorID = propMap.at("Id").get<uint32_t>();
36     auto timestamp = propMap.at("Timestamp").get<uint64_t>();
37     auto sev = propMap.at("Severity").get<std::string>();
38     auto isev = static_cast<uint8_t>(Entry::convertLevelFromString(sev));
39     auto message = propMap.at("Message").get<std::string>();
40     try
41     {
42         sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message);
43     }
44     catch (const InternalFailure& e)
45     {
46         log<level::INFO>(
47             "Failed to send SNMP trap",
48             phosphor::logging::entry("ERROR_ID=%d", errorID),
49             phosphor::logging::entry("TIMESTAMP=%llu", timestamp),
50             phosphor::logging::entry("SEVERITY=%s", sev.c_str()),
51             phosphor::logging::entry("MESSAGE=%s", message.c_str()));
52     }
53 }
54 } // namespace monitoring
55 } // namespace dbus
56 } // namespace phosphor
57