blob: ab0abe0963e330a72e39f087597136ce79afd1f9 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02003#pragma once
4
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08005#include "app.hpp"
6#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07007#include "generated/enums/resource.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "query.hpp"
9#include "registries/privilege_registry.hpp"
10#include "utils/dbus_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020011#include "utils/telemetry_utils.hpp"
Ed Tanousd093c992023-01-19 19:01:49 -080012#include "utils/time_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020013
Krzysztof Grobelny89474492022-09-06 16:30:38 +020014#include <sdbusplus/asio/property.hpp>
15#include <sdbusplus/unpack_properties.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070016
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020017namespace redfish
18{
19
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070020inline void handleTelemetryServiceGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070021 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080022 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070023{
Carson Labrado3ba00072022-06-06 19:40:56 +000024 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070025 {
26 return;
27 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070028 asyncResp->res.jsonValue["@odata.type"] =
29 "#TelemetryService.v1_2_1.TelemetryService";
30 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
31 asyncResp->res.jsonValue["Id"] = "TelemetryService";
32 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
33
34 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
35 "/redfish/v1/TelemetryService/MetricReportDefinitions";
36 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
37 "/redfish/v1/TelemetryService/MetricReports";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020038 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
39 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070040
Ed Tanousdeae6a72024-11-11 21:58:57 -080041 dbus::utility::getAllProperties(
42 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
Krzysztof Grobelny89474492022-09-06 16:30:38 +020043 "xyz.openbmc_project.Telemetry.ReportManager",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080044 [asyncResp](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -080045 const dbus::utility::DBusPropertiesMap& ret) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040046 if (ec == boost::system::errc::host_unreachable)
47 {
48 asyncResp->res.jsonValue["Status"]["State"] =
49 resource::State::Absent;
50 return;
51 }
52 if (ec)
53 {
54 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
55 messages::internalError(asyncResp->res);
56 return;
57 }
58
Ed Tanous539d8c62024-06-19 14:38:27 -070059 asyncResp->res.jsonValue["Status"]["State"] =
Patrick Williamsbd79bce2024-08-16 15:22:20 -040060 resource::State::Enabled;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070061
Patrick Williamsbd79bce2024-08-16 15:22:20 -040062 const size_t* maxReports = nullptr;
63 const uint64_t* minInterval = nullptr;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070064
Patrick Williamsbd79bce2024-08-16 15:22:20 -040065 const bool success = sdbusplus::unpackPropertiesNoThrow(
66 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
67 "MinInterval", minInterval);
Krzysztof Grobelny89474492022-09-06 16:30:38 +020068
Patrick Williamsbd79bce2024-08-16 15:22:20 -040069 if (!success)
70 {
71 messages::internalError(asyncResp->res);
72 return;
73 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +020074
Patrick Williamsbd79bce2024-08-16 15:22:20 -040075 if (maxReports != nullptr)
76 {
77 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
78 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070079
Patrick Williamsbd79bce2024-08-16 15:22:20 -040080 if (minInterval != nullptr)
81 {
82 asyncResp->res.jsonValue["MinCollectionInterval"] =
83 time_utils::toDurationString(std::chrono::milliseconds(
84 static_cast<time_t>(*minInterval)));
85 }
86 nlohmann::json::array_t supportedCollectionFunctions;
87 supportedCollectionFunctions.emplace_back("Maximum");
88 supportedCollectionFunctions.emplace_back("Minimum");
89 supportedCollectionFunctions.emplace_back("Average");
90 supportedCollectionFunctions.emplace_back("Summation");
Krzysztof Grobelny89474492022-09-06 16:30:38 +020091
Patrick Williamsbd79bce2024-08-16 15:22:20 -040092 asyncResp->res.jsonValue["SupportedCollectionFunctions"] =
93 std::move(supportedCollectionFunctions);
94 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070095}
96
John Edward Broadbent7e860f12021-04-08 15:57:16 -070097inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020098{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070099 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -0700100 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700101 .methods(boost::beast::http::verb::get)(
102 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700103}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -0700104
Wludzik, Jozef081ebf02020-04-27 17:24:15 +0200105} // namespace redfish