blob: e6f5b0f1c7da1c48bd0ee0a99deee4a79965d886 [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>
6
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02007#include <variant>
8
9namespace redfish
10{
11
John Edward Broadbent7e860f12021-04-08 15:57:16 -070012inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020013{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070014 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
15 .privileges({"Login"})
16 .methods(
17 boost::beast::http::verb::
18 get)([](const crow::Request&,
19 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
20 asyncResp->res.jsonValue["@odata.type"] =
21 "#TelemetryService.v1_2_1.TelemetryService";
22 asyncResp->res.jsonValue["@odata.id"] =
23 "/redfish/v1/TelemetryService";
24 asyncResp->res.jsonValue["Id"] = "TelemetryService";
25 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020026
John Edward Broadbent7e860f12021-04-08 15:57:16 -070027 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
28 "/redfish/v1/TelemetryService/MetricReportDefinitions";
29 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
30 "/redfish/v1/TelemetryService/MetricReports";
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020031
John Edward Broadbent7e860f12021-04-08 15:57:16 -070032 crow::connections::systemBus->async_method_call(
33 [asyncResp](
34 const boost::system::error_code ec,
35 const std::vector<std::pair<
36 std::string, std::variant<uint32_t, uint64_t>>>& ret) {
37 if (ec == boost::system::errc::host_unreachable)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020038 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070039 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
40 return;
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020041 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -070042 if (ec)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020043 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070044 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
45 messages::internalError(asyncResp->res);
46 return;
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020047 }
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020048
John Edward Broadbent7e860f12021-04-08 15:57:16 -070049 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
50
51 const size_t* maxReports = nullptr;
52 const uint64_t* minInterval = nullptr;
53 for (const auto& [key, var] : ret)
54 {
55 if (key == "MaxReports")
56 {
57 maxReports = std::get_if<size_t>(&var);
58 }
59 else if (key == "MinInterval")
60 {
61 minInterval = std::get_if<uint64_t>(&var);
62 }
63 }
64 if (!maxReports || !minInterval)
65 {
66 BMCWEB_LOG_ERROR
67 << "Property type mismatch or property is missing";
68 messages::internalError(asyncResp->res);
69 return;
70 }
71
72 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
73 asyncResp->res.jsonValue["MinCollectionInterval"] =
74 time_utils::toDurationString(std::chrono::milliseconds(
75 static_cast<time_t>(*minInterval)));
76 },
77 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
78 "org.freedesktop.DBus.Properties", "GetAll",
79 "xyz.openbmc_project.Telemetry.ReportManager");
80 });
81}
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020082} // namespace redfish