blob: 0eaf89bf9f9595ed076c8dc75ac3025a639374ca [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"
9
Krzysztof Grobelny89474492022-09-06 16:30:38 +020010#include <sdbusplus/asio/property.hpp>
11#include <sdbusplus/unpack_properties.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070012
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020013namespace redfish
14{
15
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070016inline void handleTelemetryServiceGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070017 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080018 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070019{
Carson Labrado3ba00072022-06-06 19:40:56 +000020 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070021 {
22 return;
23 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070024 asyncResp->res.jsonValue["@odata.type"] =
25 "#TelemetryService.v1_2_1.TelemetryService";
26 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
27 asyncResp->res.jsonValue["Id"] = "TelemetryService";
28 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
29
30 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
31 "/redfish/v1/TelemetryService/MetricReportDefinitions";
32 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
33 "/redfish/v1/TelemetryService/MetricReports";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020034 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
35 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070036
Krzysztof Grobelny89474492022-09-06 16:30:38 +020037 sdbusplus::asio::getAllProperties(
38 *crow::connections::systemBus, telemetry::service,
39 "/xyz/openbmc_project/Telemetry/Reports",
40 "xyz.openbmc_project.Telemetry.ReportManager",
Ed Tanousb9d36b42022-02-26 21:42:46 -080041 [asyncResp](const boost::system::error_code ec,
42 const dbus::utility::DBusPropertiesMap& ret) {
Ed Tanous002d39b2022-05-31 08:59:27 -070043 if (ec == boost::system::errc::host_unreachable)
44 {
45 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
46 return;
47 }
48 if (ec)
49 {
50 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
51 messages::internalError(asyncResp->res);
52 return;
53 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070054
Ed Tanous002d39b2022-05-31 08:59:27 -070055 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070056
Ed Tanous002d39b2022-05-31 08:59:27 -070057 const size_t* maxReports = nullptr;
58 const uint64_t* minInterval = nullptr;
Krzysztof Grobelny89474492022-09-06 16:30:38 +020059
60 const bool success = sdbusplus::unpackPropertiesNoThrow(
61 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
62 "MinInterval", minInterval);
63
64 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -070065 {
Ed Tanous002d39b2022-05-31 08:59:27 -070066 messages::internalError(asyncResp->res);
67 return;
68 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070069
Krzysztof Grobelny89474492022-09-06 16:30:38 +020070 if (maxReports != nullptr)
71 {
72 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
73 }
74
75 if (minInterval != nullptr)
76 {
77 asyncResp->res.jsonValue["MinCollectionInterval"] =
78 time_utils::toDurationString(std::chrono::milliseconds(
79 static_cast<time_t>(*minInterval)));
80 }
81 });
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070082}
83
John Edward Broadbent7e860f12021-04-08 15:57:16 -070084inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020085{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070086 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070087 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -070088 .methods(boost::beast::http::verb::get)(
89 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070090}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070091
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020092} // namespace redfish