diff options
-rw-r--r-- | selutility.cpp | 32 | ||||
-rw-r--r-- | selutility.hpp | 10 |
2 files changed, 41 insertions, 1 deletions
diff --git a/selutility.cpp b/selutility.cpp index 0107515..3f9d9ab 100644 --- a/selutility.cpp +++ b/selutility.cpp @@ -182,6 +182,38 @@ GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath) return internal::prepareSELEntry(objPath, iter); } +std::chrono::seconds getEntryTimeStamp(const std::string& objPath) +{ + sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; + + auto service = ipmi::getService(bus, logEntryIntf, objPath); + + using namespace std::string_literals; + static const auto propTimeStamp = "Timestamp"s; + + auto methodCall = bus.new_method_call(service.c_str(), + objPath.c_str(), + propIntf, + "Get"); + methodCall.append(logEntryIntf); + methodCall.append(propTimeStamp); + + auto reply = bus.call(methodCall); + if (reply.is_method_error()) + { + log<level::ERR>("Error in reading Timestamp from Entry interface"); + elog<InternalFailure>(); + } + + sdbusplus::message::variant<uint64_t> timeStamp; + reply.read(timeStamp); + + std::chrono::milliseconds chronoTimeStamp( + sdbusplus::message::variant_ns::get<uint64_t>(timeStamp)); + + return std::chrono::duration_cast<std::chrono::seconds>(chronoTimeStamp); +} + } // namespace sel } // namespace ipmi diff --git a/selutility.hpp b/selutility.hpp index 573e89b..09104a3 100644 --- a/selutility.hpp +++ b/selutility.hpp @@ -51,6 +51,14 @@ struct GetSELEntryResponse */ GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath); +/** @brief Get the timestamp of the log entry + * + * @param[in] objPath - DBUS object path of the logging entry. + * + * @return On success return the timestamp of the log entry as number of + * seconds from epoch. + */ +std::chrono::seconds getEntryTimeStamp(const std::string& objPath); namespace internal { @@ -68,7 +76,7 @@ GetSELEntryResponse prepareSELEntry( const std::string& objPath, ipmi::sensor::InvObjectIDMap::const_iterator iter); -} //internal +} } // namespace sel |