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 | { |
Michal Orzel | 8018a3b | 2024-06-26 14:14:16 +0200 | [diff] [blame] | 13 | constexpr const char* TriggerDiscreteConditionMet = |
| 14 | "Telemetry.1.0.TriggerDiscreteConditionMet"; |
| 15 | constexpr const char* TriggerNumericAboveLowerCritical = |
| 16 | "Telemetry.1.0.TriggerNumericAboveLowerCritical"; |
| 17 | constexpr const char* TriggerNumericAboveUpperCritical = |
| 18 | "Telemetry.1.0.TriggerNumericAboveUpperCritical"; |
| 19 | constexpr const char* TriggerNumericAboveUpperWarning = |
| 20 | "Telemetry.1.0.TriggerNumericAboveUpperWarning"; |
| 21 | constexpr const char* TriggerNumericBelowLowerCritical = |
| 22 | "Telemetry.1.0.TriggerNumericBelowLowerCritical"; |
| 23 | constexpr const char* TriggerNumericBelowLowerWarning = |
| 24 | "Telemetry.1.0.TriggerNumericBelowLowerWarning"; |
| 25 | constexpr const char* TriggerNumericBelowUpperCritical = |
| 26 | "Telemetry.1.0.TriggerNumericBelowUpperCritical"; |
| 27 | constexpr const char* TriggerNumericReadingNormal = |
| 28 | "Telemetry.1.0.TriggerNumericReadingNormal"; |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 29 | } // namespace redfish_message_ids |
| 30 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 31 | namespace numeric |
| 32 | { |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 33 | class LogToJournal : public interfaces::TriggerAction |
| 34 | { |
| 35 | public: |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 36 | LogToJournal(::numeric::Type type, double val) : type(type), threshold(val) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 37 | {} |
| 38 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 39 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 40 | const std::string& sensorName, const Milliseconds timestamp, |
| 41 | const TriggerValue value) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 42 | |
| 43 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 44 | const ::numeric::Type type; |
| 45 | const double threshold; |
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 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 49 | { |
| 50 | public: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 51 | LogToRedfishEventLog(::numeric::Type type, double val) : |
| 52 | type(type), threshold(val) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 53 | {} |
| 54 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 55 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 56 | const std::string& sensorName, const Milliseconds timestamp, |
| 57 | const TriggerValue value) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 58 | |
| 59 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 60 | const ::numeric::Type type; |
| 61 | const double threshold; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 62 | |
Michal Orzel | 8018a3b | 2024-06-26 14:14:16 +0200 | [diff] [blame] | 63 | const char* getRedfishMessageId(const double value) const; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 64 | }; |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 65 | |
| 66 | void fillActions( |
| 67 | std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, |
| 68 | const std::vector<TriggerAction>& ActionsEnum, ::numeric::Type type, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 69 | double thresholdValue, boost::asio::io_context& ioc, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 70 | const std::shared_ptr<std::vector<std::string>>& reportIds); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 71 | } // namespace numeric |
| 72 | |
| 73 | namespace discrete |
| 74 | { |
| 75 | class LogToJournal : public interfaces::TriggerAction |
| 76 | { |
| 77 | public: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 78 | explicit LogToJournal(::discrete::Severity severity) : severity(severity) {} |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 79 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 80 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 81 | const std::string& sensorName, const Milliseconds timestamp, |
| 82 | const TriggerValue value) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 83 | |
| 84 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 85 | const ::discrete::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 | class LogToRedfishEventLog : public interfaces::TriggerAction |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 89 | { |
| 90 | public: |
Michal Orzel | 8018a3b | 2024-06-26 14:14:16 +0200 | [diff] [blame] | 91 | explicit LogToRedfishEventLog() {} |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 92 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 93 | void commit(const std::string& triggerId, const ThresholdName thresholdName, |
| 94 | const std::string& sensorName, const Milliseconds timestamp, |
| 95 | const TriggerValue value) override; |
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 |