xref: /openbmc/telemetry/src/report_manager.hpp (revision b8cc78ddf9cc87c83176c7bda575ceef2678d00f)
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 "report.hpp"
8 
9 #include <systemd/sd-bus-protocol.h>
10 
11 #include <sdbusplus/asio/object_server.hpp>
12 
13 #include <chrono>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 class ReportManager : public interfaces::ReportManager
19 {
20   public:
21     ReportManager(
22         std::unique_ptr<interfaces::ReportFactory> reportFactory,
23         std::unique_ptr<interfaces::JsonStorage> reportStorage,
24         const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
25     ~ReportManager() = default;
26 
27     ReportManager(ReportManager&) = delete;
28     ReportManager(ReportManager&&) = delete;
29     ReportManager& operator=(ReportManager&) = delete;
30     ReportManager& operator=(ReportManager&&) = delete;
31 
32     void removeReport(const interfaces::Report* report) override;
33     void updateReport(const std::string& id) override;
34 
35   private:
36     std::unique_ptr<interfaces::ReportFactory> reportFactory;
37     std::unique_ptr<interfaces::JsonStorage> reportStorage;
38     std::shared_ptr<sdbusplus::asio::object_server> objServer;
39     std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface;
40     std::vector<std::unique_ptr<interfaces::Report>> reports;
41 
42     void verifyReportIdLength(const std::string& reportName);
43     void verifyAddReport(
44         const std::string& reportId, const std::string& reportName,
45         const ReportingType reportingType, Milliseconds interval,
46         const ReportUpdates reportUpdates,
47         const std::vector<LabeledMetricParameters>& readingParams);
48     interfaces::Report& addReport(
49         boost::asio::yield_context& yield, const std::string& reportId,
50         const std::string& reportName, const ReportingType reportingType,
51         const std::vector<ReportAction>& reportActions, Milliseconds interval,
52         const uint64_t appendLimit, const ReportUpdates reportUpdates,
53         ReadingParameters metricParams, const bool enabled);
54     interfaces::Report& addReport(
55         const std::string& reportId, const std::string& reportName,
56         const ReportingType reportingType,
57         const std::vector<ReportAction>& reportActions, Milliseconds interval,
58         const uint64_t appendLimit, const ReportUpdates reportUpdates,
59         std::vector<LabeledMetricParameters> metricParams, const bool enabled);
60     void loadFromPersistent();
61 
62   public:
63     static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
64     static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
65     static constexpr size_t maxReportIdLength{
66         TELEMETRY_MAX_DBUS_PATH_LENGTH -
67         std::string_view(Report::reportDir).length()};
68     static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
69     static constexpr const char* reportManagerIfaceName =
70         "xyz.openbmc_project.Telemetry.ReportManager";
71     static constexpr const char* reportManagerPath =
72         "/xyz/openbmc_project/Telemetry/Reports";
73     static constexpr std::array<ReportUpdates, 3> supportedReportUpdates = {
74         ReportUpdates::overwrite, ReportUpdates::appendStopsWhenFull,
75         ReportUpdates::appendWrapsWhenFull};
76 
77     static void verifyReportUpdates(const ReportUpdates reportUpdates);
78 };
79