1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3081ebf06SWludzik, Jozef #pragma once 4081ebf06SWludzik, Jozef 53ccb3adbSEd Tanous #include "app.hpp" 63ccb3adbSEd Tanous #include "dbus_utility.hpp" 7539d8c6bSEd Tanous #include "generated/enums/resource.hpp" 83ccb3adbSEd Tanous #include "query.hpp" 93ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 103ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 11081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp" 12d093c996SEd Tanous #include "utils/time_utils.hpp" 13081ebf06SWludzik, Jozef 1489474494SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 1589474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 167e860f15SJohn Edward Broadbent 17081ebf06SWludzik, Jozef namespace redfish 18081ebf06SWludzik, Jozef { 19081ebf06SWludzik, Jozef 2026bd9b57SJohn Edward Broadbent inline void handleTelemetryServiceGet( 2145ca1b86SEd Tanous crow::App& app, const crow::Request& req, 22104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 23081ebf06SWludzik, Jozef { 243ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2545ca1b86SEd Tanous { 2645ca1b86SEd Tanous return; 2745ca1b86SEd Tanous } 288d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 29081ebf06SWludzik, Jozef "#TelemetryService.v1_2_1.TelemetryService"; 3026bd9b57SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; 318d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "TelemetryService"; 328d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Telemetry Service"; 33081ebf06SWludzik, Jozef 348d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = 35081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReportDefinitions"; 368d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = 37081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReports"; 3807148cf2SLukasz Kazmierczak asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 3907148cf2SLukasz Kazmierczak "/redfish/v1/TelemetryService/Triggers"; 40081ebf06SWludzik, Jozef 41deae6a78SEd Tanous dbus::utility::getAllProperties( 42deae6a78SEd Tanous telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", 4389474494SKrzysztof Grobelny "xyz.openbmc_project.Telemetry.ReportManager", 445e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 45b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& ret) { 46081ebf06SWludzik, Jozef if (ec == boost::system::errc::host_unreachable) 47081ebf06SWludzik, Jozef { 48539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 49539d8c6bSEd Tanous resource::State::Absent; 50081ebf06SWludzik, Jozef return; 51081ebf06SWludzik, Jozef } 52081ebf06SWludzik, Jozef if (ec) 53081ebf06SWludzik, Jozef { 5462598e31SEd Tanous BMCWEB_LOG_ERROR("respHandler DBus error {}", ec); 55081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 56081ebf06SWludzik, Jozef return; 57081ebf06SWludzik, Jozef } 58081ebf06SWludzik, Jozef 59bd79bce8SPatrick Williams asyncResp->res.jsonValue["Status"]["State"] = 60bd79bce8SPatrick Williams resource::State::Enabled; 61081ebf06SWludzik, Jozef 62081ebf06SWludzik, Jozef const size_t* maxReports = nullptr; 63081ebf06SWludzik, Jozef const uint64_t* minInterval = nullptr; 6489474494SKrzysztof Grobelny 6589474494SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 6689474494SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports, 6789474494SKrzysztof Grobelny "MinInterval", minInterval); 6889474494SKrzysztof Grobelny 6989474494SKrzysztof Grobelny if (!success) 70081ebf06SWludzik, Jozef { 71081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 72081ebf06SWludzik, Jozef return; 73081ebf06SWludzik, Jozef } 74081ebf06SWludzik, Jozef 7589474494SKrzysztof Grobelny if (maxReports != nullptr) 7689474494SKrzysztof Grobelny { 77081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MaxReports"] = *maxReports; 7889474494SKrzysztof Grobelny } 7989474494SKrzysztof Grobelny 8089474494SKrzysztof Grobelny if (minInterval != nullptr) 8189474494SKrzysztof Grobelny { 82081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MinCollectionInterval"] = 8389474494SKrzysztof Grobelny time_utils::toDurationString(std::chrono::milliseconds( 8489474494SKrzysztof Grobelny static_cast<time_t>(*minInterval))); 8589474494SKrzysztof Grobelny } 86479e899dSKrzysztof Grobelny nlohmann::json::array_t supportedCollectionFunctions; 87479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Maximum"); 88479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Minimum"); 89479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Average"); 90479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Summation"); 91479e899dSKrzysztof Grobelny 92479e899dSKrzysztof Grobelny asyncResp->res.jsonValue["SupportedCollectionFunctions"] = 93479e899dSKrzysztof Grobelny std::move(supportedCollectionFunctions); 9489474494SKrzysztof Grobelny }); 95081ebf06SWludzik, Jozef } 9626bd9b57SJohn Edward Broadbent 9726bd9b57SJohn Edward Broadbent inline void requestRoutesTelemetryService(App& app) 9826bd9b57SJohn Edward Broadbent { 9926bd9b57SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 10026bd9b57SJohn Edward Broadbent .privileges(redfish::privileges::getTelemetryService) 10145ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 10245ca1b86SEd Tanous std::bind_front(handleTelemetryServiceGet, std::ref(app))); 10326bd9b57SJohn Edward Broadbent } 10426bd9b57SJohn Edward Broadbent 105081ebf06SWludzik, Jozef } // namespace redfish 106