140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3081ebf06SWludzik, Jozef #pragma once 4081ebf06SWludzik, Jozef 53ccb3adbSEd Tanous #include "app.hpp" 6*d7857201SEd Tanous #include "async_resp.hpp" 73ccb3adbSEd Tanous #include "dbus_utility.hpp" 8*d7857201SEd Tanous #include "error_messages.hpp" 9539d8c6bSEd Tanous #include "generated/enums/resource.hpp" 10*d7857201SEd Tanous #include "http_request.hpp" 11*d7857201SEd Tanous #include "logging.hpp" 123ccb3adbSEd Tanous #include "query.hpp" 133ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 143ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 15081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp" 16d093c996SEd Tanous #include "utils/time_utils.hpp" 17081ebf06SWludzik, Jozef 18*d7857201SEd Tanous #include <boost/beast/http/verb.hpp> 1989474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 207e860f15SJohn Edward Broadbent 21*d7857201SEd Tanous #include <chrono> 22*d7857201SEd Tanous #include <cstddef> 23*d7857201SEd Tanous #include <cstdint> 24*d7857201SEd Tanous #include <ctime> 25*d7857201SEd Tanous #include <functional> 26*d7857201SEd Tanous #include <memory> 27*d7857201SEd Tanous #include <utility> 28*d7857201SEd Tanous 29081ebf06SWludzik, Jozef namespace redfish 30081ebf06SWludzik, Jozef { 31081ebf06SWludzik, Jozef 3226bd9b57SJohn Edward Broadbent inline void handleTelemetryServiceGet( 3345ca1b86SEd Tanous crow::App& app, const crow::Request& req, 34104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 35081ebf06SWludzik, Jozef { 363ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3745ca1b86SEd Tanous { 3845ca1b86SEd Tanous return; 3945ca1b86SEd Tanous } 408d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 41081ebf06SWludzik, Jozef "#TelemetryService.v1_2_1.TelemetryService"; 4226bd9b57SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; 438d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "TelemetryService"; 448d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Telemetry Service"; 45081ebf06SWludzik, Jozef 468d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = 47081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReportDefinitions"; 488d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = 49081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReports"; 5007148cf2SLukasz Kazmierczak asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 5107148cf2SLukasz Kazmierczak "/redfish/v1/TelemetryService/Triggers"; 52081ebf06SWludzik, Jozef 53deae6a78SEd Tanous dbus::utility::getAllProperties( 54deae6a78SEd Tanous telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", 5589474494SKrzysztof Grobelny "xyz.openbmc_project.Telemetry.ReportManager", 565e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 57b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& ret) { 58081ebf06SWludzik, Jozef if (ec == boost::system::errc::host_unreachable) 59081ebf06SWludzik, Jozef { 60539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 61539d8c6bSEd Tanous resource::State::Absent; 62081ebf06SWludzik, Jozef return; 63081ebf06SWludzik, Jozef } 64081ebf06SWludzik, Jozef if (ec) 65081ebf06SWludzik, Jozef { 6662598e31SEd Tanous BMCWEB_LOG_ERROR("respHandler DBus error {}", ec); 67081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 68081ebf06SWludzik, Jozef return; 69081ebf06SWludzik, Jozef } 70081ebf06SWludzik, Jozef 71bd79bce8SPatrick Williams asyncResp->res.jsonValue["Status"]["State"] = 72bd79bce8SPatrick Williams resource::State::Enabled; 73081ebf06SWludzik, Jozef 74081ebf06SWludzik, Jozef const size_t* maxReports = nullptr; 75081ebf06SWludzik, Jozef const uint64_t* minInterval = nullptr; 7689474494SKrzysztof Grobelny 7789474494SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 7889474494SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports, 7989474494SKrzysztof Grobelny "MinInterval", minInterval); 8089474494SKrzysztof Grobelny 8189474494SKrzysztof Grobelny if (!success) 82081ebf06SWludzik, Jozef { 83081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 84081ebf06SWludzik, Jozef return; 85081ebf06SWludzik, Jozef } 86081ebf06SWludzik, Jozef 8789474494SKrzysztof Grobelny if (maxReports != nullptr) 8889474494SKrzysztof Grobelny { 89081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MaxReports"] = *maxReports; 9089474494SKrzysztof Grobelny } 9189474494SKrzysztof Grobelny 9289474494SKrzysztof Grobelny if (minInterval != nullptr) 9389474494SKrzysztof Grobelny { 94081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MinCollectionInterval"] = 9589474494SKrzysztof Grobelny time_utils::toDurationString(std::chrono::milliseconds( 9689474494SKrzysztof Grobelny static_cast<time_t>(*minInterval))); 9789474494SKrzysztof Grobelny } 98479e899dSKrzysztof Grobelny nlohmann::json::array_t supportedCollectionFunctions; 99479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Maximum"); 100479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Minimum"); 101479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Average"); 102479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Summation"); 103479e899dSKrzysztof Grobelny 104479e899dSKrzysztof Grobelny asyncResp->res.jsonValue["SupportedCollectionFunctions"] = 105479e899dSKrzysztof Grobelny std::move(supportedCollectionFunctions); 10689474494SKrzysztof Grobelny }); 107081ebf06SWludzik, Jozef } 10826bd9b57SJohn Edward Broadbent 10926bd9b57SJohn Edward Broadbent inline void requestRoutesTelemetryService(App& app) 11026bd9b57SJohn Edward Broadbent { 11126bd9b57SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 11226bd9b57SJohn Edward Broadbent .privileges(redfish::privileges::getTelemetryService) 11345ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 11445ca1b86SEd Tanous std::bind_front(handleTelemetryServiceGet, std::ref(app))); 11526bd9b57SJohn Edward Broadbent } 11626bd9b57SJohn Edward Broadbent 117081ebf06SWludzik, Jozef } // namespace redfish 118