Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "node.hpp" |
| 4 | #include "utils/telemetry_utils.hpp" |
| 5 | |
| 6 | #include <variant> |
| 7 | |
| 8 | namespace redfish |
| 9 | { |
| 10 | |
| 11 | class 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 | |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 35 | res.jsonValue["MetricReportDefinitions"]["@odata.id"] = |
| 36 | "/redfish/v1/TelemetryService/MetricReportDefinitions"; |
| 37 | res.jsonValue["MetricReports"]["@odata.id"] = |
| 38 | "/redfish/v1/TelemetryService/MetricReports"; |
| 39 | |
| 40 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 41 | crow::connections::systemBus->async_method_call( |
| 42 | [asyncResp]( |
| 43 | const boost::system::error_code ec, |
| 44 | const std::vector<std::pair< |
| 45 | std::string, std::variant<uint32_t, uint64_t>>>& ret) { |
| 46 | if (ec == boost::system::errc::host_unreachable) |
| 47 | { |
| 48 | asyncResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 49 | return; |
| 50 | } |
| 51 | if (ec) |
| 52 | { |
| 53 | BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; |
| 54 | messages::internalError(asyncResp->res); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 59 | |
| 60 | const size_t* maxReports = nullptr; |
| 61 | const uint64_t* minInterval = nullptr; |
| 62 | for (const auto& [key, var] : ret) |
| 63 | { |
| 64 | if (key == "MaxReports") |
| 65 | { |
| 66 | maxReports = std::get_if<size_t>(&var); |
| 67 | } |
| 68 | else if (key == "MinInterval") |
| 69 | { |
| 70 | minInterval = std::get_if<uint64_t>(&var); |
| 71 | } |
| 72 | } |
| 73 | if (!maxReports || !minInterval) |
| 74 | { |
| 75 | BMCWEB_LOG_ERROR |
| 76 | << "Property type mismatch or property is missing"; |
| 77 | messages::internalError(asyncResp->res); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | asyncResp->res.jsonValue["MaxReports"] = *maxReports; |
| 82 | asyncResp->res.jsonValue["MinCollectionInterval"] = |
| 83 | time_utils::toDurationString(std::chrono::milliseconds( |
| 84 | static_cast<time_t>(*minInterval))); |
| 85 | }, |
| 86 | telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", |
| 87 | "org.freedesktop.DBus.Properties", "GetAll", |
| 88 | "xyz.openbmc_project.Telemetry.ReportManager"); |
| 89 | } |
| 90 | }; |
| 91 | } // namespace redfish |