blob: 9ec07379a4e130401081aebab669cbc1e76d1875 [file] [log] [blame]
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02001#pragma once
2
3#include "node.hpp"
4#include "utils/telemetry_utils.hpp"
5
6#include <variant>
7
8namespace redfish
9{
10
11class TelemetryService : public Node
12{
13 public:
14 TelemetryService(App& app) : Node(app, "/redfish/v1/TelemetryService/")
15 {
16 entityPrivileges = {
17 {boost::beast::http::verb::get, {{"Login"}}},
18 {boost::beast::http::verb::head, {{"Login"}}},
19 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
20 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
21 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
22 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
23 }
24
25 private:
zhanghch058d1b46d2021-04-01 11:18:24 +080026 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
27 const crow::Request&, const std::vector<std::string>&) override
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020028 {
zhanghch058d1b46d2021-04-01 11:18:24 +080029 asyncResp->res.jsonValue["@odata.type"] =
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020030 "#TelemetryService.v1_2_1.TelemetryService";
zhanghch058d1b46d2021-04-01 11:18:24 +080031 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
32 asyncResp->res.jsonValue["Id"] = "TelemetryService";
33 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020034
zhanghch058d1b46d2021-04-01 11:18:24 +080035 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020036 "/redfish/v1/TelemetryService/MetricReportDefinitions";
zhanghch058d1b46d2021-04-01 11:18:24 +080037 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020038 "/redfish/v1/TelemetryService/MetricReports";
39
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020040 crow::connections::systemBus->async_method_call(
41 [asyncResp](
42 const boost::system::error_code ec,
43 const std::vector<std::pair<
44 std::string, std::variant<uint32_t, uint64_t>>>& ret) {
45 if (ec == boost::system::errc::host_unreachable)
46 {
47 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
48 return;
49 }
50 if (ec)
51 {
52 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
53 messages::internalError(asyncResp->res);
54 return;
55 }
56
57 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
58
59 const size_t* maxReports = nullptr;
60 const uint64_t* minInterval = nullptr;
61 for (const auto& [key, var] : ret)
62 {
63 if (key == "MaxReports")
64 {
65 maxReports = std::get_if<size_t>(&var);
66 }
67 else if (key == "MinInterval")
68 {
69 minInterval = std::get_if<uint64_t>(&var);
70 }
71 }
72 if (!maxReports || !minInterval)
73 {
74 BMCWEB_LOG_ERROR
75 << "Property type mismatch or property is missing";
76 messages::internalError(asyncResp->res);
77 return;
78 }
79
80 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
81 asyncResp->res.jsonValue["MinCollectionInterval"] =
82 time_utils::toDurationString(std::chrono::milliseconds(
83 static_cast<time_t>(*minInterval)));
84 },
85 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
86 "org.freedesktop.DBus.Properties", "GetAll",
87 "xyz.openbmc_project.Telemetry.ReportManager");
88 }
89};
90} // namespace redfish