blob: cd051dcc0c308da45dcff13cef38049af2cfeb31 [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) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040045 if (ec == boost::system::errc::host_unreachable)
46 {
47 asyncResp->res.jsonValue["Status"]["State"] =
48 resource::State::Absent;
49 return;
50 }
51 if (ec)
52 {
53 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
54 messages::internalError(asyncResp->res);
55 return;
56 }
57
Ed Tanous539d8c62024-06-19 14:38:27 -070058 asyncResp->res.jsonValue["Status"]["State"] =
Patrick Williamsbd79bce2024-08-16 15:22:20 -040059 resource::State::Enabled;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070060
Patrick Williamsbd79bce2024-08-16 15:22:20 -040061 const size_t* maxReports = nullptr;
62 const uint64_t* minInterval = nullptr;
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070063
Patrick Williamsbd79bce2024-08-16 15:22:20 -040064 const bool success = sdbusplus::unpackPropertiesNoThrow(
65 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
66 "MinInterval", minInterval);
Krzysztof Grobelny89474492022-09-06 16:30:38 +020067
Patrick Williamsbd79bce2024-08-16 15:22:20 -040068 if (!success)
69 {
70 messages::internalError(asyncResp->res);
71 return;
72 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +020073
Patrick Williamsbd79bce2024-08-16 15:22:20 -040074 if (maxReports != nullptr)
75 {
76 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
77 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070078
Patrick Williamsbd79bce2024-08-16 15:22:20 -040079 if (minInterval != nullptr)
80 {
81 asyncResp->res.jsonValue["MinCollectionInterval"] =
82 time_utils::toDurationString(std::chrono::milliseconds(
83 static_cast<time_t>(*minInterval)));
84 }
85 nlohmann::json::array_t supportedCollectionFunctions;
86 supportedCollectionFunctions.emplace_back("Maximum");
87 supportedCollectionFunctions.emplace_back("Minimum");
88 supportedCollectionFunctions.emplace_back("Average");
89 supportedCollectionFunctions.emplace_back("Summation");
Krzysztof Grobelny89474492022-09-06 16:30:38 +020090
Patrick Williamsbd79bce2024-08-16 15:22:20 -040091 asyncResp->res.jsonValue["SupportedCollectionFunctions"] =
92 std::move(supportedCollectionFunctions);
93 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070094}
95
John Edward Broadbent7e860f12021-04-08 15:57:16 -070096inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020097{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070098 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070099 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700100 .methods(boost::beast::http::verb::get)(
101 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700102}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -0700103
Wludzik, Jozef081ebf02020-04-27 17:24:15 +0200104} // namespace redfish