blob: eb2efd3641b9ce2968122cede9142b1a9859b0e1 [file] [log] [blame]
Marri Devender Rao70aafbb2018-04-12 01:11:48 -05001#include "snmp_trap.hpp"
Patrick Venture3d6d3182018-08-31 09:33:09 -07002
3#include <phosphor-logging/elog-errors.hpp>
4#include <phosphor-logging/elog.hpp>
5#include <phosphor-logging/log.hpp>
Marri Devender Raoe88df9c2018-05-02 00:16:06 -05006#include <snmp.hpp>
7#include <snmp_notification.hpp>
Marri Devender Raoe88df9c2018-05-02 00:16:06 -05008#include <xyz/openbmc_project/Common/error.hpp>
Patrick Venture3d6d3182018-08-31 09:33:09 -07009#include <xyz/openbmc_project/Logging/Entry/server.hpp>
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050010namespace phosphor
11{
12namespace dbus
13{
14namespace monitoring
15{
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050016using namespace phosphor::logging;
17using namespace sdbusplus::xyz::openbmc_project::Logging::server;
18using namespace phosphor::network::snmp;
19using InternalFailure =
20 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
21
22static constexpr auto entry = "xyz.openbmc_project.Logging.Entry";
23
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050024void ErrorTrap::trap(sdbusplus::message::message& msg) const
25{
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050026 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;
William A. Kennington IIIefcd6532018-11-12 15:54:32 -080036 auto errorID =
37 sdbusplus::message::variant_ns::get<uint32_t>(propMap.at("Id"));
38 auto timestamp =
39 sdbusplus::message::variant_ns::get<uint64_t>(propMap.at("Timestamp"));
40 auto sev = sdbusplus::message::variant_ns::get<std::string>(
41 propMap.at("Severity"));
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050042 auto isev = static_cast<uint8_t>(Entry::convertLevelFromString(sev));
William A. Kennington IIIefcd6532018-11-12 15:54:32 -080043 auto message =
44 sdbusplus::message::variant_ns::get<std::string>(propMap.at("Message"));
Marri Devender Raoe88df9c2018-05-02 00:16:06 -050045 try
46 {
47 sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message);
48 }
49 catch (const InternalFailure& e)
50 {
51 log<level::INFO>(
52 "Failed to send SNMP trap",
53 phosphor::logging::entry("ERROR_ID=%d", errorID),
54 phosphor::logging::entry("TIMESTAMP=%llu", timestamp),
55 phosphor::logging::entry("SEVERITY=%s", sev.c_str()),
56 phosphor::logging::entry("MESSAGE=%s", message.c_str()));
57 }
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050058}
59} // namespace monitoring
60} // namespace dbus
61} // namespace phosphor