diff options
author | Andrew Geissler <geissonator@yahoo.com> | 2018-08-17 17:56:14 +0300 |
---|---|---|
committer | Anthony Wilson <wilsonan@us.ibm.com> | 2019-04-05 00:50:05 +0300 |
commit | cb92c03b1a8798657b9e03602e1ae851b2614e77 (patch) | |
tree | e0c4a9939a68cf15d1e508819e09daf7b2d1b9e8 /crow | |
parent | 61adbda37aa63ae77585797587a7b4b6c3b61b25 (diff) | |
download | bmcweb-cb92c03b1a8798657b9e03602e1ae851b2614e77.tar.xz |
Initial redfish logging support
This was imported from a fork:
https://github.com/ampere-openbmc/bmcweb/commits/ampere-next/redfish-core/lib/logservices.hpp
Which had a series of commits from TungVuX and hyche
The initial patch is that code verbatim.
Follow up patches on top of this make the necessary changes
for current bmcweb:
- Move to sdbusplus
- C++ naming convention changes
- Clang format
- Some refactoring
Tested:
Verified new services work correctly when queried
e.g. curl -k -H "X-Auth-Token: $bmc_token" -X GET \
https://${bmc}/redfish/v1/Systems/system/LogServices/EventLog/Entries
displays the entries properly.
RedfishServiceValidator results:
/redfish/v1/Systems/system/LogServices
pass: 3
passGet: 1
skipOptional: 1
/redfish/v1/Systems/system/LogServices/EventLog
pass: 5
passGet: 1
skipOptional: 8
/redfish/v1/Systems/system/LogServices/EventLog/Entries
pass: 3
passGet: 1
skipOptional: 1
/redfish/v1/Systems/system/LogServices/EventLog/<str>
pass: 6
passGet: 1
skipOptional: 16
Sample Output: curl -k -H "X-Auth-Token: $bmc_token" -X GET https://${bmc}/redfish/v1/Systems/system/LogServices/EventLog/Entries
{
"@odata.context": "/redfish/v1/$metadata#LogEntryCollection.LogEntryCollection",
"@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/Entries",
"@odata.type": "#LogEntryCollection.LogEntryCollection",
"Description": "Collection of System Event Log Entries",
"Members": [
{
"@odata.context": "/redfish/v1/$metadata#LogEntry.LogEntry",
"@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/Entries/1",
"@odata.type": "#LogEntry.v1_4_0.LogEntry",
"Created": "2019-02-22T17:11:00+00:00",
"EntryType": "Event",
"Id": "1",
"Message": "example.xyz.openbmc_project.Example.Elog.AutoTestSimple",
"Name": "System DBus Event Log Entry",
"Severity": "Critical"
}
],
"Members@odata.count": 1,
"Name": "System Event Log Entries"
}
Change-Id: I422b0d0ec577ea734fecfb6f49101ec5ff45a556
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Signed-off-by: Anthony Wilson <wilsonan@us.ibm.com>
Diffstat (limited to 'crow')
-rw-r--r-- | crow/include/crow/utility.h | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/crow/include/crow/utility.h b/crow/include/crow/utility.h index a07c0415af..63d2dece5f 100644 --- a/crow/include/crow/utility.h +++ b/crow/include/crow/utility.h @@ -2,7 +2,6 @@ #include "nlohmann/json.hpp" -#include <boost/utility/string_view.hpp> #include <cstdint> #include <cstring> #include <functional> @@ -712,5 +711,34 @@ inline void convertToLinks(std::string& s) s = std::regex_replace(s, nextLink, "$1<a href=\"$5\">$4</a>"); } +/** + * Method returns Date Time information according to requested format + * + * @param[in] time time in second since the Epoch + * + * @return Date Time according to requested format + */ +inline std::string getDateTime(const std::time_t& time) +{ + std::array<char, 128> dateTime; + std::string redfishDateTime("0000-00-00T00:00:00Z00:00"); + + if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z", + std::localtime(&time))) + { + // insert the colon required by the ISO 8601 standard + redfishDateTime = std::string(dateTime.data()); + redfishDateTime.insert(redfishDateTime.end() - 2, ':'); + } + + return redfishDateTime; +} + +inline std::string dateTimeNow() +{ + std::time_t time = std::time(nullptr); + return getDateTime(time); +} + } // namespace utility } // namespace crow |