blob: 8ecc5916cabb5be6e1218ded3769975b51f3c9a4 [file] [log] [blame]
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02001#pragma once
2
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02003#include "utils/telemetry_utils.hpp"
4
John Edward Broadbent7e860f12021-04-08 15:57:16 -07005#include <app.hpp>
Ed Tanoused398212021-06-09 17:05:54 -07006#include <registries/privilege_registry.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -07007
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02008#include <variant>
9
10namespace redfish
11{
12
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070013inline void handleTelemetryServiceGet(
14 const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
15{
16 asyncResp->res.jsonValue["@odata.type"] =
17 "#TelemetryService.v1_2_1.TelemetryService";
18 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
19 asyncResp->res.jsonValue["Id"] = "TelemetryService";
20 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
21
22 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
23 "/redfish/v1/TelemetryService/MetricReportDefinitions";
24 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
25 "/redfish/v1/TelemetryService/MetricReports";
26
27 crow::connections::systemBus->async_method_call(
28 [asyncResp](const boost::system::error_code ec,
29 const std::vector<std::pair<
30 std::string, std::variant<uint32_t, uint64_t>>>& ret) {
31 if (ec == boost::system::errc::host_unreachable)
32 {
33 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
34 return;
35 }
36 if (ec)
37 {
38 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
39 messages::internalError(asyncResp->res);
40 return;
41 }
42
43 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
44
45 const size_t* maxReports = nullptr;
46 const uint64_t* minInterval = nullptr;
47 for (const auto& [key, var] : ret)
48 {
49 if (key == "MaxReports")
50 {
51 maxReports = std::get_if<size_t>(&var);
52 }
53 else if (key == "MinInterval")
54 {
55 minInterval = std::get_if<uint64_t>(&var);
56 }
57 }
58 if (!maxReports || !minInterval)
59 {
60 BMCWEB_LOG_ERROR
61 << "Property type mismatch or property is missing";
62 messages::internalError(asyncResp->res);
63 return;
64 }
65
66 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
67 asyncResp->res.jsonValue["MinCollectionInterval"] =
68 time_utils::toDurationString(std::chrono::milliseconds(
69 static_cast<time_t>(*minInterval)));
70 },
71 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
72 "org.freedesktop.DBus.Properties", "GetAll",
73 "xyz.openbmc_project.Telemetry.ReportManager");
74}
75
John Edward Broadbent7e860f12021-04-08 15:57:16 -070076inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020077{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070078 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070079 .privileges(redfish::privileges::getTelemetryService)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070080 .methods(boost::beast::http::verb::get)(handleTelemetryServiceGet);
John Edward Broadbent7e860f12021-04-08 15:57:16 -070081}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070082
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020083} // namespace redfish