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