Clean up metric report definition to use readJsonObject
Change-Id: I29a9ecbdc9011b6513dc6bfccd28e7e7158fed9b
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 43a1849..f68abdc 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -428,7 +428,7 @@
return true;
}
-inline bool getUserMetric(crow::Response& res, nlohmann::json& metric,
+inline bool getUserMetric(crow::Response& res, nlohmann::json::object_t& metric,
AddReportArgs::MetricArgs& metricArgs)
{
std::optional<std::vector<std::string>> uris;
@@ -436,10 +436,10 @@
std::optional<std::string> collectionFunction;
std::optional<std::string> collectionTimeScopeStr;
- if (!json_util::readJson(metric, res, "MetricProperties", uris,
- "CollectionFunction", collectionFunction,
- "CollectionTimeScope", collectionTimeScopeStr,
- "CollectionDuration", collectionDurationStr))
+ if (!json_util::readJsonObject(
+ metric, res, "MetricProperties", uris, "CollectionFunction",
+ collectionFunction, "CollectionTimeScope", collectionTimeScopeStr,
+ "CollectionDuration", collectionDurationStr))
{
return false;
}
@@ -495,12 +495,12 @@
}
inline bool getUserMetrics(crow::Response& res,
- std::span<nlohmann::json> metrics,
+ std::span<nlohmann::json::object_t> metrics,
std::vector<AddReportArgs::MetricArgs>& result)
{
result.reserve(metrics.size());
- for (nlohmann::json& m : metrics)
+ for (nlohmann::json::object_t& m : metrics)
{
AddReportArgs::MetricArgs metricArgs;
@@ -524,16 +524,17 @@
std::optional<std::string> reportUpdatesStr;
std::optional<uint64_t> appendLimit;
std::optional<bool> metricReportDefinitionEnabled;
- std::optional<std::vector<nlohmann::json>> metrics;
+ std::optional<std::vector<nlohmann::json::object_t>> metrics;
std::optional<std::vector<std::string>> reportActionsStr;
- std::optional<nlohmann::json> schedule;
+ std::optional<std::string> scheduleDurationStr;
if (!json_util::readJsonPatch(
req, res, "Id", id, "Name", name, "Metrics", metrics,
"MetricReportDefinitionType", reportingTypeStr, "ReportUpdates",
reportUpdatesStr, "AppendLimit", appendLimit, "ReportActions",
- reportActionsStr, "Schedule", schedule,
- "MetricReportDefinitionEnabled", metricReportDefinitionEnabled))
+ reportActionsStr, "Schedule/RecurrenceInterval",
+ scheduleDurationStr, "MetricReportDefinitionEnabled",
+ metricReportDefinitionEnabled))
{
return false;
}
@@ -600,25 +601,18 @@
if (reportingTypeStr == "Periodic")
{
- if (!schedule)
+ if (!scheduleDurationStr)
{
messages::createFailedMissingReqProperties(res, "Schedule");
return false;
}
- std::string durationStr;
- if (!json_util::readJson(*schedule, res, "RecurrenceInterval",
- durationStr))
- {
- return false;
- }
-
std::optional<std::chrono::milliseconds> durationNum =
- time_utils::fromDurationString(durationStr);
+ time_utils::fromDurationString(*scheduleDurationStr);
if (!durationNum || durationNum->count() < 0)
{
messages::propertyValueIncorrect(res, "RecurrenceInterval",
- durationStr);
+ *scheduleDurationStr);
return false;
}
args.interval = static_cast<uint64_t>(durationNum->count());
@@ -960,14 +954,15 @@
inline void
setReportMetrics(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- std::string_view id, std::span<nlohmann::json> metrics)
+ std::string_view id,
+ std::span<nlohmann::json::object_t> metrics)
{
sdbusplus::asio::getAllProperties(
*crow::connections::systemBus, telemetry::service,
telemetry::getDbusReportPath(id), telemetry::reportInterface,
[asyncResp, id = std::string(id),
- redfishMetrics = std::vector<nlohmann::json>(metrics.begin(),
- metrics.end())](
+ redfishMetrics = std::vector<nlohmann::json::object_t>(metrics.begin(),
+ metrics.end())](
boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& properties) mutable {
if (!redfish::telemetry::verifyCommonErrors(asyncResp->res, id, ec))
@@ -993,13 +988,8 @@
chassisSensors;
size_t index = 0;
- for (nlohmann::json& metric : redfishMetrics)
+ for (nlohmann::json::object_t& metric : redfishMetrics)
{
- if (metric.is_null())
- {
- continue;
- }
-
AddReportArgs::MetricArgs metricArgs;
std::vector<
std::tuple<sdbusplus::message::object_path, std::string>>
@@ -1109,16 +1099,16 @@
std::optional<std::string> reportingTypeStr;
std::optional<std::string> reportUpdatesStr;
std::optional<bool> metricReportDefinitionEnabled;
- std::optional<std::vector<nlohmann::json>> metrics;
+ std::optional<std::vector<nlohmann::json::object_t>> metrics;
std::optional<std::vector<std::string>> reportActionsStr;
- std::optional<nlohmann::json> schedule;
+ std::optional<std::string> scheduleDurationStr;
if (!json_util::readJsonPatch(
req, asyncResp->res, "Metrics", metrics,
"MetricReportDefinitionType", reportingTypeStr, "ReportUpdates",
- reportUpdatesStr, "ReportActions", reportActionsStr, "Schedule",
- schedule, "MetricReportDefinitionEnabled",
- metricReportDefinitionEnabled))
+ reportUpdatesStr, "ReportActions", reportActionsStr,
+ "Schedule/RecurrenceInterval", scheduleDurationStr,
+ "MetricReportDefinitionEnabled", metricReportDefinitionEnabled))
{
return;
}
@@ -1151,7 +1141,7 @@
setReportActions(asyncResp, id, dbusReportActions);
}
- if (reportingTypeStr || schedule)
+ if (reportingTypeStr || scheduleDurationStr)
{
std::string dbusReportingType;
if (reportingTypeStr)
@@ -1167,21 +1157,14 @@
}
uint64_t recurrenceInterval = std::numeric_limits<uint64_t>::max();
- if (schedule)
+ if (scheduleDurationStr)
{
- std::string durationStr;
- if (!json_util::readJson(*schedule, asyncResp->res,
- "RecurrenceInterval", durationStr))
- {
- return;
- }
-
std::optional<std::chrono::milliseconds> durationNum =
- time_utils::fromDurationString(durationStr);
+ time_utils::fromDurationString(*scheduleDurationStr);
if (!durationNum || durationNum->count() < 0)
{
messages::propertyValueIncorrect(
- asyncResp->res, "RecurrenceInterval", durationStr);
+ asyncResp->res, "RecurrenceInterval", *scheduleDurationStr);
return;
}