summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/telemetry/0004-Add-support-for-OnRequest-in-MetricReportDefinition.patch
blob: e996ac585faee85106bd0e636b93db68c2287bd1 (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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From 9fc7d722b3192df9940062185b40ebb0fabad518 Mon Sep 17 00:00:00 2001
From: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Date: Mon, 8 Jun 2020 15:16:10 +0200
Subject: [PATCH 4/5] Add support for "OnRequest" in MetricReportDefinition

Added support for "OnRequest" of ReportingType property in
MetricReportDefinition node. Now user is able to create
MetricReportDefinition that is updated on every GET request
on MetricReport.

Tested:
  - Succesfully passed RedfishServiceValidator.py
  - Manually tested via curl

Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I1cdfe47e56fdc5ec9753558145d0bf3645160aaf
---
 include/dbus_utility.hpp                       | 30 +++++++++++++++
 redfish-core/include/utils/telemetry_utils.hpp |  8 ++--
 redfish-core/lib/metric_report.hpp             | 53 +++++++++++++++++++++++++-
 3 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index 3df88d8..029d8d8 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -17,6 +17,7 @@
 
 #include <sdbusplus/message.hpp>
 
+#include <functional>
 #include <regex>
 
 namespace dbus
@@ -130,5 +131,34 @@ inline void getAllProperties(Callback&& callback, const std::string& service,
         interface);
 }
 
+template <typename T>
+static void getProperty(
+    std::function<void(const boost::system::error_code&, const T&)> callback,
+    const std::string& service, const std::string& path,
+    const std::string& interface, const std::string& property)
+{
+    crow::connections::systemBus->async_method_call(
+        [callback](const boost::system::error_code ec,
+                   const std::variant<T>& value) {
+            if (ec)
+            {
+                callback(ec, T{});
+                return;
+            }
+
+            if (auto v = std::get_if<T>(&value))
+            {
+                callback(ec, *v);
+                return;
+            }
+
+            callback(boost::system::errc::make_error_code(
+                         boost::system::errc::io_error),
+                     T{});
+        },
+        service, path, "org.freedesktop.DBus.Properties", "Get", interface,
+        property);
+}
+
 } // namespace utility
 } // namespace dbus
diff --git a/redfish-core/include/utils/telemetry_utils.hpp b/redfish-core/include/utils/telemetry_utils.hpp
index 05ed00f..6c4e810 100644
--- a/redfish-core/include/utils/telemetry_utils.hpp
+++ b/redfish-core/include/utils/telemetry_utils.hpp
@@ -26,6 +26,8 @@ static constexpr const char* metricReportDefinitionUri =
     "/redfish/v1/TelemetryService/MetricReportDefinitions/";
 static constexpr const char* metricReportUri =
     "/redfish/v1/TelemetryService/MetricReports/";
+static constexpr const char* monitoringService =
+    "xyz.openbmc_project.MonitoringService";
 static constexpr const char* reportInterface =
     "xyz.openbmc_project.MonitoringService.Report";
 static constexpr const char* telemetryPath =
@@ -66,9 +68,9 @@ static void getReport(const std::shared_ptr<AsyncResp>& asyncResp,
     const std::array<const char*, 1> interfaces = {reportInterface};
 
     dbus::utility::getSubTreePaths(
-        [asyncResp, id, schemaType,
-         callback](const boost::system::error_code ec,
-                   const std::vector<std::string>& reports) {
+        [asyncResp, id, schemaType, callback = std::move(callback)](
+            const boost::system::error_code ec,
+            const std::vector<std::string>& reports) {
             if (ec == boost::system::errc::no_such_file_or_directory)
             {
                 messages::resourceNotFound(asyncResp->res, schemaType, id);
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index a52d680..877e7f1 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -85,7 +85,7 @@ class MetricReport : public Node
         }
 
         const std::string& id = params[0];
-        telemetry::getReport(asyncResp, id, schemaType, getReportProperties);
+        telemetry::getReport(asyncResp, id, schemaType, updateReportIfRequired);
     }
 
     using Readings =
@@ -143,6 +143,57 @@ class MetricReport : public Node
             "xyz.openbmc_project.MonitoringService.Report");
     }
 
+    template <typename Callback>
+    static void updateReport(Callback&& callback,
+                             const std::shared_ptr<AsyncResp>& asyncResp,
+                             const std::string& path)
+    {
+        crow::connections::systemBus->async_method_call(
+            [asyncResp, callback{std::move(callback)}](
+                const boost::system::error_code& ec) {
+                if (ec)
+                {
+                    messages::internalError(asyncResp->res);
+                    return;
+                }
+
+                callback();
+            },
+            telemetry::monitoringService, path, telemetry::reportInterface,
+            "Update");
+    }
+
+    static void
+        updateReportIfRequired(const std::shared_ptr<AsyncResp> asyncResp,
+                               const std::string& reportPath,
+                               const std::string& id)
+    {
+        dbus::utility::getProperty<std::string>(
+            [asyncResp, id, reportPath](const boost::system::error_code& ec,
+                                        const std::string& reportingType) {
+                if (ec)
+                {
+                    messages::internalError(asyncResp->res);
+                    return;
+                }
+
+                if (reportingType == "OnRequest")
+                {
+                    updateReport(
+                        [asyncResp, reportPath, id] {
+                            getReportProperties(asyncResp, reportPath, id);
+                        },
+                        asyncResp, reportPath);
+                }
+                else
+                {
+                    getReportProperties(asyncResp, reportPath, id);
+                }
+            },
+            telemetry::monitoringService, reportPath,
+            telemetry::reportInterface, "ReportingType");
+    }
+
     static constexpr const char* schemaType =
         "#MetricReport.v1_3_0.MetricReport";
 };
-- 
2.16.6