xref: /openbmc/telemetry/src/report_manager.hpp (revision 5e7cbf42)
1 #pragma once
2 
3 #include "interfaces/json_storage.hpp"
4 #include "interfaces/report.hpp"
5 #include "interfaces/report_factory.hpp"
6 #include "interfaces/report_manager.hpp"
7 #include "interfaces/trigger_manager.hpp"
8 #include "report.hpp"
9 #include "utils/dbus_path_utils.hpp"
10 
11 #include <systemd/sd-bus-protocol.h>
12 
13 #include <sdbusplus/asio/object_server.hpp>
14 
15 #include <chrono>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 class ReportManager : public interfaces::ReportManager
21 {
22   public:
23     ReportManager(
24         std::unique_ptr<interfaces::ReportFactory> reportFactory,
25         std::unique_ptr<interfaces::JsonStorage> reportStorage,
26         const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
27     ~ReportManager() = default;
28 
29     ReportManager(const ReportManager&) = delete;
30     ReportManager(ReportManager&&) = delete;
31     ReportManager& operator=(const ReportManager&) = delete;
32     ReportManager& operator=(ReportManager&&) = delete;
33 
34     void removeReport(const interfaces::Report* report) override;
35 
36     static void verifyMetricParams(
37         const std::vector<LabeledMetricParameters>& metricParams);
38 
39   private:
40     std::unique_ptr<interfaces::ReportFactory> reportFactory;
41     std::unique_ptr<interfaces::JsonStorage> reportStorage;
42     std::shared_ptr<sdbusplus::asio::object_server> objServer;
43     std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface;
44     std::vector<std::unique_ptr<interfaces::Report>> reports;
45 
46     void verifyAddReport(
47         const std::string& reportId, const std::string& reportName,
48         const ReportingType reportingType, Milliseconds interval,
49         const ReportUpdates reportUpdates, const uint64_t appendLimit,
50         const std::vector<LabeledMetricParameters>& readingParams);
51     interfaces::Report& addReport(
52         boost::asio::yield_context& yield, const std::string& reportId,
53         const std::string& reportName, const ReportingType reportingType,
54         const std::vector<ReportAction>& reportActions, Milliseconds interval,
55         const uint64_t appendLimit, const ReportUpdates reportUpdates,
56         ReadingParameters metricParams, const bool enabled);
57     interfaces::Report&
58         addReport(const std::string& reportId, const std::string& reportName,
59                   const ReportingType reportingType,
60                   const std::vector<ReportAction>& reportActions,
61                   Milliseconds interval, const uint64_t appendLimit,
62                   const ReportUpdates reportUpdates,
63                   std::vector<LabeledMetricParameters> metricParams,
64                   const bool enabled, Readings);
65     void loadFromPersistent();
66 
67   public:
68     static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
69     static constexpr size_t maxNumberMetrics{TELEMETRY_MAX_READING_PARAMS};
70     static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
71     static constexpr size_t maxAppendLimit{TELEMETRY_MAX_APPEND_LIMIT};
72     static constexpr const char* reportManagerIfaceName =
73         "xyz.openbmc_project.Telemetry.ReportManager";
74     static constexpr const char* reportManagerPath =
75         "/xyz/openbmc_project/Telemetry/Reports";
76     static constexpr std::string_view reportNameDefault = "Report";
77 
78     static_assert(!reportNameDefault.empty(),
79                   "Default report name cannot be empty.");
80 };
81