diff options
Diffstat (limited to 'meta-ibs/meta-cp2-5422/recipes-phosphor')
-rw-r--r-- | meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0018-add-timezone.patch | 149 | ||||
-rw-r--r-- | meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend | 1 |
2 files changed, 150 insertions, 0 deletions
diff --git a/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0018-add-timezone.patch b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0018-add-timezone.patch new file mode 100644 index 0000000000..62c3ef1363 --- /dev/null +++ b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0018-add-timezone.patch @@ -0,0 +1,149 @@ +From ba2f5fad6f6c4ac052954606b0d22846e70d66f4 Mon Sep 17 00:00:00 2001 +From: claiff <claiff@mail.ru> +Date: Wed, 21 Sep 2022 12:53:28 +0300 +Subject: [PATCH] add timezone + +--- + meson.build | 1 - + .../include/event_service_manager.hpp | 2 +- + redfish-core/lib/metric_report.hpp | 40 ++++++++++++++----- + 3 files changed, 32 insertions(+), 11 deletions(-) + +diff --git a/meson.build b/meson.build +index 2f204764..370dc4d1 100644 +--- a/meson.build ++++ b/meson.build +@@ -133,7 +133,6 @@ add_project_arguments( + '-Wformat=2', + '-Wold-style-cast', + '-Woverloaded-virtual', +- '-Wsign-conversion', + '-Wunused', + '-Wno-attributes', + ]), +diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp +index 636ab5be..d1abaf0e 100644 +--- a/redfish-core/include/event_service_manager.hpp ++++ b/redfish-core/include/event_service_manager.hpp +@@ -526,7 +526,7 @@ class Subscription : public persistent_data::UserSubscription + } + + nlohmann::json msg; +- if (!telemetry::fillReport(msg, reportId, var)) ++ if (!telemetry::fillReport(msg, reportId, 0, var)) + { + BMCWEB_LOG_ERROR << "Failed to fill the MetricReport for DBus " + "Report with id " +diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp +index 66066cbb..0cedd4d9 100644 +--- a/redfish-core/lib/metric_report.hpp ++++ b/redfish-core/lib/metric_report.hpp +@@ -21,6 +21,7 @@ enum class Params + ReportName, + IdGroup, + Period, ++ TimeZone, + }; + + enum class Periods +@@ -37,11 +38,14 @@ using Readings = + std::list<std::tuple<std::string, double, uint64_t>>; + using TimestampReadings = std::tuple<uint64_t, Readings>; + +-inline std::string GetCroppedTimeStamp(uint64_t timestamp) ++inline std::string GetCroppedTimeStamp(uint64_t timestamp, int time_zone) + { + static constexpr char DOT_CHAR = '.'; ++ static constexpr int COUNT_MS_HOUR = 60 * 60 * 1000; + +- auto timestamp_as_string = redfish::time_utils::getDateTimeUintMs(timestamp); ++ auto corrected_timestamp = timestamp + time_zone * COUNT_MS_HOUR; ++ ++ auto timestamp_as_string = redfish::time_utils::getDateTimeUintMs(corrected_timestamp); + auto last_dot_position = timestamp_as_string.rfind(DOT_CHAR); + if(last_dot_position != std::string::npos) + { +@@ -65,7 +69,7 @@ inline std::string GetCroppedValue(double value) + return value_as_string; + } + +-inline nlohmann::json toMetricValues(const Readings& readings) ++inline nlohmann::json toMetricValues(const Readings& readings, int time_zone) + { + nlohmann::json metricValues = nlohmann::json::array_t(); + +@@ -74,14 +78,14 @@ inline nlohmann::json toMetricValues(const Readings& readings) + metricValues.push_back({ + {"Sensor", metadata}, + {"Value", GetCroppedValue(sensorValue)}, +- {"Timestamp", GetCroppedTimeStamp(timestamp)}, ++ {"Timestamp", GetCroppedTimeStamp(timestamp, time_zone)}, + }); + } + + return metricValues; + } + +-inline bool fillReport(nlohmann::json& json, const std::string& id, ++inline bool fillReport(nlohmann::json& json, const std::string& id, int time_zone, + const TimestampReadings& timestampReadings) + { + json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport"; +@@ -97,8 +101,8 @@ inline bool fillReport(nlohmann::json& json, const std::string& id, + .string(); + + const auto& [timestamp, readings] = timestampReadings; +- json["Timestamp"] = GetCroppedTimeStamp(timestamp); +- json["MetricValues"] = toMetricValues(readings); ++ json["Timestamp"] = GetCroppedTimeStamp(timestamp, time_zone); ++ json["MetricValues"] = toMetricValues(readings, time_zone); + return true; + } + +@@ -140,6 +144,12 @@ inline std::pair<Params, std::string> BuildPairParams(std::vector<std::string> c + result.first = telemetry::Params::ReportName; + result.second = params_as_string[1]; + } ++ else if( params_as_string[0] == "timezone" ) ++ { ++ result.first = telemetry::Params::TimeZone; ++ result.second = params_as_string[1]; ++ } ++ + return result; + } + +@@ -224,11 +234,23 @@ inline void requestRoutesMetricReport(App& app) + auto period_it = parsed_params.find(telemetry::Params::Period); + auto period = period_it != parsed_params.end() ? period_it->second : ""; + ++ auto time_zone_it = parsed_params.find(telemetry::Params::TimeZone); ++ auto time_zone_as_string = time_zone_it != parsed_params.end() ? time_zone_it->second : ""; ++ + const std::string reportPath = telemetry::getDbusReportPath(report_name); + + auto is_need_last_hour = telemetry::ConvertPeriod(period) == telemetry::Periods::LastHour; + +- crow::connections::systemBus->async_method_call([asyncResp, report_name, period](const boost::system::error_code& error_code, ++ int time_zone_as_int = 0; ++ try ++ { ++ time_zone_as_int = std::stoi( time_zone_as_string ); ++ } ++ catch (...) ++ { ++ time_zone_as_int = 0; ++ } ++ crow::connections::systemBus->async_method_call([asyncResp, report_name, period, time_zone_as_int](const boost::system::error_code& error_code, + const telemetry::TimestampReadings& ret){ + if(error_code.value() == EBADR || + error_code == boost::system::errc::host_unreachable) +@@ -243,7 +265,7 @@ inline void requestRoutesMetricReport(App& app) + return; + } + +- telemetry::fillReport(asyncResp->res.jsonValue,report_name, ret); ++ telemetry::fillReport(asyncResp->res.jsonValue,report_name, time_zone_as_int, ret); + }, + telemetry::service, reportPath, telemetry::reportInterface, + "GetReadings", is_need_last_hour); diff --git a/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend index 3b579231ec..f090cf8f78 100644 --- a/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend +++ b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend @@ -14,6 +14,7 @@ SRC_URI += "\ file://0015-Redfish-Implement-SNMP-Trap.patch \ file://0016-Redfish-implement-Syslog-config.patch \ file://0017-update-smtp.patch \ + file://0018-add-timezone.patch \ " EXTRA_OEMESON += "\ |