blob: 19eccba21d945ca3354d0386a5b9cf9c6d2845f6 [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
Krzysztof Grobelny89474492022-09-06 16:30:38 +020039 sdbusplus::asio::getAllProperties(
40 *crow::connections::systemBus, telemetry::service,
41 "/xyz/openbmc_project/Telemetry/Reports",
42 "xyz.openbmc_project.Telemetry.ReportManager",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080043 [asyncResp](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -080044 const dbus::utility::DBusPropertiesMap& ret) {
Ed Tanous002d39b2022-05-31 08:59:27 -070045 if (ec == boost::system::errc::host_unreachable)
46 {
Ed Tanous539d8c62024-06-19 14:38:27 -070047 asyncResp->res.jsonValue["Status"]["State"] =
48 resource::State::Absent;
Ed Tanous002d39b2022-05-31 08:59:27 -070049 return;
50 }
51 if (ec)
52 {
Ed Tanous62598e32023-07-17 17:06:25 -070053 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -070054 messages::internalError(asyncResp->res);
55 return;
56 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070057
Ed Tanous539d8c62024-06-19 14:38:27 -070058 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070059
Ed Tanous002d39b2022-05-31 08:59:27 -070060 const size_t* maxReports = nullptr;
61 const uint64_t* minInterval = nullptr;
Krzysztof Grobelny89474492022-09-06 16:30:38 +020062
63 const bool success = sdbusplus::unpackPropertiesNoThrow(
64 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
65 "MinInterval", minInterval);
66
67 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -070068 {
Ed Tanous002d39b2022-05-31 08:59:27 -070069 messages::internalError(asyncResp->res);
70 return;
71 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070072
Krzysztof Grobelny89474492022-09-06 16:30:38 +020073 if (maxReports != nullptr)
74 {
75 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
76 }
77
78 if (minInterval != nullptr)
79 {
80 asyncResp->res.jsonValue["MinCollectionInterval"] =
81 time_utils::toDurationString(std::chrono::milliseconds(
82 static_cast<time_t>(*minInterval)));
83 }
Krzysztof Grobelny479e8992021-06-17 13:37:57 +000084 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");
89
90 asyncResp->res.jsonValue["SupportedCollectionFunctions"] =
91 std::move(supportedCollectionFunctions);
Patrick Williams5a39f772023-10-20 11:20:21 -050092 });
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