blob: e3755a7facbd61c035dc863b3d196c22c507ae84 [file] [log] [blame]
Jagpal Singh Gill15dde862024-10-16 09:42:54 -07001#include "LeakEvents.hpp"
2
3#include "LeakGPIODetector.hpp"
4
5#include <phosphor-logging/commit.hpp>
6#include <phosphor-logging/lg2.hpp>
7#include <sdbusplus/async.hpp>
8#include <sdbusplus/message/native_types.hpp>
9#include <xyz/openbmc_project/State/Leak/Detector/event.hpp>
10
11#include <tuple>
12
13PHOSPHOR_LOG2_USING;
14
15namespace leak
16{
17
18auto Events::generateLeakEvent(sdbusplus::message::object_path detectorPath,
19 DetectorStateIntf::DetectorState state,
20 config::DetectorLevel level)
21 -> sdbusplus::async::task<>
22{
23 auto eventName = std::make_tuple(detectorPath.str, level);
24
25 // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.Branch)
26 if (state == DetectorStateIntf::DetectorState::Normal)
27 {
28 auto pendingEvent = pendingEvents.find(eventName);
29 if (pendingEvent != pendingEvents.end())
30 {
31 co_await lg2::resolve(ctx, pendingEvent->second);
32
33 using DetectorNormal = sdbusplus::event::xyz::openbmc_project::
34 state::leak::Detector::LeakDetectedNormal;
35 co_await lg2::commit(ctx,
36 DetectorNormal("DETECTOR_NAME", detectorPath));
37
38 pendingEvents.erase(eventName);
39 }
40 co_return;
41 }
42
43 namespace error_intf =
44 sdbusplus::error::xyz::openbmc_project::state::leak::Detector;
45 sdbusplus::message::object_path eventPath{};
46
47 if (level == config::DetectorLevel::critical)
48 {
49 eventPath = co_await lg2::commit(
50 ctx,
51 error_intf::LeakDetectedCritical("DETECTOR_NAME", detectorPath));
52 error("Critical leak detected for {PATH}", "PATH", detectorPath);
53 }
54 else
55 {
56 eventPath = co_await lg2::commit(
57 ctx,
58 error_intf::LeakDetectedWarning("DETECTOR_NAME", detectorPath));
59 warning("Warning leak detected for {PATH}", "PATH", detectorPath);
60 }
61 pendingEvents[eventName] = eventPath;
62}
63
64} // namespace leak