xref: /openbmc/telemetry/src/report_manager.hpp (revision 51497a0c878d939c9ed2a6ed30d12b465af4d51c)
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& name) 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 verifyReportNameLength(const std::string& reportName);
43     void verifyAddReport(
44         const std::string& reportName, const ReportingType reportingType,
45         Milliseconds interval, const ReportUpdates reportUpdates,
46         const std::vector<LabeledMetricParameters>& readingParams);
47     interfaces::Report& addReport(
48         boost::asio::yield_context& yield, const std::string& reportName,
49         const ReportingType reportingType,
50         const std::vector<ReportAction>& reportActions, Milliseconds interval,
51         const uint64_t appendLimit, const ReportUpdates reportUpdates,
52         ReadingParameters metricParams, const bool enabled);
53     interfaces::Report& addReport(
54         const std::string& reportName, const ReportingType reportingType,
55         const std::vector<ReportAction>& reportActions, Milliseconds interval,
56         const uint64_t appendLimit, const ReportUpdates reportUpdates,
57         std::vector<LabeledMetricParameters> metricParams, const bool enabled);
58     void loadFromPersistent();
59 
60   public:
61     static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
62     static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
63     static constexpr size_t maxReportNameLength{
64         TELEMETRY_MAX_DBUS_PATH_LENGTH -
65         std::string_view(Report::reportDir).length()};
66     static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
67     static constexpr const char* reportManagerIfaceName =
68         "xyz.openbmc_project.Telemetry.ReportManager";
69     static constexpr const char* reportManagerPath =
70         "/xyz/openbmc_project/Telemetry/Reports";
71     static constexpr std::array<ReportUpdates, 3> supportedReportUpdates = {
72         ReportUpdates::overwrite, ReportUpdates::appendStopsWhenFull,
73         ReportUpdates::appendWrapsWhenFull};
74 
75     static void verifyReportUpdates(const ReportUpdates reportUpdates);
76 };
77