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