Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 1 | #include "report_manager.hpp" |
| 2 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 3 | #include "report.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 4 | #include "types/report_types.hpp" |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 5 | #include "utils/conversion.hpp" |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 6 | #include "utils/generate_id.hpp" |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 7 | #include "utils/transform.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 8 | |
| 9 | #include <phosphor-logging/log.hpp> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 10 | #include <sdbusplus/exception.hpp> |
| 11 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 12 | #include <stdexcept> |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 13 | #include <system_error> |
| 14 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 15 | ReadingParameters |
| 16 | convertToReadingParameters(ReadingParametersPastVersion params) |
| 17 | { |
| 18 | return utils::transform(params, [](const auto& param) { |
| 19 | using namespace std::chrono_literals; |
| 20 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 21 | const auto& [sensorPath, operationType, id, metadata] = param; |
| 22 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 23 | return ReadingParameters::value_type( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 24 | std::vector< |
| 25 | std::tuple<sdbusplus::message::object_path, std::string>>{ |
| 26 | {sensorPath, metadata}}, |
| 27 | operationType, id, utils::enumToString(CollectionTimeScope::point), |
| 28 | 0u); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 29 | }); |
| 30 | } |
| 31 | |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 32 | ReportManager::ReportManager( |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 33 | std::unique_ptr<interfaces::ReportFactory> reportFactoryIn, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 34 | std::unique_ptr<interfaces::JsonStorage> reportStorageIn, |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 35 | const std::shared_ptr<sdbusplus::asio::object_server>& objServerIn) : |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 36 | reportFactory(std::move(reportFactoryIn)), |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 37 | reportStorage(std::move(reportStorageIn)), objServer(objServerIn) |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 38 | { |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 39 | reports.reserve(maxReports); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 40 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 41 | loadFromPersistent(); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 42 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 43 | reportManagerIface = objServer->add_unique_interface( |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 44 | reportManagerPath, reportManagerIfaceName, [this](auto& dbusIface) { |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 45 | dbusIface.register_property_r( |
Wludzik, Jozef | 503c158 | 2020-12-11 14:48:01 +0100 | [diff] [blame] | 46 | "MaxReports", size_t{}, sdbusplus::vtable::property_::const_, |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 47 | [](const auto&) { return maxReports; }); |
| 48 | dbusIface.register_property_r( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 49 | "MaxReportIdLength", size_t{}, |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 50 | sdbusplus::vtable::property_::const_, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 51 | [](const auto&) { return maxReportIdLength; }); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 52 | dbusIface.register_property_r( |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 53 | "MinInterval", uint64_t{}, sdbusplus::vtable::property_::const_, |
| 54 | [](const auto&) -> uint64_t { return minInterval.count(); }); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 55 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 56 | dbusIface.register_method( |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 57 | "AddReport", [this](boost::asio::yield_context& yield, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 58 | const std::string& reportId, |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 59 | const std::string& reportingType, |
| 60 | const bool emitsReadingsUpdate, |
| 61 | const bool logToMetricReportsCollection, |
| 62 | const uint64_t interval, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 63 | ReadingParametersPastVersion metricParams) { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 64 | constexpr auto enabledDefault = true; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 65 | constexpr uint64_t appendLimitDefault = 0; |
| 66 | constexpr ReportUpdates reportUpdatesDefault = |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 67 | ReportUpdates::overwrite; |
| 68 | |
| 69 | std::vector<ReportAction> reportActions; |
| 70 | |
| 71 | if (emitsReadingsUpdate) |
| 72 | { |
| 73 | reportActions.emplace_back( |
| 74 | ReportAction::emitsReadingsUpdate); |
| 75 | } |
| 76 | if (logToMetricReportsCollection) |
| 77 | { |
| 78 | reportActions.emplace_back( |
| 79 | ReportAction::logToMetricReportsCollection); |
| 80 | } |
| 81 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 82 | return addReport(yield, reportId, reportId, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 83 | utils::toReportingType(reportingType), |
| 84 | reportActions, Milliseconds(interval), |
| 85 | appendLimitDefault, reportUpdatesDefault, |
| 86 | convertToReadingParameters( |
| 87 | std::move(metricParams)), |
| 88 | enabledDefault) |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 89 | .getPath(); |
| 90 | }); |
| 91 | |
| 92 | dbusIface.register_method( |
| 93 | "AddReportFutureVersion", |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 94 | [this]( |
| 95 | boost::asio::yield_context& yield, |
| 96 | const std::string& reportId, const std::string& reportName, |
| 97 | const std::string& reportingType, |
| 98 | const std::string& reportUpdates, |
| 99 | const uint64_t appendLimit, |
| 100 | const std::vector<std::string>& reportActions, |
| 101 | const uint64_t interval, ReadingParameters metricParams) { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 102 | constexpr auto enabledDefault = true; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 103 | return addReport(yield, reportId, reportName, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 104 | utils::toReportingType(reportingType), |
| 105 | utils::transform( |
| 106 | reportActions, |
| 107 | [](const auto& reportAction) { |
| 108 | return utils::toReportAction( |
| 109 | reportAction); |
| 110 | }), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 111 | Milliseconds(interval), appendLimit, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 112 | utils::toReportUpdates(reportUpdates), |
| 113 | std::move(metricParams), enabledDefault) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 114 | .getPath(); |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 115 | }); |
| 116 | }); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 119 | void ReportManager::removeReport(const interfaces::Report* report) |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 120 | { |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 121 | reports.erase( |
| 122 | std::remove_if(reports.begin(), reports.end(), |
| 123 | [report](const auto& x) { return report == x.get(); }), |
| 124 | reports.end()); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 125 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 126 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 127 | void ReportManager::verifyReportIdLength(const std::string& reportId) |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 128 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 129 | if (reportId.length() > maxReportIdLength) |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 130 | { |
| 131 | throw sdbusplus::exception::SdBusError( |
| 132 | static_cast<int>(std::errc::invalid_argument), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 133 | "Report id exceeds maximum length"); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 137 | void ReportManager::verifyAddReport( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 138 | const std::string& reportId, const std::string& reportName, |
| 139 | const ReportingType reportingType, Milliseconds interval, |
| 140 | const ReportUpdates reportUpdates, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 141 | const std::vector<LabeledMetricParameters>& readingParams) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 142 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 143 | if (reportingType == ReportingType::onChange) |
| 144 | { |
| 145 | throw sdbusplus::exception::SdBusError( |
| 146 | static_cast<int>(std::errc::invalid_argument), |
| 147 | "Invalid reportingType"); |
| 148 | } |
| 149 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 150 | if (reports.size() >= maxReports) |
| 151 | { |
| 152 | throw sdbusplus::exception::SdBusError( |
| 153 | static_cast<int>(std::errc::too_many_files_open), |
| 154 | "Reached maximal report count"); |
| 155 | } |
| 156 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 157 | verifyReportIdLength(reportId); |
| 158 | utils::verifyIdCharacters(reportId); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 159 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 160 | for (const auto& report : reports) |
| 161 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 162 | if (report->getId() == reportId) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 163 | { |
| 164 | throw sdbusplus::exception::SdBusError( |
| 165 | static_cast<int>(std::errc::file_exists), "Duplicate report"); |
| 166 | } |
| 167 | } |
| 168 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 169 | verifyReportUpdates(reportUpdates); |
| 170 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 171 | if (reportingType == ReportingType::periodic && interval < minInterval) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 172 | { |
| 173 | throw sdbusplus::exception::SdBusError( |
| 174 | static_cast<int>(std::errc::invalid_argument), "Invalid interval"); |
| 175 | } |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 176 | |
Wludzik, Jozef | 503c158 | 2020-12-11 14:48:01 +0100 | [diff] [blame] | 177 | if (readingParams.size() > maxReadingParams) |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 178 | |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 179 | { |
| 180 | throw sdbusplus::exception::SdBusError( |
| 181 | static_cast<int>(std::errc::argument_list_too_long), |
| 182 | "Too many reading parameters"); |
| 183 | } |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 184 | |
| 185 | try |
| 186 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 187 | namespace ts = utils::tstring; |
| 188 | |
| 189 | for (const LabeledMetricParameters& item : readingParams) |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 190 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 191 | utils::toOperationType( |
| 192 | utils::toUnderlying(item.at_label<ts::OperationType>())); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | catch (const std::exception& e) |
| 196 | { |
| 197 | throw sdbusplus::exception::SdBusError( |
| 198 | static_cast<int>(std::errc::invalid_argument), e.what()); |
| 199 | } |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 200 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 201 | |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 202 | interfaces::Report& ReportManager::addReport( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 203 | boost::asio::yield_context& yield, const std::string& reportId, |
| 204 | const std::string& reportName, const ReportingType reportingType, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 205 | const std::vector<ReportAction>& reportActions, Milliseconds interval, |
| 206 | const uint64_t appendLimit, const ReportUpdates reportUpdates, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 207 | ReadingParameters metricParams, const bool enabled) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 208 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 209 | auto labeledMetricParams = |
| 210 | reportFactory->convertMetricParams(yield, metricParams); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 211 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 212 | return addReport(reportId, reportName, reportingType, reportActions, |
| 213 | interval, appendLimit, reportUpdates, |
| 214 | std::move(labeledMetricParams), enabled); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | interfaces::Report& ReportManager::addReport( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 218 | const std::string& reportId, const std::string& reportName, |
| 219 | const ReportingType reportingType, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 220 | const std::vector<ReportAction>& reportActions, Milliseconds interval, |
| 221 | const uint64_t appendLimit, const ReportUpdates reportUpdates, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 222 | std::vector<LabeledMetricParameters> labeledMetricParams, |
| 223 | const bool enabled) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 224 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 225 | std::string name = reportName; |
| 226 | if (name.empty()) |
| 227 | { |
| 228 | name = "Report"; |
| 229 | } |
| 230 | |
| 231 | const auto existingReportIds = utils::transform( |
| 232 | reports, [](const auto& report) { return report->getId(); }); |
| 233 | |
| 234 | std::string id = |
| 235 | utils::generateId(reportId, name, existingReportIds, maxReportIdLength); |
| 236 | |
| 237 | verifyAddReport(id, name, reportingType, interval, reportUpdates, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 238 | labeledMetricParams); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 239 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 240 | reports.emplace_back(reportFactory->make( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 241 | id, name, reportingType, reportActions, interval, appendLimit, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 242 | reportUpdates, *this, *reportStorage, labeledMetricParams, enabled)); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 243 | return *reports.back(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void ReportManager::loadFromPersistent() |
| 247 | { |
| 248 | std::vector<interfaces::JsonStorage::FilePath> paths = |
| 249 | reportStorage->list(); |
| 250 | |
| 251 | for (const auto& path : paths) |
| 252 | { |
| 253 | std::optional<nlohmann::json> data = reportStorage->load(path); |
| 254 | try |
| 255 | { |
| 256 | size_t version = data->at("Version").get<size_t>(); |
| 257 | if (version != Report::reportVersion) |
| 258 | { |
| 259 | throw std::logic_error("Invalid version"); |
| 260 | } |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 261 | bool enabled = data->at("Enabled").get<bool>(); |
| 262 | std::string& id = data->at("Id").get_ref<std::string&>(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 263 | std::string& name = data->at("Name").get_ref<std::string&>(); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 264 | |
| 265 | uint32_t reportingType = data->at("ReportingType").get<uint32_t>(); |
| 266 | std::vector<ReportAction> reportActions = utils::transform( |
| 267 | data->at("ReportActions").get<std::vector<uint32_t>>(), |
| 268 | [](const auto reportAction) { |
| 269 | return utils::toReportAction(reportAction); |
| 270 | }); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 271 | uint64_t interval = data->at("Interval").get<uint64_t>(); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 272 | uint64_t appendLimit = data->at("AppendLimit").get<uint64_t>(); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 273 | uint32_t reportUpdates = data->at("ReportUpdates").get<uint32_t>(); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 274 | auto readingParameters = |
| 275 | data->at("ReadingParameters") |
| 276 | .get<std::vector<LabeledMetricParameters>>(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 277 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 278 | addReport(id, name, utils::toReportingType(reportingType), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 279 | reportActions, Milliseconds(interval), appendLimit, |
| 280 | utils::toReportUpdates(reportUpdates), |
| 281 | std::move(readingParameters), enabled); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 282 | } |
| 283 | catch (const std::exception& e) |
| 284 | { |
| 285 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 286 | "Failed to load report from storage", |
| 287 | phosphor::logging::entry( |
Wludzik, Jozef | 982c5b5 | 2021-01-02 12:05:21 +0100 | [diff] [blame] | 288 | "FILENAME=%s", |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 289 | static_cast<std::filesystem::path>(path).c_str()), |
Wludzik, Jozef | 982c5b5 | 2021-01-02 12:05:21 +0100 | [diff] [blame] | 290 | phosphor::logging::entry("EXCEPTION_MSG=%s", e.what())); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 291 | reportStorage->remove(path); |
| 292 | } |
| 293 | } |
| 294 | } |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 295 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 296 | void ReportManager::updateReport(const std::string& id) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 297 | { |
| 298 | for (auto& report : reports) |
| 299 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 300 | if (report->getId() == id) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 301 | { |
| 302 | report->updateReadings(); |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | } |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 307 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 308 | void ReportManager::verifyReportUpdates(const ReportUpdates reportUpdates) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 309 | { |
| 310 | if (std::find(supportedReportUpdates.begin(), supportedReportUpdates.end(), |
| 311 | reportUpdates) == supportedReportUpdates.end()) |
| 312 | { |
| 313 | throw sdbusplus::exception::SdBusError( |
| 314 | static_cast<int>(std::errc::invalid_argument), |
| 315 | "Invalid ReportUpdates"); |
| 316 | } |
| 317 | } |