blob: 6b0cf2e3a454ccdc209fa5487064f3e7712e8ee2 [file] [log] [blame]
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02001#pragma once
2
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08003#include "app.hpp"
4#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07005#include "generated/enums/resource.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "query.hpp"
7#include "registries/privilege_registry.hpp"
8#include "utils/dbus_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02009#include "utils/telemetry_utils.hpp"
Ed Tanousd093c992023-01-19 19:01:49 -080010#include "utils/time_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020011
Krzysztof Grobelny89474492022-09-06 16:30:38 +020012#include <sdbusplus/asio/property.hpp>
13#include <sdbusplus/unpack_properties.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070014
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020015namespace redfish
16{
17
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070018inline void handleTelemetryServiceGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070019 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080020 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070021{
Carson Labrado3ba00072022-06-06 19:40:56 +000022 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070023 {
24 return;
25 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070026 asyncResp->res.jsonValue["@odata.type"] =
27 "#TelemetryService.v1_2_1.TelemetryService";
28 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
29 asyncResp->res.jsonValue["Id"] = "TelemetryService";
30 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
31
32 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
33 "/redfish/v1/TelemetryService/MetricReportDefinitions";
34 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
35 "/redfish/v1/TelemetryService/MetricReports";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020036 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
37 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070038
Ed Tanousdeae6a72024-11-11 21:58:57 -080039 dbus::utility::getAllProperties(
40 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
Krzysztof Grobelny89474492022-09-06 16:30:38 +020041 "xyz.openbmc_project.Telemetry.ReportManager",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080042 [asyncResp](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -080043 const dbus::utility::DBusPropertiesMap& ret) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040044 if (ec == boost::system::errc::host_unreachable)
45 {
46 asyncResp->res.jsonValue["Status"]["State"] =
47 resource::State::Absent;
48 return;
49 }
50 if (ec)
51 {
52 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
53 messages::internalError(asyncResp->res);
54 return;
55 }
56
Ed Tanous539d8c62024-06-19 14:38:27 -070057 asyncResp->res.jsonValue["Status"]["State"] =
Patrick Williamsbd79bce2024-08-16 15:22:20 -040058 resource::State::Enabled;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070059
Patrick Williamsbd79bce2024-08-16 15:22:20 -040060 const size_t* maxReports = nullptr;
61 const uint64_t* minInterval = nullptr;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070062
Patrick Williamsbd79bce2024-08-16 15:22:20 -040063 const bool success = sdbusplus::unpackPropertiesNoThrow(
64 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
65 "MinInterval", minInterval);
Krzysztof Grobelny89474492022-09-06 16:30:38 +020066
Patrick Williamsbd79bce2024-08-16 15:22:20 -040067 if (!success)
68 {
69 messages::internalError(asyncResp->res);
70 return;
71 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +020072
Patrick Williamsbd79bce2024-08-16 15:22:20 -040073 if (maxReports != nullptr)
74 {
75 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
76 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070077
Patrick Williamsbd79bce2024-08-16 15:22:20 -040078 if (minInterval != nullptr)
79 {
80 asyncResp->res.jsonValue["MinCollectionInterval"] =
81 time_utils::toDurationString(std::chrono::milliseconds(
82 static_cast<time_t>(*minInterval)));
83 }
84 nlohmann::json::array_t supportedCollectionFunctions;
85 supportedCollectionFunctions.emplace_back("Maximum");
86 supportedCollectionFunctions.emplace_back("Minimum");
87 supportedCollectionFunctions.emplace_back("Average");
88 supportedCollectionFunctions.emplace_back("Summation");
Krzysztof Grobelny89474492022-09-06 16:30:38 +020089
Patrick Williamsbd79bce2024-08-16 15:22:20 -040090 asyncResp->res.jsonValue["SupportedCollectionFunctions"] =
91 std::move(supportedCollectionFunctions);
92 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070093}
94
John Edward Broadbent7e860f12021-04-08 15:57:16 -070095inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020096{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070097 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070098 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -070099 .methods(boost::beast::http::verb::get)(
100 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700101}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -0700102
Wludzik, Jozef081ebf02020-04-27 17:24:15 +0200103} // namespace redfish