blob: 3a047d3adc844bbac54705a4af98ba9f42ec0473 [file] [log] [blame]
Marri Devender Rao78479602020-01-06 03:45:11 -06001#include "create_pel.hpp"
2
3#include <libekb.H>
4#include <unistd.h>
5
6#include <map>
7#include <phosphor-logging/elog.hpp>
8#include <xyz/openbmc_project/Logging/Entry/server.hpp>
9namespace openpower
10{
11using namespace phosphor::logging;
12
13namespace util
14{
15std::string getService(sdbusplus::bus::bus& bus, const std::string& objectPath,
16 const std::string& interface)
17{
18 constexpr auto mapperBusBame = "xyz.openbmc_project.ObjectMapper";
19 constexpr auto mapperObjectPath = "/xyz/openbmc_project/object_mapper";
20 constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
21 std::vector<std::pair<std::string, std::vector<std::string>>> response;
22 auto method = bus.new_method_call(mapperBusBame, mapperObjectPath,
23 mapperInterface, "GetObject");
24 method.append(objectPath, std::vector<std::string>({interface}));
25 try
26 {
27 auto reply = bus.call(method);
28 reply.read(response);
29 }
30 catch (const sdbusplus::exception::SdBusError& e)
31 {
32 log<level::ERR>("D-Bus call exception",
33 entry("OBJPATH=%s", mapperObjectPath),
34 entry("INTERFACE=%s", mapperInterface),
35 entry("EXCEPTION=%s", e.what()));
36
37 throw std::runtime_error("Service name is not found");
38 }
39
40 if (response.empty())
41 {
42 throw std::runtime_error("Service name response is empty");
43 }
44 return response.begin()->first;
45}
46} // namespace util
47
48namespace pel
49{
50void createBootErrorPEL(const FFDCData& ffdcData)
51{
52 constexpr auto loggingObjectPath = "/xyz/openbmc_project/logging";
53 constexpr auto loggingInterface = "xyz.openbmc_project.Logging.Create";
54
55 std::map<std::string, std::string> additionalData;
56 auto bus = sdbusplus::bus::new_default();
57 additionalData.emplace("_PID", std::to_string(getpid()));
58 for (auto& data : ffdcData)
59 {
60 additionalData.emplace(data);
61 }
62 try
63 {
64 static constexpr auto bootErrorMessage =
65 "org.open_power.PHAL.Error.Boot";
66 std::string service =
67 util::getService(bus, loggingObjectPath, loggingInterface);
68 auto method = bus.new_method_call(service.c_str(), loggingObjectPath,
69 loggingInterface, "Create");
70 auto level =
71 sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
72 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
73 Error);
74 method.append(bootErrorMessage, level, additionalData);
75 auto resp = bus.call(method);
76 }
77 catch (const sdbusplus::exception::SdBusError& e)
78 {
79 log<level::ERR>("D-Bus call exception",
80 entry("OBJPATH=%s", loggingObjectPath),
81 entry("INTERFACE=%s", loggingInterface),
82 entry("EXCEPTION=%s", e.what()));
83
84 throw std::runtime_error(
85 "Error in invoking D-Bus logging create interface");
86 }
87}
88} // namespace pel
89} // namespace openpower