1 #include "snmp_trap.hpp" 2 3 #include <phosphor-logging/elog-errors.hpp> 4 #include <phosphor-logging/elog.hpp> 5 #include <phosphor-logging/log.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 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 24 void ErrorTrap::trap(sdbusplus::message::message& msg) const 25 { 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; 36 auto errorID = std::get<uint32_t>(propMap.at("Id")); 37 auto timestamp = std::get<uint64_t>(propMap.at("Timestamp")); 38 auto sev = std::get<std::string>(propMap.at("Severity")); 39 auto isev = static_cast<uint8_t>(Entry::convertLevelFromString(sev)); 40 auto message = std::get<std::string>(propMap.at("Message")); 41 try 42 { 43 sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message); 44 } 45 catch (const InternalFailure& e) 46 { 47 log<level::INFO>( 48 "Failed to send SNMP trap", 49 phosphor::logging::entry("ERROR_ID=%d", errorID), 50 phosphor::logging::entry("TIMESTAMP=%llu", timestamp), 51 phosphor::logging::entry("SEVERITY=%s", sev.c_str()), 52 phosphor::logging::entry("MESSAGE=%s", message.c_str())); 53 } 54 } 55 } // namespace monitoring 56 } // namespace dbus 57 } // namespace phosphor 58