1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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);
|