summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0011-configure-telemetry.patch
blob: d77457ce7aa454621d751e7f4fb3ff5d34c7a5b7 (plain)
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
From 1920d507c28baa6ca9ec3de3694a2df218a4f265 Mon Sep 17 00:00:00 2001
From: eportnov <eportnov@ibs.ru>
Date: Thu, 8 Sep 2022 14:25:36 +0300
Subject: [PATCH] configure telemetry

---
 include/dbus_utility.hpp           |  1 +
 redfish-core/lib/metric_report.hpp | 39 +++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index bd0d64bd..05adb1e6 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -62,6 +62,7 @@ using DbusVariantType = std::variant<
     std::vector<uint16_t>,
     sdbusplus::message::object_path,
     std::tuple<uint64_t, std::vector<std::tuple<std::string, std::string, double, uint64_t>>>,
+    std::tuple<uint64_t, std::vector<std::tuple<std::string, double, uint64_t>>>,
     std::vector<std::tuple<std::string, std::string>>,
     std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>,
     std::vector<std::tuple<uint32_t, size_t>>,
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index 18830f13..b3f5721e 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -20,20 +20,47 @@ constexpr const char* metricReportUri =
     "/redfish/v1/TelemetryService/MetricReports";
 
 using Readings =
-    std::vector<std::tuple<std::string, std::string, double, uint64_t>>;
+    std::vector<std::tuple<std::string, double, uint64_t>>;
 using TimestampReadings = std::tuple<uint64_t, Readings>;
 
+inline std::string GetCroppedTimeStamp(uint64_t timestamp)
+{
+    static constexpr char DOT_CHAR = '.';
+
+    auto timestamp_as_string = redfish::time_utils::getDateTimeUintMs(timestamp);
+    auto last_dot_position = timestamp_as_string.rfind(DOT_CHAR);
+    if(last_dot_position != std::string::npos)
+    {
+        timestamp_as_string.erase(last_dot_position);
+    }
+    return timestamp_as_string;
+}
+
+inline std::string GetCroppedValue(double value)
+{
+    static constexpr char DOT_CHAR = '.';
+    static constexpr size_t COUNT_NUMBER_AFTER_DOT = 1;
+
+    auto value_as_string = std::to_string(value);
+    auto last_dot_position = value_as_string.rfind(DOT_CHAR);
+    auto general_size = last_dot_position + COUNT_NUMBER_AFTER_DOT + sizeof(DOT_CHAR);
+    if(last_dot_position != std::string::npos && general_size <= value_as_string.length())
+    {
+        value_as_string.erase(general_size);
+    }
+    return value_as_string;
+}
+
 inline nlohmann::json toMetricValues(const Readings& readings)
 {
     nlohmann::json metricValues = nlohmann::json::array_t();
 
-    for (const auto& [id, metadata, sensorValue, timestamp] : readings)
+    for (const auto& [metadata, sensorValue, timestamp] : readings)
     {
         metricValues.push_back({
-            {"MetricId", id},
-            {"MetricProperty", metadata},
-            {"MetricValue", std::to_string(sensorValue)},
-            {"Timestamp", redfish::time_utils::getDateTimeUintMs(timestamp)},
+            {"Sensor", metadata}, 
+            {"Value", GetCroppedValue(sensorValue)},
+            {"Timestamp", GetCroppedTimeStamp(timestamp)},
         });
     }
 
@@ -56,7 +83,7 @@ inline bool fillReport(nlohmann::json& json, const std::string& id,
             .string();
 
     const auto& [timestamp, readings] = timestampReadings;
-    json["Timestamp"] = redfish::time_utils::getDateTimeUintMs(timestamp);
+    json["Timestamp"] = GetCroppedTimeStamp(timestamp);
     json["MetricValues"] = toMetricValues(readings);
     return true;
 }