Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 3 | #include "utils/telemetry_utils.hpp" |
| 4 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 5 | #include <app.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 6 | #include <registries/privilege_registry.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 7 | |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 8 | #include <variant> |
| 9 | |
| 10 | namespace redfish |
| 11 | { |
| 12 | |
John Edward Broadbent | 26bd9b5 | 2021-07-12 14:06:30 -0700 | [diff] [blame^] | 13 | inline 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"; |
| 26 | |
| 27 | crow::connections::systemBus->async_method_call( |
| 28 | [asyncResp](const boost::system::error_code ec, |
| 29 | const std::vector<std::pair< |
| 30 | std::string, std::variant<uint32_t, uint64_t>>>& ret) { |
| 31 | if (ec == boost::system::errc::host_unreachable) |
| 32 | { |
| 33 | asyncResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 34 | return; |
| 35 | } |
| 36 | if (ec) |
| 37 | { |
| 38 | BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; |
| 39 | messages::internalError(asyncResp->res); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 44 | |
| 45 | const size_t* maxReports = nullptr; |
| 46 | const uint64_t* minInterval = nullptr; |
| 47 | for (const auto& [key, var] : ret) |
| 48 | { |
| 49 | if (key == "MaxReports") |
| 50 | { |
| 51 | maxReports = std::get_if<size_t>(&var); |
| 52 | } |
| 53 | else if (key == "MinInterval") |
| 54 | { |
| 55 | minInterval = std::get_if<uint64_t>(&var); |
| 56 | } |
| 57 | } |
| 58 | if (!maxReports || !minInterval) |
| 59 | { |
| 60 | BMCWEB_LOG_ERROR |
| 61 | << "Property type mismatch or property is missing"; |
| 62 | messages::internalError(asyncResp->res); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | asyncResp->res.jsonValue["MaxReports"] = *maxReports; |
| 67 | asyncResp->res.jsonValue["MinCollectionInterval"] = |
| 68 | time_utils::toDurationString(std::chrono::milliseconds( |
| 69 | static_cast<time_t>(*minInterval))); |
| 70 | }, |
| 71 | telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", |
| 72 | "org.freedesktop.DBus.Properties", "GetAll", |
| 73 | "xyz.openbmc_project.Telemetry.ReportManager"); |
| 74 | } |
| 75 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 76 | inline void requestRoutesTelemetryService(App& app) |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 77 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 78 | BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 79 | .privileges(redfish::privileges::getTelemetryService) |
John Edward Broadbent | 26bd9b5 | 2021-07-12 14:06:30 -0700 | [diff] [blame^] | 80 | .methods(boost::beast::http::verb::get)(handleTelemetryServiceGet); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 81 | } |
John Edward Broadbent | 26bd9b5 | 2021-07-12 14:06:30 -0700 | [diff] [blame^] | 82 | |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 83 | } // namespace redfish |