1 #pragma once 2 3 #include "app.hpp" 4 #include "dbus_utility.hpp" 5 #include "generated/enums/resource.hpp" 6 #include "query.hpp" 7 #include "registries/privilege_registry.hpp" 8 #include "utils/dbus_utils.hpp" 9 #include "utils/telemetry_utils.hpp" 10 #include "utils/time_utils.hpp" 11 12 #include <sdbusplus/asio/property.hpp> 13 #include <sdbusplus/unpack_properties.hpp> 14 15 namespace redfish 16 { 17 18 inline void handleTelemetryServiceGet( 19 crow::App& app, const crow::Request& req, 20 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21 { 22 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 23 { 24 return; 25 } 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"; 36 asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 37 "/redfish/v1/TelemetryService/Triggers"; 38 39 dbus::utility::getAllProperties( 40 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", 41 "xyz.openbmc_project.Telemetry.ReportManager", 42 [asyncResp](const boost::system::error_code& ec, 43 const dbus::utility::DBusPropertiesMap& ret) { 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 57 asyncResp->res.jsonValue["Status"]["State"] = 58 resource::State::Enabled; 59 60 const size_t* maxReports = nullptr; 61 const uint64_t* minInterval = nullptr; 62 63 const bool success = sdbusplus::unpackPropertiesNoThrow( 64 dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports, 65 "MinInterval", minInterval); 66 67 if (!success) 68 { 69 messages::internalError(asyncResp->res); 70 return; 71 } 72 73 if (maxReports != nullptr) 74 { 75 asyncResp->res.jsonValue["MaxReports"] = *maxReports; 76 } 77 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"); 89 90 asyncResp->res.jsonValue["SupportedCollectionFunctions"] = 91 std::move(supportedCollectionFunctions); 92 }); 93 } 94 95 inline void requestRoutesTelemetryService(App& app) 96 { 97 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 98 .privileges(redfish::privileges::getTelemetryService) 99 .methods(boost::beast::http::verb::get)( 100 std::bind_front(handleTelemetryServiceGet, std::ref(app))); 101 } 102 103 } // namespace redfish 104