Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 1 | #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 Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 5 | #include "fru-fault-monitor.hpp" |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/elog-errors.hpp> |
| 7 | #include "xyz/openbmc_project/Common/error.hpp" |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 8 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
| 11 | namespace led |
| 12 | { |
| 13 | namespace fru |
| 14 | { |
| 15 | namespace fault |
| 16 | { |
| 17 | namespace monitor |
| 18 | { |
| 19 | |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 20 | using namespace phosphor::logging; |
| 21 | |
| 22 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 23 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 24 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 25 | constexpr auto OBJMGR_IFACE = "org.freedesktop.DBus.ObjectManager"; |
| 26 | constexpr auto LED_GROUPS = "/xyz/openbmc_project/led/groups/"; |
| 27 | constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 28 | constexpr auto LOG_IFACE = "xyz.openbmc_project.Logging.Entry"; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 29 | |
| 30 | using AssociationList = std::vector<std::tuple< |
| 31 | std::string, std::string, std::string>>; |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 32 | using Attributes = sdbusplus::message::variant<bool,AssociationList>; |
| 33 | using AttributeName = std::string; |
| 34 | using AttributeMap = std::map<AttributeName, Attributes>; |
| 35 | using PropertyName = std::string; |
| 36 | using PropertyMap = std::map<PropertyName, AttributeMap>; |
| 37 | using LogEntryMsg = std::pair<sdbusplus::message::object_path, PropertyMap>; |
| 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; |
| 75 | mapperResponseMsg.read(mapperResponse); |
| 76 | if (mapperResponse.empty()) |
| 77 | { |
| 78 | using namespace xyz::openbmc_project::Led::Mapper; |
| 79 | elog<ObjectNotFoundErr>( |
| 80 | ObjectNotFoundError::METHOD_NAME("GetObject"), |
| 81 | ObjectNotFoundError::PATH(path.c_str()), |
| 82 | ObjectNotFoundError::INTERFACE( |
| 83 | OBJMGR_IFACE)); |
| 84 | } |
| 85 | |
| 86 | return mapperResponse.cbegin()->first; |
| 87 | } |
| 88 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 89 | void action(sdbusplus::bus::bus& bus, |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 90 | const std::string& path, |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 91 | bool assert) |
| 92 | { |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 93 | std::string service; |
| 94 | try |
| 95 | { |
| 96 | service = getService(bus, LED_GROUPS); |
| 97 | } |
| 98 | catch (MethodErr& e) |
| 99 | { |
| 100 | commit<MethodErr>(); |
| 101 | return; |
| 102 | } |
| 103 | catch (ObjectNotFoundErr& e) |
| 104 | { |
| 105 | commit<ObjectNotFoundErr>(); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | auto pos = path.rfind("/"); |
| 110 | if (pos == std::string::npos) |
| 111 | { |
| 112 | using namespace xyz::openbmc_project::Led::Fru::Monitor; |
| 113 | report<InventoryPathErr>( |
| 114 | InventoryPathError::PATH( |
| 115 | path.c_str())); |
| 116 | return; |
| 117 | } |
| 118 | auto unit = path.substr(pos + 1); |
| 119 | |
| 120 | std::string ledPath = LED_GROUPS + |
| 121 | unit + '_' + LED_FAULT; |
| 122 | |
| 123 | auto method = bus.new_method_call(service.c_str(), |
| 124 | ledPath.c_str(), |
| 125 | "org.freedesktop.DBus.Properties", |
| 126 | "Set"); |
| 127 | method.append("xyz.openbmc_project.Led.Group"); |
| 128 | method.append("Asserted"); |
| 129 | |
| 130 | method.append(sdbusplus::message::variant<bool>(assert)); |
| 131 | bus.call_noreply(method); |
| 132 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 136 | void Add::created(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 137 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 138 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 139 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 140 | LogEntryMsg logEntry; |
| 141 | msg.read(logEntry); |
| 142 | std::string objectPath(std::move(logEntry.first)); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 143 | |
| 144 | std::size_t found = objectPath.find(ELOG_ENTRY); |
| 145 | if (found == std::string::npos) |
| 146 | { |
| 147 | //Not a new error entry skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 148 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 149 | } |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 150 | auto iter = logEntry.second.find("org.openbmc.Associations"); |
| 151 | if (iter == logEntry.second.end()) |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 152 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 153 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 154 | } |
| 155 | |
Matt Spinler | 3d2b0d6 | 2018-03-29 08:48:37 -0500 | [diff] [blame] | 156 | //Nothing else shows when a specific error log |
| 157 | //has been created. Do it here. |
| 158 | std::string message{objectPath + " created"}; |
| 159 | log<level::INFO>(message.c_str()); |
| 160 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 161 | auto attr = iter->second.find("associations"); |
| 162 | if (attr == iter->second.end()) |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 163 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 164 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 167 | auto& assocs = |
| 168 | sdbusplus::message::variant_ns::get<AssociationList>(attr->second); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 169 | if (assocs.empty()) |
| 170 | { |
| 171 | //No associations skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 172 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | for (const auto& item : assocs) |
| 176 | { |
| 177 | if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) |
| 178 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 179 | removeWatches.emplace_back( |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 180 | std::make_unique<Remove>(bus, std::get<2>(item))); |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 181 | action(bus, std::get<2>(item), true); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 182 | } |
| 183 | } |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame] | 184 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 185 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 188 | void Add::processExistingCallouts(sdbusplus::bus::bus& bus) |
| 189 | { |
| 190 | auto depth = 0; |
| 191 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, |
| 192 | MAPPER_OBJ_PATH, |
| 193 | MAPPER_IFACE, |
| 194 | "GetSubTree"); |
| 195 | mapperCall.append("/"); |
| 196 | mapperCall.append(depth); |
| 197 | mapperCall.append(std::vector<Interface>({LOG_IFACE})); |
| 198 | |
| 199 | auto mapperResponseMsg = bus.call(mapperCall); |
| 200 | if (mapperResponseMsg.is_method_error()) |
| 201 | { |
| 202 | using namespace xyz::openbmc_project::Led::Mapper; |
| 203 | report<MethodErr>( |
| 204 | MethodError::METHOD_NAME("GetSubTree"), |
| 205 | MethodError::PATH(MAPPER_OBJ_PATH), |
| 206 | MethodError::INTERFACE( |
| 207 | OBJMGR_IFACE)); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | MapperResponseType mapperResponse; |
| 212 | mapperResponseMsg.read(mapperResponse); |
| 213 | if (mapperResponse.empty()) |
| 214 | { |
Dhruvaraj Subhashchandran | fc30e0c | 2017-09-19 03:59:08 -0500 | [diff] [blame] | 215 | //No errors to process. |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 216 | return; |
| 217 | } |
| 218 | |
| 219 | for (const auto& elem : mapperResponse) |
| 220 | { |
| 221 | auto method = bus.new_method_call(elem.second.begin()->first.c_str(), |
| 222 | elem.first.c_str(), |
| 223 | "org.freedesktop.DBus.Properties", |
| 224 | "Get"); |
| 225 | method.append("org.openbmc.Associations"); |
| 226 | method.append("associations"); |
| 227 | auto reply = bus.call(method); |
| 228 | if (reply.is_method_error()) |
| 229 | { |
| 230 | //do not stop, continue with next elog |
| 231 | log<level::ERR>("Error in getting associations"); |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | sdbusplus::message::variant<AssociationList> assoc; |
| 236 | reply.read(assoc); |
| 237 | auto& assocs = assoc.get<AssociationList>(); |
| 238 | if (assocs.empty()) |
| 239 | { |
| 240 | //no associations, skip |
| 241 | continue; |
| 242 | } |
| 243 | |
| 244 | for (const auto& item : assocs) |
| 245 | { |
| 246 | if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) |
| 247 | { |
| 248 | removeWatches.emplace_back( |
| 249 | std::make_unique<Remove>(bus, std::get<2>(item))); |
| 250 | action(bus, std::get<2>(item), true); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 256 | void Remove::removed(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 257 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 258 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 259 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 260 | action(bus, inventoryPath, false); |
| 261 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | }//namespace monitor |
| 265 | }//namespace fault |
| 266 | }//namespace fru |
| 267 | }//namespace led |
| 268 | }//namespace phosphor |