summaryrefslogtreecommitdiffstats
path: root/src/snmp_trap.cpp
blob: eb2efd3641b9ce2968122cede9142b1a9859b0e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "snmp_trap.hpp"

#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <snmp.hpp>
#include <snmp_notification.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Logging/Entry/server.hpp>
namespace phosphor
{
namespace dbus
{
namespace monitoring
{
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Logging::server;
using namespace phosphor::network::snmp;
using InternalFailure =
    sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;

static constexpr auto entry = "xyz.openbmc_project.Logging.Entry";

void ErrorTrap::trap(sdbusplus::message::message& msg) const
{
    sdbusplus::message::object_path path;
    msg.read(path);
    PathInterfacesAdded intfs;
    msg.read(intfs);
    auto it = intfs.find(entry);
    if (it == intfs.end())
    {
        return;
    }
    auto& propMap = it->second;
    auto errorID =
        sdbusplus::message::variant_ns::get<uint32_t>(propMap.at("Id"));
    auto timestamp =
        sdbusplus::message::variant_ns::get<uint64_t>(propMap.at("Timestamp"));
    auto sev = sdbusplus::message::variant_ns::get<std::string>(
        propMap.at("Severity"));
    auto isev = static_cast<uint8_t>(Entry::convertLevelFromString(sev));
    auto message =
        sdbusplus::message::variant_ns::get<std::string>(propMap.at("Message"));
    try
    {
        sendTrap<OBMCErrorNotification>(errorID, timestamp, isev, message);
    }
    catch (const InternalFailure& e)
    {
        log<level::INFO>(
            "Failed to send SNMP trap",
            phosphor::logging::entry("ERROR_ID=%d", errorID),
            phosphor::logging::entry("TIMESTAMP=%llu", timestamp),
            phosphor::logging::entry("SEVERITY=%s", sev.c_str()),
            phosphor::logging::entry("MESSAGE=%s", message.c_str()));
    }
}
} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud