Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 3 | #include "interfaces/trigger_action.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 4 | #include "types/trigger_types.hpp" |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 5 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 6 | #include <boost/asio/io_context.hpp> |
| 7 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 8 | namespace action |
| 9 | { |
| 10 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 11 | namespace redfish_message_ids |
| 12 | { |
| 13 | constexpr const char* TriggerNumericWarning = |
| 14 | "OpenBMC.0.1.TriggerNumericWarning"; |
| 15 | constexpr const char* TriggerNumericCritical = |
| 16 | "OpenBMC.0.1.TriggerNumericCritical"; |
| 17 | constexpr const char* TriggerDiscreteOK = "OpenBMC.0.1.TriggerDiscreteOK"; |
| 18 | constexpr const char* TriggerDiscreteWarning = |
| 19 | "OpenBMC.0.1.TriggerDiscreteWarning"; |
| 20 | constexpr const char* TriggerDiscreteCritical = |
| 21 | "OpenBMC.0.1.TriggerDiscreteCritical"; |
| 22 | } // namespace redfish_message_ids |
| 23 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 24 | namespace numeric |
| 25 | { |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 26 | class LogToJournal : public interfaces::TriggerAction |
| 27 | { |
| 28 | public: |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 29 | LogToJournal(::numeric::Type type, double val) : type(type), threshold(val) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 30 | {} |
| 31 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 32 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 33 | const std::string& sensorName, const Milliseconds timestamp, |
| 34 | const TriggerValue value) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 35 | |
| 36 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 37 | const ::numeric::Type type; |
| 38 | const double threshold; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 41 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 42 | { |
| 43 | public: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 44 | LogToRedfishEventLog(::numeric::Type type, double val) : |
| 45 | type(type), threshold(val) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 46 | {} |
| 47 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 48 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 49 | const std::string& sensorName, const Milliseconds timestamp, |
| 50 | const TriggerValue value) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 51 | |
| 52 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 53 | const ::numeric::Type type; |
| 54 | const double threshold; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 55 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 56 | const char* getRedfishMessageId() const; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 57 | }; |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 58 | |
| 59 | void fillActions( |
| 60 | std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, |
| 61 | const std::vector<TriggerAction>& ActionsEnum, ::numeric::Type type, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 62 | double thresholdValue, boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 63 | const std::shared_ptr<std::vector<std::string>>& reportIds); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 64 | } // namespace numeric |
| 65 | |
| 66 | namespace discrete |
| 67 | { |
| 68 | class LogToJournal : public interfaces::TriggerAction |
| 69 | { |
| 70 | public: |
Krzysztof Grobelny | fbeb5bf | 2022-01-03 09:41:29 +0100 | [diff] [blame] | 71 | explicit LogToJournal(::discrete::Severity severity) : severity(severity) |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 72 | {} |
| 73 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 74 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 75 | const std::string& sensorName, const Milliseconds timestamp, |
| 76 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 77 | |
| 78 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 79 | const ::discrete::Severity severity; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 80 | }; |
| 81 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 82 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 83 | { |
| 84 | public: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 85 | explicit LogToRedfishEventLog(::discrete::Severity severity) : |
| 86 | severity(severity) |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 87 | {} |
| 88 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 89 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 90 | const std::string& sensorName, const Milliseconds timestamp, |
| 91 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 92 | |
| 93 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 94 | const ::discrete::Severity severity; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 95 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 96 | const char* getRedfishMessageId() const; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 99 | void fillActions( |
| 100 | std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, |
| 101 | const std::vector<TriggerAction>& ActionsEnum, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 102 | ::discrete::Severity severity, boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 103 | const std::shared_ptr<std::vector<std::string>>& reportIds); |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 104 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 105 | namespace onChange |
| 106 | { |
| 107 | class LogToJournal : public interfaces::TriggerAction |
| 108 | { |
| 109 | public: |
| 110 | LogToJournal() |
| 111 | {} |
| 112 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 113 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 114 | const std::string& sensorName, const Milliseconds timestamp, |
| 115 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 118 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 119 | { |
| 120 | public: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 121 | LogToRedfishEventLog() |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 122 | {} |
| 123 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 124 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 125 | const std::string& sensorName, const Milliseconds timestamp, |
| 126 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 127 | }; |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 128 | |
| 129 | void fillActions( |
| 130 | std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 131 | const std::vector<TriggerAction>& ActionsEnum, boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 132 | const std::shared_ptr<std::vector<std::string>>& reportIds); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 133 | } // namespace onChange |
| 134 | |
| 135 | } // namespace discrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 136 | |
| 137 | class UpdateReport : public interfaces::TriggerAction |
| 138 | { |
| 139 | public: |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 140 | UpdateReport(boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 141 | std::shared_ptr<std::vector<std::string>> ids) : |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 142 | ioc(ioc), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 143 | reportIds(std::move(ids)) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 144 | {} |
| 145 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 146 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 147 | const std::string& sensorName, const Milliseconds timestamp, |
| 148 | const TriggerValue value) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 149 | |
| 150 | private: |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 151 | boost::asio::io_context& ioc; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 152 | std::shared_ptr<std::vector<std::string>> reportIds; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 153 | }; |
| 154 | } // namespace action |