xref: /openbmc/phosphor-debug-collector/ramoops_manager.cpp (revision d1f670fe7ea219c643f8b630e8c2d7b333f16e35)
1 #include "config.h"
2 
3 #include "ramoops_manager.hpp"
4 
5 #include <phosphor-logging/lg2.hpp>
6 #include <sdbusplus/exception.hpp>
7 
8 #include <filesystem>
9 
10 namespace phosphor
11 {
12 namespace dump
13 {
14 namespace ramoops
15 {
16 
17 Manager::Manager(const std::string& filePath)
18 {
19     namespace fs = std::filesystem;
20 
21     fs::path dir(filePath);
22     if (!fs::exists(dir) || fs::is_empty(dir))
23     {
24         return;
25     }
26 
27     std::vector<std::string> files;
28     files.push_back(filePath);
29 
30     createHelper(files);
31 }
32 
33 void Manager::createHelper(const std::vector<std::string>& files)
34 {
35     constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
36     constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
37     constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
38     constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
39     constexpr auto RAMOOPS =
40         "xyz.openbmc_project.Dump.Internal.Create.Type.Ramoops";
41 
42     auto b = sdbusplus::bus::new_default();
43     auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
44                                     MAPPER_INTERFACE, "GetObject");
45     mapper.append(OBJ_INTERNAL, std::set<std::string>({IFACE_INTERNAL}));
46 
47     std::map<std::string, std::set<std::string>> mapperResponse;
48     try
49     {
50         auto mapperResponseMsg = b.call(mapper);
51         mapperResponseMsg.read(mapperResponse);
52     }
53     catch (const sdbusplus::exception_t& e)
54     {
55         lg2::error("Failed to parse dump create message, error: {ERROR}",
56                    "ERROR", e);
57         return;
58     }
59     if (mapperResponse.empty())
60     {
61         lg2::error("Error reading mapper response");
62         return;
63     }
64 
65     const auto& host = mapperResponse.cbegin()->first;
66     auto m = b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL,
67                                "Create");
68     m.append(RAMOOPS, files);
69     try
70     {
71         b.call_noreply(m);
72     }
73     catch (const sdbusplus::exception_t& e)
74     {
75         lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR",
76                    e);
77     }
78 }
79 
80 } // namespace ramoops
81 } // namespace dump
82 } // namespace phosphor
83