blob: ad86d5cd450c63dc94b76a14fdda02a2d466c3a7 [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 Broadbent7e860f12021-04-08 15:57:16 -070013inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020014{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070015 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070016 .privileges(redfish::privileges::getTelemetryService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070017 .methods(
18 boost::beast::http::verb::
19 get)([](const crow::Request&,
20 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
21 asyncResp->res.jsonValue["@odata.type"] =
22 "#TelemetryService.v1_2_1.TelemetryService";
23 asyncResp->res.jsonValue["@odata.id"] =
24 "/redfish/v1/TelemetryService";
25 asyncResp->res.jsonValue["Id"] = "TelemetryService";
26 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020027
John Edward Broadbent7e860f12021-04-08 15:57:16 -070028 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
29 "/redfish/v1/TelemetryService/MetricReportDefinitions";
30 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
31 "/redfish/v1/TelemetryService/MetricReports";
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020032
John Edward Broadbent7e860f12021-04-08 15:57:16 -070033 crow::connections::systemBus->async_method_call(
34 [asyncResp](
35 const boost::system::error_code ec,
36 const std::vector<std::pair<
37 std::string, std::variant<uint32_t, uint64_t>>>& ret) {
38 if (ec == boost::system::errc::host_unreachable)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020039 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070040 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
41 return;
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020042 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -070043 if (ec)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020044 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070045 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
46 messages::internalError(asyncResp->res);
47 return;
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020048 }
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020049
John Edward Broadbent7e860f12021-04-08 15:57:16 -070050 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
51
52 const size_t* maxReports = nullptr;
53 const uint64_t* minInterval = nullptr;
54 for (const auto& [key, var] : ret)
55 {
56 if (key == "MaxReports")
57 {
58 maxReports = std::get_if<size_t>(&var);
59 }
60 else if (key == "MinInterval")
61 {
62 minInterval = std::get_if<uint64_t>(&var);
63 }
64 }
65 if (!maxReports || !minInterval)
66 {
67 BMCWEB_LOG_ERROR
68 << "Property type mismatch or property is missing";
69 messages::internalError(asyncResp->res);
70 return;
71 }
72
73 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
74 asyncResp->res.jsonValue["MinCollectionInterval"] =
75 time_utils::toDurationString(std::chrono::milliseconds(
76 static_cast<time_t>(*minInterval)));
77 },
78 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
79 "org.freedesktop.DBus.Properties", "GetAll",
80 "xyz.openbmc_project.Telemetry.ReportManager");
81 });
82}
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020083} // namespace redfish