blob: a6acc34c4db10d873c46d9fbc0458024c2f880fe [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:
26 void doGet(crow::Response& res, const crow::Request&,
27 const std::vector<std::string>&) override
28 {
29 res.jsonValue["@odata.type"] =
30 "#TelemetryService.v1_2_1.TelemetryService";
31 res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
32 res.jsonValue["Id"] = "TelemetryService";
33 res.jsonValue["Name"] = "Telemetry Service";
34
35 res.jsonValue["LogService"]["@odata.id"] =
36 "/redfish/v1/Managers/bmc/LogServices/Journal";
37 res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
38 "/redfish/v1/TelemetryService/MetricReportDefinitions";
39 res.jsonValue["MetricReports"]["@odata.id"] =
40 "/redfish/v1/TelemetryService/MetricReports";
41
42 auto asyncResp = std::make_shared<AsyncResp>(res);
43 crow::connections::systemBus->async_method_call(
44 [asyncResp](
45 const boost::system::error_code ec,
46 const std::vector<std::pair<
47 std::string, std::variant<uint32_t, uint64_t>>>& ret) {
48 if (ec == boost::system::errc::host_unreachable)
49 {
50 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
51 return;
52 }
53 if (ec)
54 {
55 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
56 messages::internalError(asyncResp->res);
57 return;
58 }
59
60 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
61
62 const size_t* maxReports = nullptr;
63 const uint64_t* minInterval = nullptr;
64 for (const auto& [key, var] : ret)
65 {
66 if (key == "MaxReports")
67 {
68 maxReports = std::get_if<size_t>(&var);
69 }
70 else if (key == "MinInterval")
71 {
72 minInterval = std::get_if<uint64_t>(&var);
73 }
74 }
75 if (!maxReports || !minInterval)
76 {
77 BMCWEB_LOG_ERROR
78 << "Property type mismatch or property is missing";
79 messages::internalError(asyncResp->res);
80 return;
81 }
82
83 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
84 asyncResp->res.jsonValue["MinCollectionInterval"] =
85 time_utils::toDurationString(std::chrono::milliseconds(
86 static_cast<time_t>(*minInterval)));
87 },
88 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
89 "org.freedesktop.DBus.Properties", "GetAll",
90 "xyz.openbmc_project.Telemetry.ReportManager");
91 }
92};
93} // namespace redfish