Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 1 | #include "snmp_trap.hpp" |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 2 | |
| 3 | #include <phosphor-logging/elog-errors.hpp> |
| 4 | #include <phosphor-logging/elog.hpp> |
| 5 | #include <phosphor-logging/log.hpp> |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 6 | #include <snmp.hpp> |
| 7 | #include <snmp_notification.hpp> |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Common/error.hpp> |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace dbus |
| 13 | { |
| 14 | namespace monitoring |
| 15 | { |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 16 | using namespace phosphor::logging; |
| 17 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
| 18 | using namespace phosphor::network::snmp; |
| 19 | using InternalFailure = |
| 20 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 21 | |
| 22 | static constexpr auto entry = "xyz.openbmc_project.Logging.Entry"; |
| 23 | |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 24 | void ErrorTrap::trap(sdbusplus::message::message& msg) const |
| 25 | { |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 26 | sdbusplus::message::object_path path; |
| 27 | msg.read(path); |
| 28 | PathInterfacesAdded intfs; |
| 29 | msg.read(intfs); |
| 30 | auto it = intfs.find(entry); |
| 31 | if (it == intfs.end()) |
| 32 | { |
| 33 | return; |
| 34 | } |
| 35 | auto& propMap = it->second; |
Patrick Williams | 34ef1e5 | 2020-05-13 11:07:43 -0500 | [diff] [blame] | 36 | auto errorID = std::get<uint32_t>(propMap.at("Id")); |
| 37 | auto timestamp = std::get<uint64_t>(propMap.at("Timestamp")); |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame^] | 38 | auto sev = std::get<Entry::Level>(propMap.at("Severity")); |
| 39 | auto isev = static_cast<uint8_t>(sev); |
Patrick Williams | 34ef1e5 | 2020-05-13 11:07:43 -0500 | [diff] [blame] | 40 | auto message = std::get<std::string>(propMap.at("Message")); |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame^] | 41 | auto additionalData = |
| 42 | std::get<std::vector<std::string>>(propMap.at("AdditionalData")); |
| 43 | for (auto& s : additionalData) |
| 44 | { |
| 45 | message += " " + s; |
| 46 | } |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 47 | try |
| 48 | { |
| 49 | sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message); |
| 50 | } |
| 51 | catch (const InternalFailure& e) |
| 52 | { |
| 53 | log<level::INFO>( |
| 54 | "Failed to send SNMP trap", |
| 55 | phosphor::logging::entry("ERROR_ID=%d", errorID), |
| 56 | phosphor::logging::entry("TIMESTAMP=%llu", timestamp), |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame^] | 57 | phosphor::logging::entry("SEVERITY=%s", |
| 58 | convertForMessage(sev).c_str()), |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 59 | phosphor::logging::entry("MESSAGE=%s", message.c_str())); |
| 60 | } |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 61 | } |
| 62 | } // namespace monitoring |
| 63 | } // namespace dbus |
| 64 | } // namespace phosphor |