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