blob: dc2f23180b40fcdd3af6759b88f72f1a702047c0 [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>>;
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -050029using Attributes = sdbusplus::message::variant<bool,AssociationList>;
30using AttributeName = std::string;
31using AttributeMap = std::map<AttributeName, Attributes>;
32using PropertyName = std::string;
33using PropertyMap = std::map<PropertyName, AttributeMap>;
34using LogEntryMsg = std::pair<sdbusplus::message::object_path, PropertyMap>;
35
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050036using MethodErr =
37 sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError;
38using ObjectNotFoundErr =
39 sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050040using InventoryPathErr =
41 sdbusplus::xyz::openbmc_project::
42 Led::Fru::Monitor::Error::InventoryPathError;
43
44std::string getService(sdbusplus::bus::bus& bus,
45 const std::string& path)
46{
47 auto mapper = bus.new_method_call(MAPPER_BUSNAME,
48 MAPPER_OBJ_PATH,
49 MAPPER_IFACE, "GetObject");
50 mapper.append(path.c_str(), std::vector<std::string>({OBJMGR_IFACE}));
51 auto mapperResponseMsg = bus.call(mapper);
52 if (mapperResponseMsg.is_method_error())
53 {
54 using namespace xyz::openbmc_project::Led::Mapper;
55 elog<MethodErr>(
56 MethodError::METHOD_NAME("GetObject"),
57 MethodError::PATH(path.c_str()),
58 MethodError::INTERFACE(
59 OBJMGR_IFACE));
60 }
61
62 std::map<std::string, std::vector<std::string>> mapperResponse;
63 mapperResponseMsg.read(mapperResponse);
64 if (mapperResponse.empty())
65 {
66 using namespace xyz::openbmc_project::Led::Mapper;
67 elog<ObjectNotFoundErr>(
68 ObjectNotFoundError::METHOD_NAME("GetObject"),
69 ObjectNotFoundError::PATH(path.c_str()),
70 ObjectNotFoundError::INTERFACE(
71 OBJMGR_IFACE));
72 }
73
74 return mapperResponse.cbegin()->first;
75}
76
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050077void action(sdbusplus::bus::bus& bus,
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050078 const std::string& path,
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050079 bool assert)
80{
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -050081 std::string service;
82 try
83 {
84 service = getService(bus, LED_GROUPS);
85 }
86 catch (MethodErr& e)
87 {
88 commit<MethodErr>();
89 return;
90 }
91 catch (ObjectNotFoundErr& e)
92 {
93 commit<ObjectNotFoundErr>();
94 return;
95 }
96
97 auto pos = path.rfind("/");
98 if (pos == std::string::npos)
99 {
100 using namespace xyz::openbmc_project::Led::Fru::Monitor;
101 report<InventoryPathErr>(
102 InventoryPathError::PATH(
103 path.c_str()));
104 return;
105 }
106 auto unit = path.substr(pos + 1);
107
108 std::string ledPath = LED_GROUPS +
109 unit + '_' + LED_FAULT;
110
111 auto method = bus.new_method_call(service.c_str(),
112 ledPath.c_str(),
113 "org.freedesktop.DBus.Properties",
114 "Set");
115 method.append("xyz.openbmc_project.Led.Group");
116 method.append("Asserted");
117
118 method.append(sdbusplus::message::variant<bool>(assert));
119 bus.call_noreply(method);
120
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500121 return;
122}
123
Patrick Williams3eedbe42017-05-31 17:27:05 -0500124void Add::created(sdbusplus::message::message& msg)
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500125{
Patrick Williams3eedbe42017-05-31 17:27:05 -0500126 auto bus = msg.get_bus();
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500127
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500128 LogEntryMsg logEntry;
129 msg.read(logEntry);
130 std::string objectPath(std::move(logEntry.first));
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500131
132 std::size_t found = objectPath.find(ELOG_ENTRY);
133 if (found == std::string::npos)
134 {
135 //Not a new error entry skip
Patrick Williams3eedbe42017-05-31 17:27:05 -0500136 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500137 }
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500138 log<level::ERR>(objectPath.c_str());
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500139
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500140 auto iter = logEntry.second.find("org.openbmc.Associations");
141 if (iter == logEntry.second.end())
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500142 {
Patrick Williams3eedbe42017-05-31 17:27:05 -0500143 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500144 }
145
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500146 auto attr = iter->second.find("associations");
147 if (attr == iter->second.end())
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500148 {
Patrick Williams3eedbe42017-05-31 17:27:05 -0500149 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500150 }
151
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500152 auto& assocs =
153 sdbusplus::message::variant_ns::get<AssociationList>(attr->second);
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500154 if (assocs.empty())
155 {
156 //No associations skip
Patrick Williams3eedbe42017-05-31 17:27:05 -0500157 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500158 }
159
160 for (const auto& item : assocs)
161 {
162 if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0)
163 {
164 action(bus, std::get<2>(item), true);
Patrick Williams3eedbe42017-05-31 17:27:05 -0500165 removeWatches.emplace_back(
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500166 std::make_unique<Remove>(bus, std::get<2>(item)));
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500167 }
168 }
Dhruvaraj Subhashchandranaebfde82017-07-11 01:36:33 -0500169
Patrick Williams3eedbe42017-05-31 17:27:05 -0500170 return;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500171}
172
Patrick Williams3eedbe42017-05-31 17:27:05 -0500173void Remove::removed(sdbusplus::message::message& msg)
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500174{
Patrick Williams3eedbe42017-05-31 17:27:05 -0500175 auto bus = msg.get_bus();
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500176 std::string assoc;
Patrick Williams3eedbe42017-05-31 17:27:05 -0500177 msg.read(assoc);
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500178
179 if (assoc.compare("org.openbmc.Association"))
180 {
181 //Skip if not about association
Patrick Williams3eedbe42017-05-31 17:27:05 -0500182 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500183 }
184
185 std::map<std::string, std::vector<std::string>> endPoints;
Patrick Williams3eedbe42017-05-31 17:27:05 -0500186 msg.read(endPoints);
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500187 auto it = endPoints.find("endpoints");
188
189 if (it == endPoints.end())
190 {
191 //No end points,skip
Patrick Williams3eedbe42017-05-31 17:27:05 -0500192 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500193 }
194
195 if (!((*it).second.empty()))
196 {
197 //Skip, end points are not empty
Patrick Williams3eedbe42017-05-31 17:27:05 -0500198 return;
Dhruvaraj Subhashchandran3c6f29a2017-04-20 09:47:28 -0500199 }
200
Patrick Williams3eedbe42017-05-31 17:27:05 -0500201 action(bus, inventoryPath, false);
202 return;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500203}
204
205}//namespace monitor
206}//namespace fault
207}//namespace fru
208}//namespace led
209}//namespace phosphor