Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 1 | #include <phosphor-logging/elog.hpp> |
William A. Kennington III | 151122a | 2018-05-15 12:00:32 -0700 | [diff] [blame] | 2 | #include <sdbusplus/exception.hpp> |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 3 | #include "xyz/openbmc_project/Led/Fru/Monitor/error.hpp" |
| 4 | #include "xyz/openbmc_project/Led/Mapper/error.hpp" |
| 5 | #include "elog-errors.hpp" |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 6 | #include "fru-fault-monitor.hpp" |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include "xyz/openbmc_project/Common/error.hpp" |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 9 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace led |
| 13 | { |
| 14 | namespace fru |
| 15 | { |
| 16 | namespace fault |
| 17 | { |
| 18 | namespace monitor |
| 19 | { |
| 20 | |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 21 | using namespace phosphor::logging; |
| 22 | |
| 23 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 24 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 25 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 26 | constexpr auto OBJMGR_IFACE = "org.freedesktop.DBus.ObjectManager"; |
| 27 | constexpr auto LED_GROUPS = "/xyz/openbmc_project/led/groups/"; |
| 28 | constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 29 | constexpr auto LOG_IFACE = "xyz.openbmc_project.Logging.Entry"; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 30 | |
| 31 | using AssociationList = std::vector<std::tuple< |
| 32 | std::string, std::string, std::string>>; |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 33 | using Attributes = sdbusplus::message::variant<bool,AssociationList>; |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 34 | using PropertyName = std::string; |
Matt Spinler | b2f253b | 2018-06-13 09:54:13 -0500 | [diff] [blame^] | 35 | using PropertyMap = std::map<PropertyName, Attributes>; |
| 36 | using InterfaceName = std::string; |
| 37 | using InterfaceMap = std::map<InterfaceName, PropertyMap>; |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 38 | |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 39 | using Service = std::string; |
| 40 | using Path = std::string; |
| 41 | using Interface = std::string; |
| 42 | using Interfaces = std::vector<Interface>; |
| 43 | using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>; |
| 44 | |
| 45 | using InternalFailure = |
| 46 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 47 | |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 48 | using MethodErr = |
| 49 | sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError; |
| 50 | using ObjectNotFoundErr = |
| 51 | sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 52 | using InventoryPathErr = |
| 53 | sdbusplus::xyz::openbmc_project:: |
| 54 | Led::Fru::Monitor::Error::InventoryPathError; |
| 55 | |
| 56 | std::string getService(sdbusplus::bus::bus& bus, |
| 57 | const std::string& path) |
| 58 | { |
| 59 | auto mapper = bus.new_method_call(MAPPER_BUSNAME, |
| 60 | MAPPER_OBJ_PATH, |
| 61 | MAPPER_IFACE, "GetObject"); |
| 62 | mapper.append(path.c_str(), std::vector<std::string>({OBJMGR_IFACE})); |
| 63 | auto mapperResponseMsg = bus.call(mapper); |
| 64 | if (mapperResponseMsg.is_method_error()) |
| 65 | { |
| 66 | using namespace xyz::openbmc_project::Led::Mapper; |
| 67 | elog<MethodErr>( |
| 68 | MethodError::METHOD_NAME("GetObject"), |
| 69 | MethodError::PATH(path.c_str()), |
| 70 | MethodError::INTERFACE( |
| 71 | OBJMGR_IFACE)); |
| 72 | } |
| 73 | |
| 74 | std::map<std::string, std::vector<std::string>> mapperResponse; |
William A. Kennington III | 151122a | 2018-05-15 12:00:32 -0700 | [diff] [blame] | 75 | try |
| 76 | { |
| 77 | mapperResponseMsg.read(mapperResponse); |
| 78 | } |
| 79 | catch (const sdbusplus::exception::SdBusError& e) |
| 80 | { |
| 81 | log<level::ERR>("Failed to parse getService mapper response", |
| 82 | entry("ERROR=%s", e.what()), |
| 83 | entry("REPLY_SIG=%s", mapperResponseMsg.get_signature())); |
| 84 | using namespace xyz::openbmc_project::Led::Mapper; |
| 85 | elog<ObjectNotFoundErr>( |
| 86 | ObjectNotFoundError::METHOD_NAME("GetObject"), |
| 87 | ObjectNotFoundError::PATH(path.c_str()), |
| 88 | ObjectNotFoundError::INTERFACE( |
| 89 | OBJMGR_IFACE)); |
| 90 | } |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 91 | if (mapperResponse.empty()) |
| 92 | { |
| 93 | using namespace xyz::openbmc_project::Led::Mapper; |
| 94 | elog<ObjectNotFoundErr>( |
| 95 | ObjectNotFoundError::METHOD_NAME("GetObject"), |
| 96 | ObjectNotFoundError::PATH(path.c_str()), |
| 97 | ObjectNotFoundError::INTERFACE( |
| 98 | OBJMGR_IFACE)); |
| 99 | } |
| 100 | |
| 101 | return mapperResponse.cbegin()->first; |
| 102 | } |
| 103 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 104 | void action(sdbusplus::bus::bus& bus, |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 105 | const std::string& path, |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 106 | bool assert) |
| 107 | { |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 108 | std::string service; |
| 109 | try |
| 110 | { |
| 111 | service = getService(bus, LED_GROUPS); |
| 112 | } |
| 113 | catch (MethodErr& e) |
| 114 | { |
| 115 | commit<MethodErr>(); |
| 116 | return; |
| 117 | } |
| 118 | catch (ObjectNotFoundErr& e) |
| 119 | { |
| 120 | commit<ObjectNotFoundErr>(); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | auto pos = path.rfind("/"); |
| 125 | if (pos == std::string::npos) |
| 126 | { |
| 127 | using namespace xyz::openbmc_project::Led::Fru::Monitor; |
| 128 | report<InventoryPathErr>( |
| 129 | InventoryPathError::PATH( |
| 130 | path.c_str())); |
| 131 | return; |
| 132 | } |
| 133 | auto unit = path.substr(pos + 1); |
| 134 | |
| 135 | std::string ledPath = LED_GROUPS + |
| 136 | unit + '_' + LED_FAULT; |
| 137 | |
| 138 | auto method = bus.new_method_call(service.c_str(), |
| 139 | ledPath.c_str(), |
| 140 | "org.freedesktop.DBus.Properties", |
| 141 | "Set"); |
| 142 | method.append("xyz.openbmc_project.Led.Group"); |
| 143 | method.append("Asserted"); |
| 144 | |
| 145 | method.append(sdbusplus::message::variant<bool>(assert)); |
| 146 | bus.call_noreply(method); |
| 147 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 148 | return; |
| 149 | } |
| 150 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 151 | void Add::created(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 152 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 153 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 154 | |
Matt Spinler | b2f253b | 2018-06-13 09:54:13 -0500 | [diff] [blame^] | 155 | sdbusplus::message::object_path objectPath; |
| 156 | InterfaceMap interfaces; |
William A. Kennington III | 151122a | 2018-05-15 12:00:32 -0700 | [diff] [blame] | 157 | try |
| 158 | { |
Matt Spinler | b2f253b | 2018-06-13 09:54:13 -0500 | [diff] [blame^] | 159 | msg.read(objectPath, interfaces); |
William A. Kennington III | 151122a | 2018-05-15 12:00:32 -0700 | [diff] [blame] | 160 | } |
| 161 | catch (const sdbusplus::exception::SdBusError& e) |
| 162 | { |
| 163 | log<level::ERR>("Failed to parse created message", |
| 164 | entry("ERROR=%s", e.what()), |
| 165 | entry("REPLY_SIG=%s", msg.get_signature())); |
| 166 | return; |
| 167 | } |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 168 | |
Matt Spinler | b2f253b | 2018-06-13 09:54:13 -0500 | [diff] [blame^] | 169 | std::size_t found = objectPath.str.find(ELOG_ENTRY); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 170 | if (found == std::string::npos) |
| 171 | { |
| 172 | //Not a new error entry skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 173 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 174 | } |
Matt Spinler | b2f253b | 2018-06-13 09:54:13 -0500 | [diff] [blame^] | 175 | auto iter = interfaces.find("org.openbmc.Associations"); |
| 176 | if (iter == interfaces.end()) |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 177 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 178 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 179 | } |
| 180 | |
Matt Spinler | 3d2b0d6 | 2018-03-29 08:48:37 -0500 | [diff] [blame] | 181 | //Nothing else shows when a specific error log |
| 182 | //has been created. Do it here. |
Matt Spinler | b2f253b | 2018-06-13 09:54:13 -0500 | [diff] [blame^] | 183 | std::string message{objectPath.str + " created"}; |
Matt Spinler | 3d2b0d6 | 2018-03-29 08:48:37 -0500 | [diff] [blame] | 184 | log<level::INFO>(message.c_str()); |
| 185 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 186 | auto attr = iter->second.find("associations"); |
| 187 | if (attr == iter->second.end()) |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 188 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 189 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 190 | } |
| 191 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 192 | auto& assocs = |
| 193 | sdbusplus::message::variant_ns::get<AssociationList>(attr->second); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 194 | if (assocs.empty()) |
| 195 | { |
| 196 | //No associations skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 197 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | for (const auto& item : assocs) |
| 201 | { |
| 202 | if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) |
| 203 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 204 | removeWatches.emplace_back( |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 205 | std::make_unique<Remove>(bus, std::get<2>(item))); |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 206 | action(bus, std::get<2>(item), true); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 207 | } |
| 208 | } |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 209 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 210 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 211 | } |
| 212 | |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 213 | void Add::processExistingCallouts(sdbusplus::bus::bus& bus) |
| 214 | { |
| 215 | auto depth = 0; |
| 216 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, |
| 217 | MAPPER_OBJ_PATH, |
| 218 | MAPPER_IFACE, |
| 219 | "GetSubTree"); |
| 220 | mapperCall.append("/"); |
| 221 | mapperCall.append(depth); |
| 222 | mapperCall.append(std::vector<Interface>({LOG_IFACE})); |
| 223 | |
| 224 | auto mapperResponseMsg = bus.call(mapperCall); |
| 225 | if (mapperResponseMsg.is_method_error()) |
| 226 | { |
| 227 | using namespace xyz::openbmc_project::Led::Mapper; |
| 228 | report<MethodErr>( |
| 229 | MethodError::METHOD_NAME("GetSubTree"), |
| 230 | MethodError::PATH(MAPPER_OBJ_PATH), |
| 231 | MethodError::INTERFACE( |
| 232 | OBJMGR_IFACE)); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | MapperResponseType mapperResponse; |
William A. Kennington III | 151122a | 2018-05-15 12:00:32 -0700 | [diff] [blame] | 237 | try |
| 238 | { |
| 239 | mapperResponseMsg.read(mapperResponse); |
| 240 | } |
| 241 | catch (const sdbusplus::exception::SdBusError& e) |
| 242 | { |
| 243 | log<level::ERR>("Failed to parse existing callouts subtree message", |
| 244 | entry("ERROR=%s", e.what()), |
| 245 | entry("REPLY_SIG=%s", mapperResponseMsg.get_signature())); |
| 246 | return; |
| 247 | } |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 248 | if (mapperResponse.empty()) |
| 249 | { |
Dhruvaraj Subhashchandran | fc30e0c | 2017-09-19 03:59:08 -0500 | [diff] [blame] | 250 | //No errors to process. |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | |
| 254 | for (const auto& elem : mapperResponse) |
| 255 | { |
| 256 | auto method = bus.new_method_call(elem.second.begin()->first.c_str(), |
| 257 | elem.first.c_str(), |
| 258 | "org.freedesktop.DBus.Properties", |
| 259 | "Get"); |
| 260 | method.append("org.openbmc.Associations"); |
| 261 | method.append("associations"); |
| 262 | auto reply = bus.call(method); |
| 263 | if (reply.is_method_error()) |
| 264 | { |
| 265 | //do not stop, continue with next elog |
| 266 | log<level::ERR>("Error in getting associations"); |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | sdbusplus::message::variant<AssociationList> assoc; |
William A. Kennington III | 151122a | 2018-05-15 12:00:32 -0700 | [diff] [blame] | 271 | try |
| 272 | { |
| 273 | reply.read(assoc); |
| 274 | } |
| 275 | catch (const sdbusplus::exception::SdBusError& e) |
| 276 | { |
| 277 | log<level::ERR>("Failed to parse existing callouts associations message", |
| 278 | entry("ERROR=%s", e.what()), |
| 279 | entry("REPLY_SIG=%s", reply.get_signature())); |
| 280 | continue; |
| 281 | } |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 282 | auto& assocs = assoc.get<AssociationList>(); |
| 283 | if (assocs.empty()) |
| 284 | { |
| 285 | //no associations, skip |
| 286 | continue; |
| 287 | } |
| 288 | |
| 289 | for (const auto& item : assocs) |
| 290 | { |
| 291 | if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) |
| 292 | { |
| 293 | removeWatches.emplace_back( |
| 294 | std::make_unique<Remove>(bus, std::get<2>(item))); |
| 295 | action(bus, std::get<2>(item), true); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 301 | void Remove::removed(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 302 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 303 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 304 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 305 | action(bus, inventoryPath, false); |
| 306 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | }//namespace monitor |
| 310 | }//namespace fault |
| 311 | }//namespace fru |
| 312 | }//namespace led |
| 313 | }//namespace phosphor |