blob: b79a5cd2915a09c66449befb1fde8c720b5e20e4 [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";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020026 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
27 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070028
29 crow::connections::systemBus->async_method_call(
30 [asyncResp](const boost::system::error_code ec,
31 const std::vector<std::pair<
32 std::string, std::variant<uint32_t, uint64_t>>>& ret) {
33 if (ec == boost::system::errc::host_unreachable)
34 {
35 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
36 return;
37 }
38 if (ec)
39 {
40 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
41 messages::internalError(asyncResp->res);
42 return;
43 }
44
45 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
46
47 const size_t* maxReports = nullptr;
48 const uint64_t* minInterval = nullptr;
49 for (const auto& [key, var] : ret)
50 {
51 if (key == "MaxReports")
52 {
53 maxReports = std::get_if<size_t>(&var);
54 }
55 else if (key == "MinInterval")
56 {
57 minInterval = std::get_if<uint64_t>(&var);
58 }
59 }
60 if (!maxReports || !minInterval)
61 {
62 BMCWEB_LOG_ERROR
63 << "Property type mismatch or property is missing";
64 messages::internalError(asyncResp->res);
65 return;
66 }
67
68 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
69 asyncResp->res.jsonValue["MinCollectionInterval"] =
70 time_utils::toDurationString(std::chrono::milliseconds(
71 static_cast<time_t>(*minInterval)));
72 },
73 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
74 "org.freedesktop.DBus.Properties", "GetAll",
75 "xyz.openbmc_project.Telemetry.ReportManager");
76}
77
John Edward Broadbent7e860f12021-04-08 15:57:16 -070078inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020079{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070080 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070081 .privileges(redfish::privileges::getTelemetryService)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070082 .methods(boost::beast::http::verb::get)(handleTelemetryServiceGet);
John Edward Broadbent7e860f12021-04-08 15:57:16 -070083}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070084
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020085} // namespace redfish