xref: /openbmc/telemetry/src/trigger_actions.hpp (revision e6d48874)
1 #pragma once
2 
3 #include "interfaces/trigger_action.hpp"
4 #include "types/trigger_types.hpp"
5 
6 #include <boost/asio/io_context.hpp>
7 
8 namespace action
9 {
10 
11 namespace numeric
12 {
13 class LogToJournal : public interfaces::TriggerAction
14 {
15   public:
16     LogToJournal(::numeric::Type type, double val) : type(type), threshold(val)
17     {}
18 
19     void commit(const std::string& id, Milliseconds timestamp,
20                 double value) override;
21 
22   private:
23     ::numeric::Type type;
24     double threshold;
25 
26     const char* getType() const;
27 };
28 
29 class LogToRedfish : public interfaces::TriggerAction
30 {
31   public:
32     LogToRedfish(::numeric::Type type, double val) : type(type), threshold(val)
33     {}
34 
35     void commit(const std::string& id, Milliseconds timestamp,
36                 double value) override;
37 
38   private:
39     ::numeric::Type type;
40     double threshold;
41 
42     const char* getMessageId() const;
43 };
44 
45 void fillActions(
46     std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf,
47     const std::vector<TriggerAction>& ActionsEnum, ::numeric::Type type,
48     double thresholdValue, boost::asio::io_context& ioc,
49     const std::shared_ptr<std::vector<std::string>>& reportIds);
50 } // namespace numeric
51 
52 namespace discrete
53 {
54 class LogToJournal : public interfaces::TriggerAction
55 {
56   public:
57     explicit LogToJournal(::discrete::Severity severity) : severity(severity)
58     {}
59 
60     void commit(const std::string& id, Milliseconds timestamp,
61                 double value) override;
62 
63   private:
64     ::discrete::Severity severity;
65 
66     const char* getSeverity() const;
67 };
68 
69 class LogToRedfish : public interfaces::TriggerAction
70 {
71   public:
72     explicit LogToRedfish(::discrete::Severity severity) : severity(severity)
73     {}
74 
75     void commit(const std::string& id, Milliseconds timestamp,
76                 double value) override;
77 
78   private:
79     ::discrete::Severity severity;
80 
81     const char* getMessageId() const;
82 };
83 
84 void fillActions(
85     std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf,
86     const std::vector<TriggerAction>& ActionsEnum,
87     ::discrete::Severity severity, boost::asio::io_context& ioc,
88     const std::shared_ptr<std::vector<std::string>>& reportIds);
89 
90 namespace onChange
91 {
92 class LogToJournal : public interfaces::TriggerAction
93 {
94   public:
95     LogToJournal()
96     {}
97 
98     void commit(const std::string& id, Milliseconds timestamp,
99                 double value) override;
100 };
101 
102 class LogToRedfish : public interfaces::TriggerAction
103 {
104   public:
105     LogToRedfish()
106     {}
107 
108     void commit(const std::string& id, Milliseconds timestamp,
109                 double value) override;
110 };
111 
112 void fillActions(
113     std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf,
114     const std::vector<TriggerAction>& ActionsEnum, boost::asio::io_context& ioc,
115     const std::shared_ptr<std::vector<std::string>>& reportIds);
116 } // namespace onChange
117 
118 } // namespace discrete
119 
120 class UpdateReport : public interfaces::TriggerAction
121 {
122   public:
123     UpdateReport(boost::asio::io_context& ioc,
124                  std::shared_ptr<std::vector<std::string>> ids) :
125         ioc(ioc),
126         reportIds(std::move(ids))
127     {}
128 
129     void commit(const std::string& id, Milliseconds timestamp,
130                 double value) override;
131 
132   private:
133     boost::asio::io_context& ioc;
134     std::shared_ptr<std::vector<std::string>> reportIds;
135 };
136 } // namespace action
137