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> |
George Liu | 13e3df6 | 2022-06-22 15:03:06 +0800 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.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 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 | |
Patrick Williams | 413a485 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 23 | void ErrorTrap::trap(sdbusplus::message_t& msg) const |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 24 | { |
Marri Devender Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 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; |
Patrick Williams | 34ef1e5 | 2020-05-13 11:07:43 -0500 | [diff] [blame] | 35 | auto errorID = std::get<uint32_t>(propMap.at("Id")); |
| 36 | auto timestamp = std::get<uint64_t>(propMap.at("Timestamp")); |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame] | 37 | auto sev = std::get<Entry::Level>(propMap.at("Severity")); |
| 38 | auto isev = static_cast<uint8_t>(sev); |
Patrick Williams | 34ef1e5 | 2020-05-13 11:07:43 -0500 | [diff] [blame] | 39 | auto message = std::get<std::string>(propMap.at("Message")); |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame] | 40 | auto additionalData = |
| 41 | std::get<std::vector<std::string>>(propMap.at("AdditionalData")); |
| 42 | for (auto& s : additionalData) |
| 43 | { |
George Liu | ecef119 | 2022-07-07 08:59:12 +0800 | [diff] [blame] | 44 | message.append(" "); |
| 45 | message.append(s); |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame] | 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 | { |
George Liu | 13e3df6 | 2022-06-22 15:03:06 +0800 | [diff] [blame] | 53 | 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 Rao | e88df9c | 2018-05-02 00:16:06 -0500 | [diff] [blame] | 57 | } |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 58 | } |
| 59 | } // namespace monitoring |
| 60 | } // namespace dbus |
| 61 | } // namespace phosphor |