1 #include "snmp_trap.hpp" 2 3 #include <phosphor-logging/elog-errors.hpp> 4 #include <phosphor-logging/elog.hpp> 5 #include <phosphor-logging/lg2.hpp> 6 #include <snmp.hpp> 7 #include <snmp_notification.hpp> 8 #include <xyz/openbmc_project/Common/error.hpp> 9 #include <xyz/openbmc_project/Logging/Entry/server.hpp> 10 namespace phosphor 11 { 12 namespace dbus 13 { 14 namespace monitoring 15 { 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 = std::get<uint32_t>(propMap.at("Id")); 36 auto timestamp = std::get<uint64_t>(propMap.at("Timestamp")); 37 auto sev = std::get<Entry::Level>(propMap.at("Severity")); 38 auto isev = static_cast<uint8_t>(sev); 39 auto message = std::get<std::string>(propMap.at("Message")); 40 auto additionalData = 41 std::get<std::vector<std::string>>(propMap.at("AdditionalData")); 42 for (auto& s : additionalData) 43 { 44 message += " " + s; 45 } 46 try 47 { 48 sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message); 49 } 50 catch (const InternalFailure& e) 51 { 52 lg2::error( 53 "Failed to send SNMP trap: {ERROR}, ERROR_ID = {EID}, TIMESTAMP = {TSP}, SEVERITY = {SEVERITY}, MESSAGE = {MSG}", 54 "ERROR", e, "EID", errorID, "TSP", timestamp, "SEVERITY", 55 convertForMessage(sev), "MSG", message); 56 } 57 } 58 } // namespace monitoring 59 } // namespace dbus 60 } // namespace phosphor 61