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 | 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) { |
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 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 51 | BMCWEB_LOG_ERROR("respHandler DBus error {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 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 | } |
Krzysztof Grobelny | 479e899 | 2021-06-17 13:37:57 +0000 | [diff] [blame] | 82 | nlohmann::json::array_t supportedCollectionFunctions; |
| 83 | supportedCollectionFunctions.emplace_back("Maximum"); |
| 84 | supportedCollectionFunctions.emplace_back("Minimum"); |
| 85 | supportedCollectionFunctions.emplace_back("Average"); |
| 86 | supportedCollectionFunctions.emplace_back("Summation"); |
| 87 | |
| 88 | asyncResp->res.jsonValue["SupportedCollectionFunctions"] = |
| 89 | std::move(supportedCollectionFunctions); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame^] | 90 | }); |
John Edward Broadbent | 26bd9b5 | 2021-07-12 14:06:30 -0700 | [diff] [blame] | 91 | } |
| 92 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 93 | inline void requestRoutesTelemetryService(App& app) |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 94 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 95 | BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 96 | .privileges(redfish::privileges::getTelemetryService) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 97 | .methods(boost::beast::http::verb::get)( |
| 98 | std::bind_front(handleTelemetryServiceGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 99 | } |
John Edward Broadbent | 26bd9b5 | 2021-07-12 14:06:30 -0700 | [diff] [blame] | 100 | |
Wludzik, Jozef | 081ebf0 | 2020-04-27 17:24:15 +0200 | [diff] [blame] | 101 | } // namespace redfish |