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: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame^] | 71 | explicit LogToJournal(::discrete::Severity severity) : severity(severity) {} |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 72 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 73 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 74 | const std::string& sensorName, const Milliseconds timestamp, |
| 75 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 76 | |
| 77 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 78 | const ::discrete::Severity severity; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 81 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 82 | { |
| 83 | public: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 84 | explicit LogToRedfishEventLog(::discrete::Severity severity) : |
| 85 | severity(severity) |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 86 | {} |
| 87 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 88 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 89 | const std::string& sensorName, const Milliseconds timestamp, |
| 90 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 91 | |
| 92 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 93 | const ::discrete::Severity severity; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 94 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 95 | const char* getRedfishMessageId() const; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 98 | void fillActions( |
| 99 | std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, |
| 100 | const std::vector<TriggerAction>& ActionsEnum, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 101 | ::discrete::Severity severity, boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 102 | const std::shared_ptr<std::vector<std::string>>& reportIds); |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 103 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 104 | namespace onChange |
| 105 | { |
| 106 | class LogToJournal : public interfaces::TriggerAction |
| 107 | { |
| 108 | public: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame^] | 109 | LogToJournal() {} |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 110 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 111 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 112 | const std::string& sensorName, const Milliseconds timestamp, |
| 113 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 116 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 117 | { |
| 118 | public: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame^] | 119 | LogToRedfishEventLog() {} |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 120 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 121 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 122 | const std::string& sensorName, const Milliseconds timestamp, |
| 123 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 124 | }; |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 125 | |
| 126 | void fillActions( |
| 127 | std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 128 | const std::vector<TriggerAction>& ActionsEnum, boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 129 | const std::shared_ptr<std::vector<std::string>>& reportIds); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 130 | } // namespace onChange |
| 131 | |
| 132 | } // namespace discrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 133 | |
| 134 | class UpdateReport : public interfaces::TriggerAction |
| 135 | { |
| 136 | public: |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 137 | UpdateReport(boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 138 | std::shared_ptr<std::vector<std::string>> ids) : |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 139 | ioc(ioc), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 140 | reportIds(std::move(ids)) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 141 | {} |
| 142 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 143 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 144 | const std::string& sensorName, const Milliseconds timestamp, |
| 145 | const TriggerValue value) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 146 | |
| 147 | private: |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 148 | boost::asio::io_context& ioc; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 149 | std::shared_ptr<std::vector<std::string>> reportIds; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 150 | }; |
| 151 | } // namespace action |