Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 1 | #include "report.hpp" |
| 2 | |
| 3 | #include "report_manager.hpp" |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 4 | #include "utils/clock.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 5 | #include "utils/contains.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 6 | #include "utils/transform.hpp" |
| 7 | |
| 8 | #include <phosphor-logging/log.hpp> |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 9 | #include <sdbusplus/vtable.hpp> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 10 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 11 | #include <limits> |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 12 | #include <numeric> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 13 | |
| 14 | Report::Report(boost::asio::io_context& ioc, |
| 15 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 16 | const std::string& reportId, const std::string& reportName, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 17 | const ReportingType reportingTypeIn, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 18 | std::vector<ReportAction> reportActionsIn, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 19 | const Milliseconds intervalIn, const uint64_t appendLimitIn, |
| 20 | const ReportUpdates reportUpdatesIn, |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 21 | interfaces::ReportManager& reportManager, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 22 | interfaces::JsonStorage& reportStorageIn, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 23 | std::vector<std::shared_ptr<interfaces::Metric>> metricsIn, |
| 24 | const bool enabledIn) : |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 25 | id(reportId), |
| 26 | name(reportName), reportingType(reportingTypeIn), interval(intervalIn), |
| 27 | reportActions(std::move(reportActionsIn)), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 28 | sensorCount(getSensorCount(metricsIn)), |
| 29 | appendLimit(deduceAppendLimit(appendLimitIn)), |
| 30 | reportUpdates(reportUpdatesIn), |
| 31 | readingsBuffer(deduceBufferSize(reportUpdates, reportingType)), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 32 | objServer(objServer), metrics(std::move(metricsIn)), timer(ioc), |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 33 | reportStorage(reportStorageIn), enabled(enabledIn) |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 34 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 35 | readingParameters = |
| 36 | toReadingParameters(utils::transform(metrics, [](const auto& metric) { |
| 37 | return metric->dumpConfiguration(); |
| 38 | })); |
| 39 | |
| 40 | readingParametersPastVersion = |
| 41 | utils::transform(readingParameters, [](const auto& item) { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 42 | const auto& [sensorData, operationType, id, collectionTimeScope, |
| 43 | collectionDuration] = item; |
| 44 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 45 | return ReadingParametersPastVersion::value_type( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 46 | std::get<0>(sensorData.front()), operationType, id, |
| 47 | std::get<1>(sensorData.front())); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 48 | }); |
| 49 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 50 | deleteIface = objServer->add_unique_interface( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 51 | getPath(), deleteIfaceName, |
| 52 | [this, &ioc, &reportManager](auto& dbusIface) { |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 53 | dbusIface.register_method("Delete", [this, &ioc, &reportManager] { |
| 54 | if (persistency) |
| 55 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 56 | reportStorage.remove(fileName()); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 57 | } |
| 58 | boost::asio::post(ioc, [this, &reportManager] { |
| 59 | reportManager.removeReport(this); |
| 60 | }); |
| 61 | }); |
| 62 | }); |
| 63 | |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 64 | persistency = storeConfiguration(); |
| 65 | reportIface = makeReportInterface(); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 66 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 67 | if (reportingType == ReportingType::periodic) |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 68 | { |
| 69 | scheduleTimer(interval); |
| 70 | } |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 71 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 72 | if (enabled) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 73 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 74 | for (auto& metric : this->metrics) |
| 75 | { |
| 76 | metric->initialize(); |
| 77 | } |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 78 | } |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 81 | uint64_t Report::getSensorCount( |
| 82 | std::vector<std::shared_ptr<interfaces::Metric>>& metrics) |
| 83 | { |
| 84 | uint64_t sensorCount = 0; |
| 85 | for (auto& metric : metrics) |
| 86 | { |
| 87 | sensorCount += metric->sensorCount(); |
| 88 | } |
| 89 | return sensorCount; |
| 90 | } |
| 91 | |
| 92 | uint64_t Report::deduceAppendLimit(const uint64_t appendLimitIn) const |
| 93 | { |
| 94 | if (appendLimitIn == std::numeric_limits<uint64_t>::max()) |
| 95 | { |
| 96 | return sensorCount; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | return appendLimitIn; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | uint64_t Report::deduceBufferSize(const ReportUpdates reportUpdatesIn, |
| 105 | const ReportingType reportingTypeIn) const |
| 106 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 107 | if (reportUpdatesIn == ReportUpdates::overwrite || |
| 108 | reportingTypeIn == ReportingType::onRequest) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 109 | { |
| 110 | return sensorCount; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | return appendLimit; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void Report::setReportUpdates(const ReportUpdates newReportUpdates) |
| 119 | { |
| 120 | if (reportUpdates != newReportUpdates) |
| 121 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 122 | if (reportingType != ReportingType::onRequest && |
| 123 | (reportUpdates == ReportUpdates::overwrite || |
| 124 | newReportUpdates == ReportUpdates::overwrite)) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 125 | { |
| 126 | readingsBuffer.clearAndResize( |
| 127 | deduceBufferSize(newReportUpdates, reportingType)); |
| 128 | } |
| 129 | reportUpdates = newReportUpdates; |
| 130 | } |
| 131 | } |
| 132 | |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 133 | std::unique_ptr<sdbusplus::asio::dbus_interface> Report::makeReportInterface() |
| 134 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 135 | auto dbusIface = |
| 136 | objServer->add_unique_interface(getPath(), reportIfaceName); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 137 | dbusIface->register_property_rw( |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 138 | "Enabled", enabled, sdbusplus::vtable::property_::emits_change, |
| 139 | [this](bool newVal, const auto&) { |
| 140 | if (newVal != enabled) |
| 141 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 142 | if (true == newVal && ReportingType::periodic == reportingType) |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 143 | { |
| 144 | scheduleTimer(interval); |
| 145 | } |
| 146 | if (newVal) |
| 147 | { |
| 148 | for (auto& metric : metrics) |
| 149 | { |
| 150 | metric->initialize(); |
| 151 | } |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | for (auto& metric : metrics) |
| 156 | { |
| 157 | metric->deinitialize(); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | enabled = newVal; |
| 162 | persistency = storeConfiguration(); |
| 163 | } |
| 164 | return true; |
| 165 | }, |
| 166 | [this](const auto&) { return enabled; }); |
| 167 | dbusIface->register_property_rw( |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 168 | "Interval", interval.count(), |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 169 | sdbusplus::vtable::property_::emits_change, |
| 170 | [this](uint64_t newVal, auto&) { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 171 | if (Milliseconds newValT{newVal}; |
| 172 | newValT >= ReportManager::minInterval) |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 173 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 174 | if (newValT != interval) |
| 175 | { |
| 176 | interval = newValT; |
| 177 | persistency = storeConfiguration(); |
| 178 | } |
| 179 | return true; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 180 | } |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 181 | return false; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 182 | }, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 183 | [this](const auto&) { return interval.count(); }); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 184 | dbusIface->register_property_rw( |
| 185 | "Persistency", persistency, sdbusplus::vtable::property_::emits_change, |
| 186 | [this](bool newVal, const auto&) { |
| 187 | if (newVal == persistency) |
| 188 | { |
| 189 | return true; |
| 190 | } |
| 191 | if (newVal) |
| 192 | { |
| 193 | persistency = storeConfiguration(); |
| 194 | } |
| 195 | else |
| 196 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 197 | reportStorage.remove(fileName()); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 198 | persistency = false; |
| 199 | } |
| 200 | return true; |
| 201 | }, |
| 202 | [this](const auto&) { return persistency; }); |
| 203 | |
| 204 | auto readingsFlag = sdbusplus::vtable::property_::none; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 205 | if (utils::contains(reportActions, ReportAction::emitsReadingsUpdate)) |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 206 | { |
| 207 | readingsFlag = sdbusplus::vtable::property_::emits_change; |
| 208 | } |
| 209 | dbusIface->register_property_r("Readings", readings, readingsFlag, |
| 210 | [this](const auto&) { return readings; }); |
| 211 | dbusIface->register_property_r( |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 212 | "ReportingType", std::string(), sdbusplus::vtable::property_::const_, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 213 | [this](const auto&) { return utils::enumToString(reportingType); }); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 214 | dbusIface->register_property_r( |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 215 | "ReadingParameters", readingParametersPastVersion, |
| 216 | sdbusplus::vtable::property_::const_, |
| 217 | [this](const auto&) { return readingParametersPastVersion; }); |
| 218 | dbusIface->register_property_r( |
| 219 | "ReadingParametersFutureVersion", readingParameters, |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 220 | sdbusplus::vtable::property_::const_, |
| 221 | [this](const auto&) { return readingParameters; }); |
| 222 | dbusIface->register_property_r( |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 223 | "EmitsReadingsUpdate", bool{}, sdbusplus::vtable::property_::const_, |
| 224 | [this](const auto&) { |
| 225 | return utils::contains(reportActions, |
| 226 | ReportAction::emitsReadingsUpdate); |
| 227 | }); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 228 | dbusIface->register_property_r("Name", std::string{}, |
| 229 | sdbusplus::vtable::property_::const_, |
| 230 | [this](const auto&) { return name; }); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 231 | dbusIface->register_property_r( |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 232 | "LogToMetricReportsCollection", bool{}, |
| 233 | sdbusplus::vtable::property_::const_, [this](const auto&) { |
| 234 | return utils::contains(reportActions, |
| 235 | ReportAction::logToMetricReportsCollection); |
| 236 | }); |
| 237 | dbusIface->register_property_r( |
| 238 | "ReportActions", std::vector<std::string>{}, |
| 239 | sdbusplus::vtable::property_::const_, [this](const auto&) { |
| 240 | return utils::transform(reportActions, [](const auto reportAction) { |
| 241 | return utils::enumToString(reportAction); |
| 242 | }); |
| 243 | }); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 244 | dbusIface->register_property_r("AppendLimit", appendLimit, |
| 245 | sdbusplus::vtable::property_::emits_change, |
| 246 | [this](const auto&) { return appendLimit; }); |
| 247 | dbusIface->register_property_rw( |
| 248 | "ReportUpdates", std::string(), |
| 249 | sdbusplus::vtable::property_::emits_change, |
| 250 | [this](auto newVal, auto& oldVal) { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 251 | ReportManager::verifyReportUpdates(utils::toReportUpdates(newVal)); |
| 252 | setReportUpdates(utils::toReportUpdates(newVal)); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 253 | oldVal = newVal; |
| 254 | return true; |
| 255 | }, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 256 | [this](const auto&) { return utils::enumToString(reportUpdates); }); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 257 | dbusIface->register_method("Update", [this] { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 258 | if (reportingType == ReportingType::onRequest) |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 259 | { |
| 260 | updateReadings(); |
| 261 | } |
| 262 | }); |
| 263 | constexpr bool skipPropertiesChangedSignal = true; |
| 264 | dbusIface->initialize(skipPropertiesChangedSignal); |
| 265 | return dbusIface; |
| 266 | } |
| 267 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 268 | void Report::timerProc(boost::system::error_code ec, Report& self) |
| 269 | { |
| 270 | if (ec) |
| 271 | { |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | self.updateReadings(); |
| 276 | self.scheduleTimer(self.interval); |
| 277 | } |
| 278 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 279 | void Report::scheduleTimer(Milliseconds timerInterval) |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 280 | { |
| 281 | timer.expires_after(timerInterval); |
| 282 | timer.async_wait( |
| 283 | [this](boost::system::error_code ec) { timerProc(ec, *this); }); |
| 284 | } |
| 285 | |
| 286 | void Report::updateReadings() |
| 287 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 288 | if (!enabled) |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 289 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 290 | return; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 291 | } |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 292 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 293 | if (reportUpdates == ReportUpdates::overwrite || |
| 294 | reportingType == ReportingType::onRequest) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 295 | { |
| 296 | readingsBuffer.clear(); |
| 297 | } |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 298 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 299 | for (const auto& metric : metrics) |
| 300 | { |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 301 | for (const auto& [id, metadata, value, timestamp] : |
| 302 | metric->getReadings()) |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 303 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 304 | if (reportUpdates == ReportUpdates::appendStopsWhenFull && |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 305 | readingsBuffer.isFull()) |
| 306 | { |
| 307 | enabled = false; |
| 308 | for (auto& metric : metrics) |
| 309 | { |
| 310 | metric->deinitialize(); |
| 311 | } |
| 312 | break; |
| 313 | } |
| 314 | readingsBuffer.emplace(id, metadata, value, timestamp); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 315 | } |
| 316 | } |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 317 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 318 | readings = { |
| 319 | Clock().timestamp(), |
| 320 | std::vector<ReadingData>(readingsBuffer.begin(), readingsBuffer.end())}; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 321 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 322 | reportIface->signal_property("Readings"); |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 323 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 324 | |
| 325 | bool Report::storeConfiguration() const |
| 326 | { |
| 327 | try |
| 328 | { |
| 329 | nlohmann::json data; |
| 330 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 331 | data["Enabled"] = enabled; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 332 | data["Version"] = reportVersion; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 333 | data["Id"] = id; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 334 | data["Name"] = name; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 335 | data["ReportingType"] = utils::toUnderlying(reportingType); |
| 336 | data["ReportActions"] = |
| 337 | utils::transform(reportActions, [](const auto reportAction) { |
| 338 | return utils::toUnderlying(reportAction); |
| 339 | }); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 340 | data["Interval"] = interval.count(); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 341 | data["AppendLimit"] = appendLimit; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 342 | data["ReportUpdates"] = utils::toUnderlying(reportUpdates); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 343 | data["ReadingParameters"] = |
| 344 | utils::transform(metrics, [](const auto& metric) { |
| 345 | return metric->dumpConfiguration(); |
| 346 | }); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 347 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 348 | reportStorage.store(fileName(), data); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 349 | } |
| 350 | catch (const std::exception& e) |
| 351 | { |
| 352 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 353 | "Failed to store a report in storage", |
Wludzik, Jozef | 982c5b5 | 2021-01-02 12:05:21 +0100 | [diff] [blame] | 354 | phosphor::logging::entry("EXCEPTION_MSG=%s", e.what())); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | |
| 358 | return true; |
| 359 | } |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame^] | 360 | interfaces::JsonStorage::FilePath Report::fileName() const |
| 361 | { |
| 362 | return interfaces::JsonStorage::FilePath{ |
| 363 | std::to_string(std::hash<std::string>{}(id))}; |
| 364 | } |