#pragma once #include "utility.hpp" #include #include #include #include #include namespace phosphor::fan::monitor { /** * @class FFDCFile * * This class holds a file that is used for event log FFDC * which needs a file descriptor as input. The file is * deleted upon destruction. */ class FFDCFile { public: FFDCFile() = delete; FFDCFile(const FFDCFile&) = delete; FFDCFile& operator=(const FFDCFile&) = delete; FFDCFile(FFDCFile&&) = delete; FFDCFile& operator=(FFDCFile&&) = delete; /** * @brief Constructor * * Opens the file and saves the descriptor * * @param[in] name - The filename */ explicit FFDCFile(const std::filesystem::path& name); /** * @brief Destructor - Deletes the file */ ~FFDCFile() { std::filesystem::remove(_name); } /** * @brief Returns the file descriptor * * @return int - The descriptor */ int fd() { return _fd(); } private: /** * @brief The file descriptor holder */ util::FileDescriptor _fd; /** * @brief The filename */ const std::filesystem::path _name; }; /** * @class FanError * * This class represents a fan error. It has a commit() interface * that will create the event log with certain FFDC. */ class FanError { public: FanError() = delete; ~FanError() = default; FanError(const FanError&) = delete; FanError& operator=(const FanError&) = delete; FanError(FanError&&) = delete; FanError& operator=(FanError&&) = delete; /** * @brief Constructor * * @param[in] error - The error name, like * xyz.openbmc_project.Fan.Error.Fault * @param[in] fan - The failing fan's inventory path * @param[in] sensor - The failing sensor's inventory path. Can be empty * if the error is for the FRU and not the sensor. * @param[in] severity - The severity of the error */ FanError(const std::string& error, const std::string& fan, const std::string& sensor, sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity) : _errorName(error), _fanName(fan), _sensorName(sensor), _severity( sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage( severity)) {} /** * @brief Commits the error by calling the D-Bus method to create * the event log. * * The FFDC is passed in here so that if an error is committed * more than once it can have up to date FFDC. * * @param[in] jsonFFDC - Free form JSON data that should be sent in as * FFDC. */ void commit(const nlohmann::json& jsonFFDC); private: /** * @brief Returns an FFDCFile holding the Logger contents * * @return std::unique_ptr - The file object */ std::unique_ptr makeLogFFDCFile(); /** * @brief Returns an FFDCFile holding the contents of the JSON FFDC * * @param[in] ffdcData - The JSON data to write to a file * * @return std::unique_ptr - The file object */ std::unique_ptr makeJsonFFDCFile(const nlohmann::json& ffdcData); /** * @brief Create and returns the AdditionalData property to use for the * event log. * * @return map - The AdditionalData contents */ std::map getAdditionalData(); /** * @brief The error name (The event log's 'Message' property) */ const std::string _errorName; /** * @brief The inventory name of the failing fan */ const std::string _fanName; /** * @brief The inventory name of the failing sensor, if there is one. */ const std::string _sensorName; /** * @brief The severity of the event log. This is the string * representation of the Entry::Level property. */ const std::string _severity; }; } // namespace phosphor::fan::monitor