191ac8d3aSPatrick Venture #include "fru-fault-monitor.hpp" 291ac8d3aSPatrick Venture 391ac8d3aSPatrick Venture #include "elog-errors.hpp" 491ac8d3aSPatrick Venture 591ac8d3aSPatrick Venture #include <phosphor-logging/elog.hpp> 6e9fb5c6aSGeorge Liu #include <phosphor-logging/lg2.hpp> 791ac8d3aSPatrick Venture #include <sdbusplus/exception.hpp> 84b062010SGeorge Liu #include <xyz/openbmc_project/Led/Fru/Monitor/error.hpp> 94b062010SGeorge Liu #include <xyz/openbmc_project/Led/Mapper/error.hpp> 103c6f29a0SDhruvaraj Subhashchandran 1159b86cd7SDhruvaraj Subhashchandran namespace phosphor 1259b86cd7SDhruvaraj Subhashchandran { 1359b86cd7SDhruvaraj Subhashchandran namespace led 1459b86cd7SDhruvaraj Subhashchandran { 1559b86cd7SDhruvaraj Subhashchandran namespace fru 1659b86cd7SDhruvaraj Subhashchandran { 1759b86cd7SDhruvaraj Subhashchandran namespace fault 1859b86cd7SDhruvaraj Subhashchandran { 1959b86cd7SDhruvaraj Subhashchandran namespace monitor 2059b86cd7SDhruvaraj Subhashchandran { 2159b86cd7SDhruvaraj Subhashchandran 223c6f29a0SDhruvaraj Subhashchandran using namespace phosphor::logging; 233c6f29a0SDhruvaraj Subhashchandran 243c6f29a0SDhruvaraj Subhashchandran constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; 253c6f29a0SDhruvaraj Subhashchandran constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; 263c6f29a0SDhruvaraj Subhashchandran constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; 273c6f29a0SDhruvaraj Subhashchandran constexpr auto OBJMGR_IFACE = "org.freedesktop.DBus.ObjectManager"; 283c6f29a0SDhruvaraj Subhashchandran constexpr auto LED_GROUPS = "/xyz/openbmc_project/led/groups/"; 293c6f29a0SDhruvaraj Subhashchandran constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; 30891c4769SDhruvaraj Subhashchandran constexpr auto LOG_IFACE = "xyz.openbmc_project.Logging.Entry"; 313c6f29a0SDhruvaraj Subhashchandran 3291ac8d3aSPatrick Venture using AssociationList = 3391ac8d3aSPatrick Venture std::vector<std::tuple<std::string, std::string, std::string>>; 34a41d282aSPatrick Williams using Attributes = std::variant<bool, AssociationList>; 35aebfde81SDhruvaraj Subhashchandran using PropertyName = std::string; 36b2f253b7SMatt Spinler using PropertyMap = std::map<PropertyName, Attributes>; 37b2f253b7SMatt Spinler using InterfaceName = std::string; 38b2f253b7SMatt Spinler using InterfaceMap = std::map<InterfaceName, PropertyMap>; 39aebfde81SDhruvaraj Subhashchandran 40891c4769SDhruvaraj Subhashchandran using Service = std::string; 41891c4769SDhruvaraj Subhashchandran using Path = std::string; 42891c4769SDhruvaraj Subhashchandran using Interface = std::string; 43891c4769SDhruvaraj Subhashchandran using Interfaces = std::vector<Interface>; 44891c4769SDhruvaraj Subhashchandran using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>; 45891c4769SDhruvaraj Subhashchandran 463c6f29a0SDhruvaraj Subhashchandran using MethodErr = 473c6f29a0SDhruvaraj Subhashchandran sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError; 483c6f29a0SDhruvaraj Subhashchandran using ObjectNotFoundErr = 493c6f29a0SDhruvaraj Subhashchandran sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError; 5091ac8d3aSPatrick Venture using InventoryPathErr = sdbusplus::xyz::openbmc_project::Led::Fru::Monitor:: 5191ac8d3aSPatrick Venture Error::InventoryPathError; 523c6f29a0SDhruvaraj Subhashchandran 5391ac8d3aSPatrick Venture std::string getService(sdbusplus::bus::bus& bus, const std::string& path) 543c6f29a0SDhruvaraj Subhashchandran { 5591ac8d3aSPatrick Venture auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_OBJ_PATH, 563c6f29a0SDhruvaraj Subhashchandran MAPPER_IFACE, "GetObject"); 573c6f29a0SDhruvaraj Subhashchandran mapper.append(path.c_str(), std::vector<std::string>({OBJMGR_IFACE})); 583c6f29a0SDhruvaraj Subhashchandran 593c6f29a0SDhruvaraj Subhashchandran std::map<std::string, std::vector<std::string>> mapperResponse; 60151122aaSWilliam A. Kennington III try 61151122aaSWilliam A. Kennington III { 62d78de14dSGeorge Liu auto mapperResponseMsg = bus.call(mapper); 633c6f29a0SDhruvaraj Subhashchandran mapperResponseMsg.read(mapperResponse); 64151122aaSWilliam A. Kennington III } 657152edcfSPatrick Williams catch (const sdbusplus::exception::exception& e) 66151122aaSWilliam A. Kennington III { 67e9fb5c6aSGeorge Liu lg2::error( 68e9fb5c6aSGeorge Liu "Failed to parse getService mapper response, ERROR = {ERROR}", 69e9fb5c6aSGeorge Liu "ERROR", e); 70151122aaSWilliam A. Kennington III using namespace xyz::openbmc_project::Led::Mapper; 7191ac8d3aSPatrick Venture elog<ObjectNotFoundErr>(ObjectNotFoundError::METHOD_NAME("GetObject"), 72151122aaSWilliam A. Kennington III ObjectNotFoundError::PATH(path.c_str()), 7391ac8d3aSPatrick Venture ObjectNotFoundError::INTERFACE(OBJMGR_IFACE)); 74151122aaSWilliam A. Kennington III } 753c6f29a0SDhruvaraj Subhashchandran if (mapperResponse.empty()) 763c6f29a0SDhruvaraj Subhashchandran { 773c6f29a0SDhruvaraj Subhashchandran using namespace xyz::openbmc_project::Led::Mapper; 7891ac8d3aSPatrick Venture elog<ObjectNotFoundErr>(ObjectNotFoundError::METHOD_NAME("GetObject"), 793c6f29a0SDhruvaraj Subhashchandran ObjectNotFoundError::PATH(path.c_str()), 8091ac8d3aSPatrick Venture ObjectNotFoundError::INTERFACE(OBJMGR_IFACE)); 81*c5e0f31cSGeorge Liu return {}; 823c6f29a0SDhruvaraj Subhashchandran } 833c6f29a0SDhruvaraj Subhashchandran 843c6f29a0SDhruvaraj Subhashchandran return mapperResponse.cbegin()->first; 853c6f29a0SDhruvaraj Subhashchandran } 863c6f29a0SDhruvaraj Subhashchandran 8791ac8d3aSPatrick Venture void action(sdbusplus::bus::bus& bus, const std::string& path, bool assert) 8859b86cd7SDhruvaraj Subhashchandran { 893c6f29a0SDhruvaraj Subhashchandran std::string service; 903c6f29a0SDhruvaraj Subhashchandran try 913c6f29a0SDhruvaraj Subhashchandran { 92e77b8345SMatt Spinler std::string groups{LED_GROUPS}; 93e77b8345SMatt Spinler groups.pop_back(); 94e77b8345SMatt Spinler service = getService(bus, groups); 953c6f29a0SDhruvaraj Subhashchandran } 96fb56fde0SPatrick Williams catch (const MethodErr& e) 973c6f29a0SDhruvaraj Subhashchandran { 983c6f29a0SDhruvaraj Subhashchandran commit<MethodErr>(); 993c6f29a0SDhruvaraj Subhashchandran return; 1003c6f29a0SDhruvaraj Subhashchandran } 101fb56fde0SPatrick Williams catch (const ObjectNotFoundErr& e) 1023c6f29a0SDhruvaraj Subhashchandran { 1033c6f29a0SDhruvaraj Subhashchandran commit<ObjectNotFoundErr>(); 1043c6f29a0SDhruvaraj Subhashchandran return; 1053c6f29a0SDhruvaraj Subhashchandran } 1063c6f29a0SDhruvaraj Subhashchandran 1073c6f29a0SDhruvaraj Subhashchandran auto pos = path.rfind("/"); 1083c6f29a0SDhruvaraj Subhashchandran if (pos == std::string::npos) 1093c6f29a0SDhruvaraj Subhashchandran { 1103c6f29a0SDhruvaraj Subhashchandran using namespace xyz::openbmc_project::Led::Fru::Monitor; 11191ac8d3aSPatrick Venture report<InventoryPathErr>(InventoryPathError::PATH(path.c_str())); 1123c6f29a0SDhruvaraj Subhashchandran return; 1133c6f29a0SDhruvaraj Subhashchandran } 1143c6f29a0SDhruvaraj Subhashchandran auto unit = path.substr(pos + 1); 1153c6f29a0SDhruvaraj Subhashchandran 11691ac8d3aSPatrick Venture std::string ledPath = LED_GROUPS + unit + '_' + LED_FAULT; 1173c6f29a0SDhruvaraj Subhashchandran 11891ac8d3aSPatrick Venture auto method = bus.new_method_call(service.c_str(), ledPath.c_str(), 11991ac8d3aSPatrick Venture "org.freedesktop.DBus.Properties", "Set"); 1203c6f29a0SDhruvaraj Subhashchandran method.append("xyz.openbmc_project.Led.Group"); 1213c6f29a0SDhruvaraj Subhashchandran method.append("Asserted"); 1223c6f29a0SDhruvaraj Subhashchandran 123a41d282aSPatrick Williams method.append(std::variant<bool>(assert)); 12408d613e7SAdriana Kobylak 12508d613e7SAdriana Kobylak try 12608d613e7SAdriana Kobylak { 1273c6f29a0SDhruvaraj Subhashchandran bus.call_noreply(method); 12808d613e7SAdriana Kobylak } 1297152edcfSPatrick Williams catch (const sdbusplus::exception::exception& e) 13008d613e7SAdriana Kobylak { 13108d613e7SAdriana Kobylak // Log an info message, system may not have all the LED Groups defined 132e9fb5c6aSGeorge Liu lg2::info("Failed to Assert LED Group, ERROR = {ERROR}", "ERROR", e); 13308d613e7SAdriana Kobylak } 1343c6f29a0SDhruvaraj Subhashchandran 13559b86cd7SDhruvaraj Subhashchandran return; 13659b86cd7SDhruvaraj Subhashchandran } 13759b86cd7SDhruvaraj Subhashchandran 1383eedbe44SPatrick Williams void Add::created(sdbusplus::message::message& msg) 13959b86cd7SDhruvaraj Subhashchandran { 1403eedbe44SPatrick Williams auto bus = msg.get_bus(); 1413c6f29a0SDhruvaraj Subhashchandran 142b2f253b7SMatt Spinler sdbusplus::message::object_path objectPath; 143b2f253b7SMatt Spinler InterfaceMap interfaces; 144151122aaSWilliam A. Kennington III try 145151122aaSWilliam A. Kennington III { 146b2f253b7SMatt Spinler msg.read(objectPath, interfaces); 147151122aaSWilliam A. Kennington III } 1487152edcfSPatrick Williams catch (const sdbusplus::exception::exception& e) 149151122aaSWilliam A. Kennington III { 150e9fb5c6aSGeorge Liu lg2::error("Failed to parse created message, ERROR = {ERROR}", "ERROR", 151e9fb5c6aSGeorge Liu e); 152151122aaSWilliam A. Kennington III return; 153151122aaSWilliam A. Kennington III } 1543c6f29a0SDhruvaraj Subhashchandran 155b2f253b7SMatt Spinler std::size_t found = objectPath.str.find(ELOG_ENTRY); 1563c6f29a0SDhruvaraj Subhashchandran if (found == std::string::npos) 1573c6f29a0SDhruvaraj Subhashchandran { 1583c6f29a0SDhruvaraj Subhashchandran // Not a new error entry skip 1593eedbe44SPatrick Williams return; 1603c6f29a0SDhruvaraj Subhashchandran } 161a6e48929SAndrew Geissler auto iter = interfaces.find("xyz.openbmc_project.Association.Definitions"); 162b2f253b7SMatt Spinler if (iter == interfaces.end()) 1633c6f29a0SDhruvaraj Subhashchandran { 1643eedbe44SPatrick Williams return; 1653c6f29a0SDhruvaraj Subhashchandran } 1663c6f29a0SDhruvaraj Subhashchandran 1673d2b0d62SMatt Spinler // Nothing else shows when a specific error log 1683d2b0d62SMatt Spinler // has been created. Do it here. 169e9fb5c6aSGeorge Liu // TODO:(phosphor-logging#25): support sdbusplus::message::object_path 170e9fb5c6aSGeorge Liu // directly. 171e9fb5c6aSGeorge Liu lg2::info("{PATH} created", "PATH", objectPath.str); 1723d2b0d62SMatt Spinler 173a6e48929SAndrew Geissler auto attr = iter->second.find("Associations"); 174aebfde81SDhruvaraj Subhashchandran if (attr == iter->second.end()) 1753c6f29a0SDhruvaraj Subhashchandran { 1763eedbe44SPatrick Williams return; 1773c6f29a0SDhruvaraj Subhashchandran } 1783c6f29a0SDhruvaraj Subhashchandran 1795ebebeffSPatrick Williams auto& assocs = std::get<AssociationList>(attr->second); 1803c6f29a0SDhruvaraj Subhashchandran if (assocs.empty()) 1813c6f29a0SDhruvaraj Subhashchandran { 1823c6f29a0SDhruvaraj Subhashchandran // No associations skip 1833eedbe44SPatrick Williams return; 1843c6f29a0SDhruvaraj Subhashchandran } 1853c6f29a0SDhruvaraj Subhashchandran 1863c6f29a0SDhruvaraj Subhashchandran for (const auto& item : assocs) 1873c6f29a0SDhruvaraj Subhashchandran { 1883c6f29a0SDhruvaraj Subhashchandran if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) 1893c6f29a0SDhruvaraj Subhashchandran { 1903eedbe44SPatrick Williams removeWatches.emplace_back( 1913c6f29a0SDhruvaraj Subhashchandran std::make_unique<Remove>(bus, std::get<2>(item))); 192891c4769SDhruvaraj Subhashchandran action(bus, std::get<2>(item), true); 1933c6f29a0SDhruvaraj Subhashchandran } 1943c6f29a0SDhruvaraj Subhashchandran } 195aebfde81SDhruvaraj Subhashchandran 1963eedbe44SPatrick Williams return; 19759b86cd7SDhruvaraj Subhashchandran } 19859b86cd7SDhruvaraj Subhashchandran 19991122927SMatt Spinler void getLoggingSubTree(sdbusplus::bus::bus& bus, MapperResponseType& subtree) 200891c4769SDhruvaraj Subhashchandran { 201891c4769SDhruvaraj Subhashchandran auto depth = 0; 20291ac8d3aSPatrick Venture auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_OBJ_PATH, 20391ac8d3aSPatrick Venture MAPPER_IFACE, "GetSubTree"); 204891c4769SDhruvaraj Subhashchandran mapperCall.append("/"); 205891c4769SDhruvaraj Subhashchandran mapperCall.append(depth); 206891c4769SDhruvaraj Subhashchandran mapperCall.append(std::vector<Interface>({LOG_IFACE})); 207891c4769SDhruvaraj Subhashchandran 20891122927SMatt Spinler try 20991122927SMatt Spinler { 210891c4769SDhruvaraj Subhashchandran auto mapperResponseMsg = bus.call(mapperCall); 21191122927SMatt Spinler mapperResponseMsg.read(subtree); 212151122aaSWilliam A. Kennington III } 2137152edcfSPatrick Williams catch (const sdbusplus::exception::exception& e) 214151122aaSWilliam A. Kennington III { 215e9fb5c6aSGeorge Liu lg2::error( 216e9fb5c6aSGeorge Liu "Failed to parse existing callouts subtree message, ERROR = {ERROR}", 217e9fb5c6aSGeorge Liu "ERROR", e); 21891122927SMatt Spinler } 21991122927SMatt Spinler } 22091122927SMatt Spinler 22191122927SMatt Spinler void Add::processExistingCallouts(sdbusplus::bus::bus& bus) 22291122927SMatt Spinler { 22391122927SMatt Spinler MapperResponseType mapperResponse; 22491122927SMatt Spinler 22591122927SMatt Spinler getLoggingSubTree(bus, mapperResponse); 226891c4769SDhruvaraj Subhashchandran if (mapperResponse.empty()) 227891c4769SDhruvaraj Subhashchandran { 228fc30e0c1SDhruvaraj Subhashchandran // No errors to process. 229891c4769SDhruvaraj Subhashchandran return; 230891c4769SDhruvaraj Subhashchandran } 231891c4769SDhruvaraj Subhashchandran 232891c4769SDhruvaraj Subhashchandran for (const auto& elem : mapperResponse) 233891c4769SDhruvaraj Subhashchandran { 23491ac8d3aSPatrick Venture auto method = bus.new_method_call( 23591ac8d3aSPatrick Venture elem.second.begin()->first.c_str(), elem.first.c_str(), 23691ac8d3aSPatrick Venture "org.freedesktop.DBus.Properties", "Get"); 237a6e48929SAndrew Geissler method.append("xyz.openbmc_project.Association.Definitions"); 238a6e48929SAndrew Geissler method.append("Associations"); 239891c4769SDhruvaraj Subhashchandran auto reply = bus.call(method); 240891c4769SDhruvaraj Subhashchandran if (reply.is_method_error()) 241891c4769SDhruvaraj Subhashchandran { 242891c4769SDhruvaraj Subhashchandran // do not stop, continue with next elog 243e9fb5c6aSGeorge Liu lg2::error("Error in getting associations"); 244891c4769SDhruvaraj Subhashchandran continue; 245891c4769SDhruvaraj Subhashchandran } 246891c4769SDhruvaraj Subhashchandran 247a41d282aSPatrick Williams std::variant<AssociationList> assoc; 248151122aaSWilliam A. Kennington III try 249151122aaSWilliam A. Kennington III { 250891c4769SDhruvaraj Subhashchandran reply.read(assoc); 251151122aaSWilliam A. Kennington III } 2527152edcfSPatrick Williams catch (const sdbusplus::exception::exception& e) 253151122aaSWilliam A. Kennington III { 254e9fb5c6aSGeorge Liu lg2::error( 255e9fb5c6aSGeorge Liu "Failed to parse existing callouts associations message, ERROR = {ERROR}", 256e9fb5c6aSGeorge Liu "ERROR", e); 257151122aaSWilliam A. Kennington III continue; 258151122aaSWilliam A. Kennington III } 2595ebebeffSPatrick Williams auto& assocs = std::get<AssociationList>(assoc); 260891c4769SDhruvaraj Subhashchandran if (assocs.empty()) 261891c4769SDhruvaraj Subhashchandran { 262891c4769SDhruvaraj Subhashchandran // no associations, skip 263891c4769SDhruvaraj Subhashchandran continue; 264891c4769SDhruvaraj Subhashchandran } 265891c4769SDhruvaraj Subhashchandran 266891c4769SDhruvaraj Subhashchandran for (const auto& item : assocs) 267891c4769SDhruvaraj Subhashchandran { 268891c4769SDhruvaraj Subhashchandran if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) 269891c4769SDhruvaraj Subhashchandran { 270891c4769SDhruvaraj Subhashchandran removeWatches.emplace_back( 271891c4769SDhruvaraj Subhashchandran std::make_unique<Remove>(bus, std::get<2>(item))); 272891c4769SDhruvaraj Subhashchandran action(bus, std::get<2>(item), true); 273891c4769SDhruvaraj Subhashchandran } 274891c4769SDhruvaraj Subhashchandran } 275891c4769SDhruvaraj Subhashchandran } 276891c4769SDhruvaraj Subhashchandran } 277891c4769SDhruvaraj Subhashchandran 2783eedbe44SPatrick Williams void Remove::removed(sdbusplus::message::message& msg) 27959b86cd7SDhruvaraj Subhashchandran { 2803eedbe44SPatrick Williams auto bus = msg.get_bus(); 2813c6f29a0SDhruvaraj Subhashchandran 2823eedbe44SPatrick Williams action(bus, inventoryPath, false); 2833eedbe44SPatrick Williams return; 28459b86cd7SDhruvaraj Subhashchandran } 28559b86cd7SDhruvaraj Subhashchandran 28659b86cd7SDhruvaraj Subhashchandran } // namespace monitor 28759b86cd7SDhruvaraj Subhashchandran } // namespace fault 28859b86cd7SDhruvaraj Subhashchandran } // namespace fru 28959b86cd7SDhruvaraj Subhashchandran } // namespace led 29059b86cd7SDhruvaraj Subhashchandran } // namespace phosphor 291