blob: a5cc4c7c5a8474e469bf2be18691ccf13a47aa40 [file] [log] [blame]
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02001#pragma once
2
Wludzik, Jozef081ebf02020-04-27 17:24:15 +02003#include "utils/telemetry_utils.hpp"
4
John Edward Broadbent7e860f12021-04-08 15:57:16 -07005#include <app.hpp>
Ed Tanous168e20c2021-12-13 14:39:53 -08006#include <dbus_utility.hpp>
Ed Tanous45ca1b82022-03-25 13:07:27 -07007#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -07008#include <registries/privilege_registry.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -07009
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020010namespace redfish
11{
12
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070013inline void handleTelemetryServiceGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070014 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080015 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070016{
Ed Tanous45ca1b82022-03-25 13:07:27 -070017 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
18 {
19 return;
20 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070021 asyncResp->res.jsonValue["@odata.type"] =
22 "#TelemetryService.v1_2_1.TelemetryService";
23 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
24 asyncResp->res.jsonValue["Id"] = "TelemetryService";
25 asyncResp->res.jsonValue["Name"] = "Telemetry Service";
26
27 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] =
28 "/redfish/v1/TelemetryService/MetricReportDefinitions";
29 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] =
30 "/redfish/v1/TelemetryService/MetricReports";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020031 asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
32 "/redfish/v1/TelemetryService/Triggers";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070033
34 crow::connections::systemBus->async_method_call(
Ed Tanousb9d36b42022-02-26 21:42:46 -080035 [asyncResp](const boost::system::error_code ec,
36 const dbus::utility::DBusPropertiesMap& ret) {
Ed Tanous002d39b2022-05-31 08:59:27 -070037 if (ec == boost::system::errc::host_unreachable)
38 {
39 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
40 return;
41 }
42 if (ec)
43 {
44 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec;
45 messages::internalError(asyncResp->res);
46 return;
47 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070048
Ed Tanous002d39b2022-05-31 08:59:27 -070049 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070050
Ed Tanous002d39b2022-05-31 08:59:27 -070051 const size_t* maxReports = nullptr;
52 const uint64_t* minInterval = nullptr;
53 for (const auto& [key, var] : ret)
54 {
55 if (key == "MaxReports")
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070056 {
Ed Tanous002d39b2022-05-31 08:59:27 -070057 maxReports = std::get_if<size_t>(&var);
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070058 }
Ed Tanous002d39b2022-05-31 08:59:27 -070059 else if (key == "MinInterval")
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070060 {
Ed Tanous002d39b2022-05-31 08:59:27 -070061 minInterval = std::get_if<uint64_t>(&var);
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070062 }
Ed Tanous002d39b2022-05-31 08:59:27 -070063 }
64 if (maxReports == nullptr || minInterval == nullptr)
65 {
66 BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
67 messages::internalError(asyncResp->res);
68 return;
69 }
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070070
Ed Tanous002d39b2022-05-31 08:59:27 -070071 asyncResp->res.jsonValue["MaxReports"] = *maxReports;
72 asyncResp->res.jsonValue["MinCollectionInterval"] =
73 time_utils::toDurationString(
74 std::chrono::milliseconds(static_cast<time_t>(*minInterval)));
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070075 },
76 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
77 "org.freedesktop.DBus.Properties", "GetAll",
78 "xyz.openbmc_project.Telemetry.ReportManager");
79}
80
John Edward Broadbent7e860f12021-04-08 15:57:16 -070081inline void requestRoutesTelemetryService(App& app)
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020082{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070083 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
Ed Tanoused398212021-06-09 17:05:54 -070084 .privileges(redfish::privileges::getTelemetryService)
Ed Tanous45ca1b82022-03-25 13:07:27 -070085 .methods(boost::beast::http::verb::get)(
86 std::bind_front(handleTelemetryServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070087}
John Edward Broadbent26bd9b52021-07-12 14:06:30 -070088
Wludzik, Jozef081ebf02020-04-27 17:24:15 +020089} // namespace redfish