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: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 26 | void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 27 | const crow::Request&, const std::vector<std::string>&) override |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 28 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 29 | asyncResp->res.jsonValue["@odata.type"] = |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 30 | "#TelemetryService.v1_2_1.TelemetryService"; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 31 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; |
| 32 | asyncResp->res.jsonValue["Id"] = "TelemetryService"; |
| 33 | asyncResp->res.jsonValue["Name"] = "Telemetry Service"; |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 34 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 35 | asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 36 | "/redfish/v1/TelemetryService/MetricReportDefinitions"; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 37 | asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 38 | "/redfish/v1/TelemetryService/MetricReports"; |
| 39 | |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 40 | 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 |