blob: 8bf27f2945ad8a692ed6ebc05eed208bee6ad8fc [file] [log] [blame]
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -05001#include <phosphor-logging/elog.hpp>
2#include "xyz/openbmc_project/Led/Fru/Monitor/error.hpp"
3#include "xyz/openbmc_project/Led/Mapper/error.hpp"
4#include "elog-errors.hpp"
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05005#include "fru-fault-monitor.hpp"
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -05006
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05007namespace phosphor
8{
9namespace led
10{
11namespace fru
12{
13namespace fault
14{
15namespace monitor
16{
17
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050018using namespace phosphor::logging;
19
20constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
21constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
22constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
23constexpr auto OBJMGR_IFACE = "org.freedesktop.DBus.ObjectManager";
24constexpr auto LED_GROUPS = "/xyz/openbmc_project/led/groups/";
25constexpr auto LOG_PATH = "/xyz/openbmc_project/logging";
26
27using AssociationList = std::vector<std::tuple<
28 std::string, std::string, std::string>>;
29using MethodErr =
30 sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError;
31using ObjectNotFoundErr =
32 sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError;
33using AssociationRetrieveErr =
34 sdbusplus::xyz::openbmc_project::
35 Led::Fru::Monitor::Error::AssociationRetrieveError;
36using InventoryPathErr =
37 sdbusplus::xyz::openbmc_project::
38 Led::Fru::Monitor::Error::InventoryPathError;
39
40std::string getService(sdbusplus::bus::bus& bus,
41 const std::string& path)
42{
43 auto mapper = bus.new_method_call(MAPPER_BUSNAME,
44 MAPPER_OBJ_PATH,
45 MAPPER_IFACE, "GetObject");
46 mapper.append(path.c_str(), std::vector<std::string>({OBJMGR_IFACE}));
47 auto mapperResponseMsg = bus.call(mapper);
48 if (mapperResponseMsg.is_method_error())
49 {
50 using namespace xyz::openbmc_project::Led::Mapper;
51 elog<MethodErr>(
52 MethodError::METHOD_NAME("GetObject"),
53 MethodError::PATH(path.c_str()),
54 MethodError::INTERFACE(
55 OBJMGR_IFACE));
56 }
57
58 std::map<std::string, std::vector<std::string>> mapperResponse;
59 mapperResponseMsg.read(mapperResponse);
60 if (mapperResponse.empty())
61 {
62 using namespace xyz::openbmc_project::Led::Mapper;
63 elog<ObjectNotFoundErr>(
64 ObjectNotFoundError::METHOD_NAME("GetObject"),
65 ObjectNotFoundError::PATH(path.c_str()),
66 ObjectNotFoundError::INTERFACE(
67 OBJMGR_IFACE));
68 }
69
70 return mapperResponse.cbegin()->first;
71}
72
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050073void action(sdbusplus::bus::bus& bus,
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050074 const std::string& path,
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050075 bool assert)
76{
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050077 std::string service;
78 try
79 {
80 service = getService(bus, LED_GROUPS);
81 }
82 catch (MethodErr& e)
83 {
84 commit<MethodErr>();
85 return;
86 }
87 catch (ObjectNotFoundErr& e)
88 {
89 commit<ObjectNotFoundErr>();
90 return;
91 }
92
93 auto pos = path.rfind("/");
94 if (pos == std::string::npos)
95 {
96 using namespace xyz::openbmc_project::Led::Fru::Monitor;
97 report<InventoryPathErr>(
98 InventoryPathError::PATH(
99 path.c_str()));
100 return;
101 }
102 auto unit = path.substr(pos + 1);
103
104 std::string ledPath = LED_GROUPS +
105 unit + '_' + LED_FAULT;
106
107 auto method = bus.new_method_call(service.c_str(),
108 ledPath.c_str(),
109 "org.freedesktop.DBus.Properties",
110 "Set");
111 method.append("xyz.openbmc_project.Led.Group");
112 method.append("Asserted");
113
114 method.append(sdbusplus::message::variant<bool>(assert));
115 bus.call_noreply(method);
116
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500117 return;
118}
119
Patrick Williams3eedbe42017-05-31 17:27:05 -0500120void Add::created(sdbusplus::message::message& msg)
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500121{
Patrick Williams3eedbe42017-05-31 17:27:05 -0500122 auto bus = msg.get_bus();
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500123
124 sdbusplus::message::object_path obPath;
Patrick Williams3eedbe42017-05-31 17:27:05 -0500125 msg.read(obPath);
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500126 std::string objectPath(std::move(obPath));
127
128 std::size_t found = objectPath.find(ELOG_ENTRY);
129 if (found == std::string::npos)
130 {
131 //Not a new error entry skip
Patrick Williams3eedbe42017-05-31 17:27:05 -0500132 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500133 }
134
135 std::string service;
136 try
137 {
138 service = getService(bus, LOG_PATH);
139 }
140 catch (MethodErr& e)
141 {
142 commit<MethodErr>();
Patrick Williams3eedbe42017-05-31 17:27:05 -0500143 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500144 }
145 catch (ObjectNotFoundErr& e)
146 {
147 commit<ObjectNotFoundErr>();
Patrick Williams3eedbe42017-05-31 17:27:05 -0500148 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500149 }
150
151 auto method = bus.new_method_call(service.c_str(), objectPath.c_str(),
152 "org.freedesktop.DBus.Properties",
153 "Get");
154
155 method.append("org.openbmc.Associations");
156 method.append("associations");
157 auto reply = bus.call(method);
158 if (reply.is_method_error())
159 {
160 using namespace xyz::openbmc_project::Led::Fru::Monitor;
161 report<AssociationRetrieveErr>(
162 AssociationRetrieveError::ELOG_ENTRY_PATH(
163 objectPath.c_str()));
Patrick Williams3eedbe42017-05-31 17:27:05 -0500164 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500165 }
166
167 sdbusplus::message::variant<AssociationList> assoc;
168 reply.read(assoc);
169
170 auto assocs =
171 sdbusplus::message::variant_ns::get<AssociationList>(assoc);
172 if (assocs.empty())
173 {
174 //No associations skip
Patrick Williams3eedbe42017-05-31 17:27:05 -0500175 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500176 }
177
178 for (const auto& item : assocs)
179 {
180 if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0)
181 {
182 action(bus, std::get<2>(item), true);
Patrick Williams3eedbe42017-05-31 17:27:05 -0500183 removeWatches.emplace_back(
184 std::make_unique<Remove>(bus, std::get<2>(item)));
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500185 }
186 }
Patrick Williams3eedbe42017-05-31 17:27:05 -0500187 return;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500188}
189
Patrick Williams3eedbe42017-05-31 17:27:05 -0500190void Remove::removed(sdbusplus::message::message& msg)
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500191{
Patrick Williams3eedbe42017-05-31 17:27:05 -0500192 auto bus = msg.get_bus();
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500193 std::string assoc;
Patrick Williams3eedbe42017-05-31 17:27:05 -0500194 msg.read(assoc);
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500195
196 if (assoc.compare("org.openbmc.Association"))
197 {
198 //Skip if not about association
Patrick Williams3eedbe42017-05-31 17:27:05 -0500199 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500200 }
201
202 std::map<std::string, std::vector<std::string>> endPoints;
Patrick Williams3eedbe42017-05-31 17:27:05 -0500203 msg.read(endPoints);
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500204 auto it = endPoints.find("endpoints");
205
206 if (it == endPoints.end())
207 {
208 //No end points,skip
Patrick Williams3eedbe42017-05-31 17:27:05 -0500209 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500210 }
211
212 if (!((*it).second.empty()))
213 {
214 //Skip, end points are not empty
Patrick Williams3eedbe42017-05-31 17:27:05 -0500215 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500216 }
217
Patrick Williams3eedbe42017-05-31 17:27:05 -0500218 action(bus, inventoryPath, false);
219 return;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500220}
221
222}//namespace monitor
223}//namespace fault
224}//namespace fru
225}//namespace led
226}//namespace phosphor