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