blob: 02d7f38f23cf704355eb3eb293e6d0cbafd667a0 [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 Tanousb9d36b42022-02-26 21:42:46 -080042 [asyncResp](const boost::system::error_code ec,
43 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 {
51 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
52 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 }
82 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070083}
84
John Edward Broadbent7e860f12021-04-08 15:57:16 -070085inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020086{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070087 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070088 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -070089 .methods(boost::beast::http::verb::get)(
90 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070091}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070092
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020093} // namespace redfish