xref: /openbmc/bmcweb/features/redfish/lib/telemetry_service.hpp (revision 3ccb3adb9a14783f6bef601506de9f8bcae22d51)
1081ebf06SWludzik, Jozef #pragma once
2081ebf06SWludzik, Jozef 
3*3ccb3adbSEd Tanous #include "app.hpp"
4*3ccb3adbSEd Tanous #include "dbus_utility.hpp"
5*3ccb3adbSEd Tanous #include "query.hpp"
6*3ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
7*3ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
8081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp"
9081ebf06SWludzik, Jozef 
1089474494SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp>
1189474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
127e860f15SJohn Edward Broadbent 
13081ebf06SWludzik, Jozef namespace redfish
14081ebf06SWludzik, Jozef {
15081ebf06SWludzik, Jozef 
1626bd9b57SJohn Edward Broadbent inline void handleTelemetryServiceGet(
1745ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
18104f09c9SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
19081ebf06SWludzik, Jozef {
203ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2145ca1b86SEd Tanous     {
2245ca1b86SEd Tanous         return;
2345ca1b86SEd Tanous     }
248d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
25081ebf06SWludzik, Jozef         "#TelemetryService.v1_2_1.TelemetryService";
2626bd9b57SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
278d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "TelemetryService";
288d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Telemetry Service";
29081ebf06SWludzik, Jozef 
308d1b46d7Szhanghch05     asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
31081ebf06SWludzik, Jozef         "/redfish/v1/TelemetryService/MetricReportDefinitions";
328d1b46d7Szhanghch05     asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
33081ebf06SWludzik, Jozef         "/redfish/v1/TelemetryService/MetricReports";
3407148cf2SLukasz Kazmierczak     asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
3507148cf2SLukasz Kazmierczak         "/redfish/v1/TelemetryService/Triggers";
36081ebf06SWludzik, Jozef 
3789474494SKrzysztof Grobelny     sdbusplus::asio::getAllProperties(
3889474494SKrzysztof Grobelny         *crow::connections::systemBus, telemetry::service,
3989474494SKrzysztof Grobelny         "/xyz/openbmc_project/Telemetry/Reports",
4089474494SKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.ReportManager",
41b9d36b47SEd Tanous         [asyncResp](const boost::system::error_code ec,
42b9d36b47SEd Tanous                     const dbus::utility::DBusPropertiesMap& ret) {
43081ebf06SWludzik, Jozef         if (ec == boost::system::errc::host_unreachable)
44081ebf06SWludzik, Jozef         {
45081ebf06SWludzik, Jozef             asyncResp->res.jsonValue["Status"]["State"] = "Absent";
46081ebf06SWludzik, Jozef             return;
47081ebf06SWludzik, Jozef         }
48081ebf06SWludzik, Jozef         if (ec)
49081ebf06SWludzik, Jozef         {
50081ebf06SWludzik, Jozef             BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
51081ebf06SWludzik, Jozef             messages::internalError(asyncResp->res);
52081ebf06SWludzik, Jozef             return;
53081ebf06SWludzik, Jozef         }
54081ebf06SWludzik, Jozef 
55081ebf06SWludzik, Jozef         asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
56081ebf06SWludzik, Jozef 
57081ebf06SWludzik, Jozef         const size_t* maxReports = nullptr;
58081ebf06SWludzik, Jozef         const uint64_t* minInterval = nullptr;
5989474494SKrzysztof Grobelny 
6089474494SKrzysztof Grobelny         const bool success = sdbusplus::unpackPropertiesNoThrow(
6189474494SKrzysztof Grobelny             dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
6289474494SKrzysztof Grobelny             "MinInterval", minInterval);
6389474494SKrzysztof Grobelny 
6489474494SKrzysztof Grobelny         if (!success)
65081ebf06SWludzik, Jozef         {
66081ebf06SWludzik, Jozef             messages::internalError(asyncResp->res);
67081ebf06SWludzik, Jozef             return;
68081ebf06SWludzik, Jozef         }
69081ebf06SWludzik, Jozef 
7089474494SKrzysztof Grobelny         if (maxReports != nullptr)
7189474494SKrzysztof Grobelny         {
72081ebf06SWludzik, Jozef             asyncResp->res.jsonValue["MaxReports"] = *maxReports;
7389474494SKrzysztof Grobelny         }
7489474494SKrzysztof Grobelny 
7589474494SKrzysztof Grobelny         if (minInterval != nullptr)
7689474494SKrzysztof Grobelny         {
77081ebf06SWludzik, Jozef             asyncResp->res.jsonValue["MinCollectionInterval"] =
7889474494SKrzysztof Grobelny                 time_utils::toDurationString(std::chrono::milliseconds(
7989474494SKrzysztof Grobelny                     static_cast<time_t>(*minInterval)));
8089474494SKrzysztof Grobelny         }
8189474494SKrzysztof Grobelny         });
82081ebf06SWludzik, Jozef }
8326bd9b57SJohn Edward Broadbent 
8426bd9b57SJohn Edward Broadbent inline void requestRoutesTelemetryService(App& app)
8526bd9b57SJohn Edward Broadbent {
8626bd9b57SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
8726bd9b57SJohn Edward Broadbent         .privileges(redfish::privileges::getTelemetryService)
8845ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
8945ca1b86SEd Tanous             std::bind_front(handleTelemetryServiceGet, std::ref(app)));
9026bd9b57SJohn Edward Broadbent }
9126bd9b57SJohn Edward Broadbent 
92081ebf06SWludzik, Jozef } // namespace redfish
93