summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0009-Fix-MetricReportDefinitions-filter-not-working.patch
blob: 64b3c11125dbe055c1bb6c10642c8c53b4cee8fa (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
From 455b1d4c687a5c14197af1c1aba80b579c75900e Mon Sep 17 00:00:00 2001
From: AppaRao Puli <apparao.puli@linux.intel.com>
Date: Mon, 3 Aug 2020 22:23:12 +0530
Subject: [PATCH 1/2] Fix: MetricReportDefinitions filter not working

The metric reports are not sending when user configures
the MetricReportDefinitions filter. This is of odata json
object type. Corrected code to properly handle odata type
object and store it as string array to make filters faster.

Tested:
 - Created metric report EventService subscription type
   with MetricReportDefinitions and events properly sent to
   Event listener.

Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
Change-Id: If96564219da7d38a2ee5e415b89824ba25cd686d
---
 redfish-core/include/event_service_manager.hpp |  4 ++--
 redfish-core/lib/event_service.hpp             | 32 +++++++++++++++++++++-----
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 214f1e4..7c47842 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -283,7 +283,7 @@ bool isFilterQuerySpecialChar(char c)
 bool readSSEQueryParams(std::string sseFilter, std::string& formatType,
                         std::vector<std::string>& messageIds,
                         std::vector<std::string>& registryPrefixes,
-                        std::vector<nlohmann::json>& metricReportDefinitions)
+                        std::vector<std::string>& metricReportDefinitions)
 {
     sseFilter.erase(std::remove_if(sseFilter.begin(), sseFilter.end(),
                                    isFilterQuerySpecialChar),
@@ -369,7 +369,7 @@ class Subscription
     std::vector<std::string> registryMsgIds;
     std::vector<std::string> registryPrefixes;
     std::vector<nlohmann::json> httpHeaders; // key-value pair
-    std::vector<nlohmann::json> metricReportDefinitions;
+    std::vector<std::string> metricReportDefinitions;
 
     Subscription(const Subscription&) = delete;
     Subscription& operator=(const Subscription&) = delete;
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 8bd30f5..f59d093 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -229,7 +229,7 @@ class EventDestinationCollection : public Node
         std::optional<std::vector<std::string>> msgIds;
         std::optional<std::vector<std::string>> regPrefixes;
         std::optional<std::vector<nlohmann::json>> headers;
-        std::optional<std::vector<nlohmann::json>> metricReportDefinitions;
+        std::optional<std::vector<nlohmann::json>> mrdJsonArray;
 
         if (!json_util::readJson(
                 req, res, "Destination", destUrl, "Context", context,
@@ -237,7 +237,7 @@ class EventDestinationCollection : public Node
                 "EventFormatType", eventFormatType, "HttpHeaders", headers,
                 "RegistryPrefixes", regPrefixes, "MessageIds", msgIds,
                 "DeliveryRetryPolicy", retryPolicy, "MetricReportDefinitions",
-                metricReportDefinitions))
+                mrdJsonArray))
         {
             return;
         }
@@ -387,9 +387,24 @@ class EventDestinationCollection : public Node
             subValue->retryPolicy = "TerminateAfterRetries";
         }
 
-        if (metricReportDefinitions)
+        if (mrdJsonArray)
         {
-            subValue->metricReportDefinitions = *metricReportDefinitions;
+            for (nlohmann::json& mrdObj : *mrdJsonArray)
+            {
+                std::string mrdUri;
+                if (json_util::getValueFromJsonObject(mrdObj, "@odata.id",
+                                                      mrdUri))
+                {
+                    subValue->metricReportDefinitions.emplace_back(mrdUri);
+                }
+                else
+                {
+                    messages::propertyValueFormatError(
+                        asyncResp->res, mrdObj.dump(),
+                        "MetricReportDefinitions");
+                    return;
+                }
+            }
         }
 
         std::string id =
@@ -565,8 +580,13 @@ class EventDestination : public Node
             subValue->registryPrefixes;
         asyncResp->res.jsonValue["MessageIds"] = subValue->registryMsgIds;
         asyncResp->res.jsonValue["DeliveryRetryPolicy"] = subValue->retryPolicy;
-        asyncResp->res.jsonValue["MetricReportDefinitions"] =
-            subValue->metricReportDefinitions;
+
+        std::vector<nlohmann::json> mrdJsonArray;
+        for (const auto& mdrUri : subValue->metricReportDefinitions)
+        {
+            mrdJsonArray.push_back({{"@odata.id", mdrUri}});
+        }
+        asyncResp->res.jsonValue["MetricReportDefinitions"] = mrdJsonArray;
     }
 
     void doPatch(crow::Response& res, const crow::Request& req,
-- 
2.7.4