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