xref: /openbmc/telemetry/tests/src/params/trigger_params.hpp (revision 2efa95d8faec80ee1eb2ce500e2cb08849cd478e)
1 #pragma once
2 
3 #include "report.hpp"
4 #include "types/duration_types.hpp"
5 #include "types/trigger_types.hpp"
6 #include "utils/dbus_path_utils.hpp"
7 #include "utils/transform.hpp"
8 
9 #include <sdbusplus/message.hpp>
10 
11 #include <chrono>
12 #include <utility>
13 
14 using sdbusplus::message::object_path;
15 
16 class TriggerParams
17 {
18   public:
TriggerParams()19     TriggerParams()
20     {
21         reportsProperty = utils::transform(reportIdsProperty,
22                                            [](const auto& id) {
23             return utils::pathAppend(utils::constants::reportDirPath, id);
24         });
25     }
26 
id(std::string_view val)27     TriggerParams& id(std::string_view val)
28     {
29         idProperty = val;
30         return *this;
31     }
32 
id() const33     const std::string& id() const
34     {
35         return idProperty;
36     }
37 
name(std::string_view val)38     TriggerParams& name(std::string_view val)
39     {
40         nameProperty = val;
41         return *this;
42     }
43 
name() const44     const std::string& name() const
45     {
46         return nameProperty;
47     }
48 
triggerActions(const std::vector<TriggerAction> & val)49     TriggerParams& triggerActions(const std::vector<TriggerAction>& val)
50     {
51         triggerActionsProperty = val;
52         return *this;
53     }
54 
triggerActions() const55     const std::vector<TriggerAction>& triggerActions() const
56     {
57         return triggerActionsProperty;
58     }
59 
sensors() const60     const std::vector<LabeledSensorInfo>& sensors() const
61     {
62         return labeledSensorsProperty;
63     }
64 
reportIds() const65     const std::vector<std::string>& reportIds() const
66     {
67         return reportIdsProperty;
68     }
69 
reportIds(std::vector<std::string> val)70     TriggerParams& reportIds(std::vector<std::string> val)
71     {
72         reportIdsProperty = std::move(val);
73         reportsProperty = utils::transform<std::vector>(reportIdsProperty,
74                                                         [](const auto& id) {
75             return utils::pathAppend(utils::constants::reportDirPath, id);
76         });
77         return *this;
78     }
79 
reports() const80     const std::vector<object_path>& reports() const
81     {
82         return reportsProperty;
83     }
84 
reports(std::vector<object_path> val)85     TriggerParams& reports(std::vector<object_path> val)
86     {
87         reportsProperty = std::move(val);
88         return *this;
89     }
90 
thresholdParams(LabeledTriggerThresholdParams val)91     TriggerParams& thresholdParams(LabeledTriggerThresholdParams val)
92     {
93         labeledThresholdsProperty = std::move(val);
94         return *this;
95     }
96 
thresholdParams() const97     const LabeledTriggerThresholdParams& thresholdParams() const
98     {
99         return labeledThresholdsProperty;
100     }
101 
102     const std::vector<numeric::LabeledThresholdParam>
numericThresholdParams() const103         numericThresholdParams() const
104     {
105         const auto* num = std::get_if<0>(&labeledThresholdsProperty);
106         if (num == nullptr)
107         {
108             return {};
109         }
110         return *num;
111     }
112 
113     const std::vector<discrete::LabeledThresholdParam>
discreteThresholdParams() const114         discreteThresholdParams() const
115     {
116         const auto* num = std::get_if<1>(&labeledThresholdsProperty);
117         if (num == nullptr)
118         {
119             return {};
120         }
121         return *num;
122     }
123 
124   private:
125     std::string idProperty = "Trigger1";
126     std::string nameProperty = "My Numeric Trigger";
127     std::vector<TriggerAction> triggerActionsProperty = {
128         TriggerAction::UpdateReport};
129     std::vector<LabeledSensorInfo> labeledSensorsProperty = {
130         {"service1", "/xyz/openbmc_project/sensors/temperature/BMC_Temp",
131          "metadata1"}};
132     std::vector<std::string> reportIdsProperty = {"Report1",
133                                                   "Prefixed/Report2"};
134     std::vector<object_path> reportsProperty;
135     LabeledTriggerThresholdParams labeledThresholdsProperty =
136         std::vector<numeric::LabeledThresholdParam>{
137             numeric::LabeledThresholdParam{numeric::Type::lowerCritical,
138                                            Milliseconds(10).count(),
139                                            numeric::Direction::decreasing, 0.5},
140             numeric::LabeledThresholdParam{
141                 numeric::Type::upperCritical, Milliseconds(10).count(),
142                 numeric::Direction::increasing, 90.2}};
143 };
144