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 redfish_message_ids 12 { 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"; 29 } // namespace redfish_message_ids 30 31 namespace numeric 32 { 33 class LogToJournal : public interfaces::TriggerAction 34 { 35 public: LogToJournal(::numeric::Type type,double val)36 LogToJournal(::numeric::Type type, double val) : type(type), threshold(val) 37 {} 38 39 void commit(const std::string& triggerId, const ThresholdName thresholdName, 40 const std::string& sensorName, const Milliseconds timestamp, 41 const TriggerValue value) override; 42 43 private: 44 const ::numeric::Type type; 45 const double threshold; 46 }; 47 48 class LogToRedfishEventLog : public interfaces::TriggerAction 49 { 50 public: LogToRedfishEventLog(::numeric::Type type,double val)51 LogToRedfishEventLog(::numeric::Type type, double val) : 52 type(type), threshold(val) 53 {} 54 55 void commit(const std::string& triggerId, const ThresholdName thresholdName, 56 const std::string& sensorName, const Milliseconds timestamp, 57 const TriggerValue value) override; 58 59 private: 60 const ::numeric::Type type; 61 const double threshold; 62 63 const char* getRedfishMessageId(const double value) const; 64 }; 65 66 void fillActions( 67 std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, 68 const std::vector<TriggerAction>& ActionsEnum, ::numeric::Type type, 69 double thresholdValue, boost::asio::io_context& ioc, 70 const std::shared_ptr<std::vector<std::string>>& reportIds); 71 } // namespace numeric 72 73 namespace discrete 74 { 75 class LogToJournal : public interfaces::TriggerAction 76 { 77 public: LogToJournal(::discrete::Severity severity)78 explicit LogToJournal(::discrete::Severity severity) : severity(severity) {} 79 80 void commit(const std::string& triggerId, const ThresholdName thresholdName, 81 const std::string& sensorName, const Milliseconds timestamp, 82 const TriggerValue value) override; 83 84 private: 85 const ::discrete::Severity severity; 86 }; 87 88 class LogToRedfishEventLog : public interfaces::TriggerAction 89 { 90 public: LogToRedfishEventLog()91 explicit LogToRedfishEventLog() {} 92 93 void commit(const std::string& triggerId, const ThresholdName thresholdName, 94 const std::string& sensorName, const Milliseconds timestamp, 95 const TriggerValue value) override; 96 }; 97 98 void fillActions( 99 std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, 100 const std::vector<TriggerAction>& ActionsEnum, 101 ::discrete::Severity severity, boost::asio::io_context& ioc, 102 const std::shared_ptr<std::vector<std::string>>& reportIds); 103 104 namespace onChange 105 { 106 class LogToJournal : public interfaces::TriggerAction 107 { 108 public: LogToJournal()109 LogToJournal() {} 110 111 void commit(const std::string& triggerId, const ThresholdName thresholdName, 112 const std::string& sensorName, const Milliseconds timestamp, 113 const TriggerValue value) override; 114 }; 115 116 class LogToRedfishEventLog : public interfaces::TriggerAction 117 { 118 public: LogToRedfishEventLog()119 LogToRedfishEventLog() {} 120 121 void commit(const std::string& triggerId, const ThresholdName thresholdName, 122 const std::string& sensorName, const Milliseconds timestamp, 123 const TriggerValue value) override; 124 }; 125 126 void fillActions( 127 std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf, 128 const std::vector<TriggerAction>& ActionsEnum, boost::asio::io_context& ioc, 129 const std::shared_ptr<std::vector<std::string>>& reportIds); 130 } // namespace onChange 131 132 } // namespace discrete 133 134 class UpdateReport : public interfaces::TriggerAction 135 { 136 public: UpdateReport(boost::asio::io_context & ioc,std::shared_ptr<std::vector<std::string>> ids)137 UpdateReport(boost::asio::io_context& ioc, 138 std::shared_ptr<std::vector<std::string>> ids) : 139 ioc(ioc), reportIds(std::move(ids)) 140 {} 141 142 void commit(const std::string& triggerId, const ThresholdName thresholdName, 143 const std::string& sensorName, const Milliseconds timestamp, 144 const TriggerValue value) override; 145 146 private: 147 boost::asio::io_context& ioc; 148 std::shared_ptr<std::vector<std::string>> reportIds; 149 }; 150 } // namespace action 151