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