blob: 724e8aad2750074dc811a21da9acdc725ab74a4e [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"
5#include "query.hpp"
6#include "registries/privilege_registry.hpp"
7#include "utils/dbus_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02008#include "utils/telemetry_utils.hpp"
Ed Tanousd093c992023-01-19 19:01:49 -08009#include "utils/time_utils.hpp"
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020010
Krzysztof Grobelny89474492022-09-06 16:30:38 +020011#include <sdbusplus/asio/property.hpp>
12#include <sdbusplus/unpack_properties.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070013
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020014namespace redfish
15{
16
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070017inline void handleTelemetryServiceGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070018 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080019 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070020{
Carson Labrado3ba00072022-06-06 19:40:56 +000021 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070022 {
23 return;
24 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070025 asyncResp->res.jsonValue["@odata.type"] =
26 "#TelemetryService.v1_2_1.TelemetryService";
27 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
28 asyncResp->res.jsonValue["Id"] = "TelemetryService";
29 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
30
31 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
32 "/redfish/v1/TelemetryService/MetricReportDefinitions";
33 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
34 "/redfish/v1/TelemetryService/MetricReports";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020035 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
36 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070037
Krzysztof Grobelny89474492022-09-06 16:30:38 +020038 sdbusplus::asio::getAllProperties(
39 *crow::connections::systemBus, telemetry::service,
40 "/xyz/openbmc_project/Telemetry/Reports",
41 "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) {
Ed Tanous002d39b2022-05-31 08:59:27 -070044 if (ec == boost::system::errc::host_unreachable)
45 {
46 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
47 return;
48 }
49 if (ec)
50 {
Ed Tanous62598e32023-07-17 17:06:25 -070051 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -070052 messages::internalError(asyncResp->res);
53 return;
54 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070055
Ed Tanous002d39b2022-05-31 08:59:27 -070056 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070057
Ed Tanous002d39b2022-05-31 08:59:27 -070058 const size_t* maxReports = nullptr;
59 const uint64_t* minInterval = nullptr;
Krzysztof Grobelny89474492022-09-06 16:30:38 +020060
61 const bool success = sdbusplus::unpackPropertiesNoThrow(
62 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
63 "MinInterval", minInterval);
64
65 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -070066 {
Ed Tanous002d39b2022-05-31 08:59:27 -070067 messages::internalError(asyncResp->res);
68 return;
69 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070070
Krzysztof Grobelny89474492022-09-06 16:30:38 +020071 if (maxReports != nullptr)
72 {
73 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
74 }
75
76 if (minInterval != nullptr)
77 {
78 asyncResp->res.jsonValue["MinCollectionInterval"] =
79 time_utils::toDurationString(std::chrono::milliseconds(
80 static_cast<time_t>(*minInterval)));
81 }
Krzysztof Grobelny479e8992021-06-17 13:37:57 +000082 nlohmann::json::array_t supportedCollectionFunctions;
83 supportedCollectionFunctions.emplace_back("Maximum");
84 supportedCollectionFunctions.emplace_back("Minimum");
85 supportedCollectionFunctions.emplace_back("Average");
86 supportedCollectionFunctions.emplace_back("Summation");
87
88 asyncResp->res.jsonValue["SupportedCollectionFunctions"] =
89 std::move(supportedCollectionFunctions);
Patrick Williams5a39f772023-10-20 11:20:21 -050090 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070091}
92
John Edward Broadbent7e860f12021-04-08 15:57:16 -070093inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020094{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070095 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070096 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -070097 .methods(boost::beast::http::verb::get)(
98 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070099}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -0700100
Wludzik, Jozef081ebf02020-04-27 17:24:15 +0200101} // namespace redfish