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 | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 6 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace led |
| 10 | { |
| 11 | namespace fru |
| 12 | { |
| 13 | namespace fault |
| 14 | { |
| 15 | namespace monitor |
| 16 | { |
| 17 | |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 18 | using namespace phosphor::logging; |
| 19 | |
| 20 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 21 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 22 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 23 | constexpr auto OBJMGR_IFACE = "org.freedesktop.DBus.ObjectManager"; |
| 24 | constexpr auto LED_GROUPS = "/xyz/openbmc_project/led/groups/"; |
| 25 | constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; |
| 26 | |
| 27 | using AssociationList = std::vector<std::tuple< |
| 28 | std::string, std::string, std::string>>; |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 29 | using Attributes = sdbusplus::message::variant<bool,AssociationList>; |
| 30 | using AttributeName = std::string; |
| 31 | using AttributeMap = std::map<AttributeName, Attributes>; |
| 32 | using PropertyName = std::string; |
| 33 | using PropertyMap = std::map<PropertyName, AttributeMap>; |
| 34 | using LogEntryMsg = std::pair<sdbusplus::message::object_path, PropertyMap>; |
| 35 | |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 36 | using MethodErr = |
| 37 | sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError; |
| 38 | using ObjectNotFoundErr = |
| 39 | sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 40 | using InventoryPathErr = |
| 41 | sdbusplus::xyz::openbmc_project:: |
| 42 | Led::Fru::Monitor::Error::InventoryPathError; |
| 43 | |
| 44 | std::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 Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 77 | void action(sdbusplus::bus::bus& bus, |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 78 | const std::string& path, |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 79 | bool assert) |
| 80 | { |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 81 | 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 Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 124 | void Add::created(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 125 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 126 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 127 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 128 | LogEntryMsg logEntry; |
| 129 | msg.read(logEntry); |
| 130 | std::string objectPath(std::move(logEntry.first)); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 131 | |
| 132 | std::size_t found = objectPath.find(ELOG_ENTRY); |
| 133 | if (found == std::string::npos) |
| 134 | { |
| 135 | //Not a new error entry skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 136 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 137 | } |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 138 | log<level::ERR>(objectPath.c_str()); |
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 | auto iter = logEntry.second.find("org.openbmc.Associations"); |
| 141 | if (iter == logEntry.second.end()) |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 142 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 143 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 146 | auto attr = iter->second.find("associations"); |
| 147 | if (attr == iter->second.end()) |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 148 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 149 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 152 | auto& assocs = |
| 153 | sdbusplus::message::variant_ns::get<AssociationList>(attr->second); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 154 | if (assocs.empty()) |
| 155 | { |
| 156 | //No associations skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 157 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 158 | } |
| 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 Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 165 | removeWatches.emplace_back( |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 166 | std::make_unique<Remove>(bus, std::get<2>(item))); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 167 | } |
| 168 | } |
Dhruvaraj Subhashchandran | aebfde8 | 2017-07-11 01:36:33 -0500 | [diff] [blame^] | 169 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 170 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 173 | void Remove::removed(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 174 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 175 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 176 | std::string assoc; |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 177 | msg.read(assoc); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 178 | |
| 179 | if (assoc.compare("org.openbmc.Association")) |
| 180 | { |
| 181 | //Skip if not about association |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 182 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | std::map<std::string, std::vector<std::string>> endPoints; |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 186 | msg.read(endPoints); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 187 | auto it = endPoints.find("endpoints"); |
| 188 | |
| 189 | if (it == endPoints.end()) |
| 190 | { |
| 191 | //No end points,skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 192 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | if (!((*it).second.empty())) |
| 196 | { |
| 197 | //Skip, end points are not empty |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 198 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 201 | action(bus, inventoryPath, false); |
| 202 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | }//namespace monitor |
| 206 | }//namespace fault |
| 207 | }//namespace fru |
| 208 | }//namespace led |
| 209 | }//namespace phosphor |