blob: 49d467335b6a6adc5734e854b2ebf6eff2db9217 [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"
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "async_resp.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08008#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07009#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080010#include "http_request.hpp"
11#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080012#include "query.hpp"
13#include "registries/privilege_registry.hpp"
14#include "utils/dbus_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020015#include "utils/telemetry_utils.hpp"
Ed Tanousd093c992023-01-19 19:01:49 -080016#include "utils/time_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020017
Ed Tanousd7857202025-01-28 15:32:26 -080018#include <boost/beast/http/verb.hpp>
Krzysztof Grobelny89474492022-09-06 16:30:38 +020019#include <sdbusplus/unpack_properties.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070020
Ed Tanousd7857202025-01-28 15:32:26 -080021#include <chrono>
22#include <cstddef>
23#include <cstdint>
24#include <ctime>
25#include <functional>
26#include <memory>
27#include <utility>
28
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020029namespace redfish
30{
31
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070032inline void handleTelemetryServiceGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070033 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080034 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070035{
Carson Labrado3ba00072022-06-06 19:40:56 +000036 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070037 {
38 return;
39 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070040 asyncResp->res.jsonValue["@odata.type"] =
41 "#TelemetryService.v1_2_1.TelemetryService";
42 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
43 asyncResp->res.jsonValue["Id"] = "TelemetryService";
44 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
45
46 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
47 "/redfish/v1/TelemetryService/MetricReportDefinitions";
48 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
49 "/redfish/v1/TelemetryService/MetricReports";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020050 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
51 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070052
Ed Tanousdeae6a72024-11-11 21:58:57 -080053 dbus::utility::getAllProperties(
54 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
Krzysztof Grobelny89474492022-09-06 16:30:38 +020055 "xyz.openbmc_project.Telemetry.ReportManager",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080056 [asyncResp](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -080057 const dbus::utility::DBusPropertiesMap& ret) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040058 if (ec == boost::system::errc::host_unreachable)
59 {
60 asyncResp->res.jsonValue["Status"]["State"] =
61 resource::State::Absent;
62 return;
63 }
64 if (ec)
65 {
66 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
67 messages::internalError(asyncResp->res);
68 return;
69 }
70
Ed Tanous539d8c62024-06-19 14:38:27 -070071 asyncResp->res.jsonValue["Status"]["State"] =
Patrick Williamsbd79bce2024-08-16 15:22:20 -040072 resource::State::Enabled;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070073
Patrick Williamsbd79bce2024-08-16 15:22:20 -040074 const size_t* maxReports = nullptr;
75 const uint64_t* minInterval = nullptr;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070076
Patrick Williamsbd79bce2024-08-16 15:22:20 -040077 const bool success = sdbusplus::unpackPropertiesNoThrow(
78 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
79 "MinInterval", minInterval);
Krzysztof Grobelny89474492022-09-06 16:30:38 +020080
Patrick Williamsbd79bce2024-08-16 15:22:20 -040081 if (!success)
82 {
83 messages::internalError(asyncResp->res);
84 return;
85 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +020086
Patrick Williamsbd79bce2024-08-16 15:22:20 -040087 if (maxReports != nullptr)
88 {
89 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
90 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070091
Patrick Williamsbd79bce2024-08-16 15:22:20 -040092 if (minInterval != nullptr)
93 {
94 asyncResp->res.jsonValue["MinCollectionInterval"] =
95 time_utils::toDurationString(std::chrono::milliseconds(
96 static_cast<time_t>(*minInterval)));
97 }
98 nlohmann::json::array_t supportedCollectionFunctions;
99 supportedCollectionFunctions.emplace_back("Maximum");
100 supportedCollectionFunctions.emplace_back("Minimum");
101 supportedCollectionFunctions.emplace_back("Average");
102 supportedCollectionFunctions.emplace_back("Summation");
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200103
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400104 asyncResp->res.jsonValue["SupportedCollectionFunctions"] =
105 std::move(supportedCollectionFunctions);
106 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -0700107}
108
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700109inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +0200110{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700111 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -0700112 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700113 .methods(boost::beast::http::verb::get)(
114 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700115}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -0700116
Wludzik, Jozef081ebf02020-04-27 17:24:15 +0200117} // namespace redfish