xref: /openbmc/bmcweb/features/redfish/src/dbus_log_watcher.cpp (revision b26ff34d5c35b623b0eb7de24f952d4c5d2459bf)
1*b26ff34dSEd Tanous #include "dbus_log_watcher.hpp"
2*b26ff34dSEd Tanous 
3*b26ff34dSEd Tanous #include "dbus_utility.hpp"
4*b26ff34dSEd Tanous #include "event_service_manager.hpp"
5*b26ff34dSEd Tanous #include "logging.hpp"
6*b26ff34dSEd Tanous #include "metric_report.hpp"
7*b26ff34dSEd Tanous 
8*b26ff34dSEd Tanous #include <sdbusplus/message.hpp>
9*b26ff34dSEd Tanous #include <sdbusplus/message/native_types.hpp>
10*b26ff34dSEd Tanous 
11*b26ff34dSEd Tanous #include <algorithm>
12*b26ff34dSEd Tanous #include <string>
13*b26ff34dSEd Tanous #include <variant>
14*b26ff34dSEd Tanous #include <vector>
15*b26ff34dSEd Tanous 
16*b26ff34dSEd Tanous namespace redfish
17*b26ff34dSEd Tanous {
18*b26ff34dSEd Tanous void getReadingsForReport(sdbusplus::message_t& msg)
19*b26ff34dSEd Tanous {
20*b26ff34dSEd Tanous     if (msg.is_method_error())
21*b26ff34dSEd Tanous     {
22*b26ff34dSEd Tanous         BMCWEB_LOG_ERROR("TelemetryMonitor Signal error");
23*b26ff34dSEd Tanous         return;
24*b26ff34dSEd Tanous     }
25*b26ff34dSEd Tanous 
26*b26ff34dSEd Tanous     sdbusplus::message::object_path path(msg.get_path());
27*b26ff34dSEd Tanous     std::string id = path.filename();
28*b26ff34dSEd Tanous     if (id.empty())
29*b26ff34dSEd Tanous     {
30*b26ff34dSEd Tanous         BMCWEB_LOG_ERROR("Failed to get Id from path");
31*b26ff34dSEd Tanous         return;
32*b26ff34dSEd Tanous     }
33*b26ff34dSEd Tanous 
34*b26ff34dSEd Tanous     std::string interface;
35*b26ff34dSEd Tanous     dbus::utility::DBusPropertiesMap props;
36*b26ff34dSEd Tanous     std::vector<std::string> invalidProps;
37*b26ff34dSEd Tanous     msg.read(interface, props, invalidProps);
38*b26ff34dSEd Tanous 
39*b26ff34dSEd Tanous     auto found = std::ranges::find_if(props, [](const auto& x) {
40*b26ff34dSEd Tanous         return x.first == "Readings";
41*b26ff34dSEd Tanous     });
42*b26ff34dSEd Tanous     if (found == props.end())
43*b26ff34dSEd Tanous     {
44*b26ff34dSEd Tanous         BMCWEB_LOG_INFO("Failed to get Readings from Report properties");
45*b26ff34dSEd Tanous         return;
46*b26ff34dSEd Tanous     }
47*b26ff34dSEd Tanous 
48*b26ff34dSEd Tanous     const telemetry::TimestampReadings* readings =
49*b26ff34dSEd Tanous         std::get_if<telemetry::TimestampReadings>(&found->second);
50*b26ff34dSEd Tanous     if (readings == nullptr)
51*b26ff34dSEd Tanous     {
52*b26ff34dSEd Tanous         BMCWEB_LOG_INFO("Failed to get Readings from Report properties");
53*b26ff34dSEd Tanous         return;
54*b26ff34dSEd Tanous     }
55*b26ff34dSEd Tanous     EventServiceManager::sendTelemetryReportToSubs(id, *readings);
56*b26ff34dSEd Tanous }
57*b26ff34dSEd Tanous } // namespace redfish
58