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" 6d7857201SEd Tanous #include "async_resp.hpp" 7d7857201SEd Tanous #include "dbus_singleton.hpp" 8177612aaSEd Tanous #include "dbus_utility.hpp" 9d7857201SEd Tanous #include "error_messages.hpp" 10d7857201SEd Tanous #include "http_request.hpp" 11d7857201SEd Tanous #include "logging.hpp" 123ccb3adbSEd Tanous #include "query.hpp" 133ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 14*f86cdd7dSEd Tanous #include "telemetry_readings.hpp" 154028ff77SEd Tanous #include "utils/collection.hpp" 16081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp" 17081ebf06SWludzik, Jozef 18d7857201SEd Tanous #include <asm-generic/errno.h> 19d7857201SEd Tanous 20d7857201SEd Tanous #include <boost/beast/http/verb.hpp> 21ef4c65b7SEd Tanous #include <boost/url/format.hpp> 22d7857201SEd Tanous #include <boost/url/url.hpp> 23d7857201SEd Tanous #include <nlohmann/json.hpp> 241e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 257e860f15SJohn Edward Broadbent 267a1dbc48SGeorge Liu #include <array> 27d7857201SEd Tanous #include <cstdint> 28d7857201SEd Tanous #include <memory> 29d7857201SEd Tanous #include <string> 307a1dbc48SGeorge Liu #include <string_view> 31d7857201SEd Tanous #include <utility> 327a1dbc48SGeorge Liu 33081ebf06SWludzik, Jozef namespace redfish 34081ebf06SWludzik, Jozef { 35081ebf06SWludzik, Jozef 367e860f15SJohn Edward Broadbent inline void requestRoutesMetricReportCollection(App& app) 37081ebf06SWludzik, Jozef { 387e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReports/") 39ed398213SEd Tanous .privileges(redfish::privileges::getMetricReportCollection) 407e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 4145ca1b86SEd Tanous [&app](const crow::Request& req, 427e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 433ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 4445ca1b86SEd Tanous { 4545ca1b86SEd Tanous return; 4645ca1b86SEd Tanous } 4745ca1b86SEd Tanous 488d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 49081ebf06SWludzik, Jozef "#MetricReportCollection.MetricReportCollection"; 50ae9031f0SWilly Tu asyncResp->res.jsonValue["@odata.id"] = 51ae9031f0SWilly Tu "/redfish/v1/TelemetryService/MetricReports"; 528d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Metric Report Collection"; 537a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces{ 547a1dbc48SGeorge Liu telemetry::reportInterface}; 554028ff77SEd Tanous collection_util::getCollectionMembers( 56ae9031f0SWilly Tu asyncResp, 57bd79bce8SPatrick Williams boost::urls::url( 58bd79bce8SPatrick Williams "/redfish/v1/TelemetryService/MetricReports"), 59ae9031f0SWilly Tu interfaces, 604028ff77SEd Tanous "/xyz/openbmc_project/Telemetry/Reports/TelemetryService"); 617e860f15SJohn Edward Broadbent }); 62081ebf06SWludzik, Jozef } 63081ebf06SWludzik, Jozef 647e860f15SJohn Edward Broadbent inline void requestRoutesMetricReport(App& app) 65081ebf06SWludzik, Jozef { 667e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReports/<str>/") 67ed398213SEd Tanous .privileges(redfish::privileges::getMetricReport) 687e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 6945ca1b86SEd Tanous [&app](const crow::Request& req, 707e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 717e860f15SJohn Edward Broadbent const std::string& id) { 723ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 7345ca1b86SEd Tanous { 7445ca1b86SEd Tanous return; 7545ca1b86SEd Tanous } 76081ebf06SWludzik, Jozef const std::string reportPath = telemetry::getDbusReportPath(id); 77177612aaSEd Tanous dbus::utility::async_method_call( 78177612aaSEd Tanous asyncResp, 79bd79bce8SPatrick Williams [asyncResp, id, 80bd79bce8SPatrick Williams reportPath](const boost::system::error_code& ec) { 81081ebf06SWludzik, Jozef if (ec.value() == EBADR || 82081ebf06SWludzik, Jozef ec == boost::system::errc::host_unreachable) 83081ebf06SWludzik, Jozef { 84bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, 85bd79bce8SPatrick Williams "MetricReport", id); 86081ebf06SWludzik, Jozef return; 87081ebf06SWludzik, Jozef } 88081ebf06SWludzik, Jozef if (ec) 89081ebf06SWludzik, Jozef { 9062598e31SEd Tanous BMCWEB_LOG_ERROR("respHandler DBus error {}", ec); 91081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 92081ebf06SWludzik, Jozef return; 93081ebf06SWludzik, Jozef } 94081ebf06SWludzik, Jozef 95bd79bce8SPatrick Williams sdbusplus::asio::getProperty< 96bd79bce8SPatrick Williams telemetry::TimestampReadings>( 97bd79bce8SPatrick Williams *crow::connections::systemBus, telemetry::service, 98bd79bce8SPatrick Williams reportPath, telemetry::reportInterface, "Readings", 99bd79bce8SPatrick Williams [asyncResp, 100bd79bce8SPatrick Williams id](const boost::system::error_code& ec2, 1011e1e598dSJonathan Doman const telemetry::TimestampReadings& ret) { 1028a592810SEd Tanous if (ec2) 103081ebf06SWludzik, Jozef { 104bd79bce8SPatrick Williams BMCWEB_LOG_ERROR( 105bd79bce8SPatrick Williams "respHandler DBus error {}", ec2); 106081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 107081ebf06SWludzik, Jozef return; 108081ebf06SWludzik, Jozef } 109081ebf06SWludzik, Jozef 110bd79bce8SPatrick Williams telemetry::fillReport(asyncResp->res.jsonValue, 111bd79bce8SPatrick Williams id, ret); 1121e1e598dSJonathan Doman }); 113081ebf06SWludzik, Jozef }, 114081ebf06SWludzik, Jozef telemetry::service, reportPath, telemetry::reportInterface, 115081ebf06SWludzik, Jozef "Update"); 1167e860f15SJohn Edward Broadbent }); 117081ebf06SWludzik, Jozef } 118081ebf06SWludzik, Jozef } // namespace redfish 119