blob: 3e2c33c89b72acd3ba5fc729c8883f4d7b773e0f [file] [log] [blame]
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01001#pragma once
2
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01003#include "interfaces/trigger_action.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00004#include "types/trigger_types.hpp"
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01005
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +01006#include <boost/asio/io_context.hpp>
7
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01008namespace action
9{
10
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020011namespace redfish_message_ids
12{
Michal Orzel8018a3b2024-06-26 14:14:16 +020013constexpr const char* TriggerDiscreteConditionMet =
14 "Telemetry.1.0.TriggerDiscreteConditionMet";
15constexpr const char* TriggerNumericAboveLowerCritical =
16 "Telemetry.1.0.TriggerNumericAboveLowerCritical";
17constexpr const char* TriggerNumericAboveUpperCritical =
18 "Telemetry.1.0.TriggerNumericAboveUpperCritical";
19constexpr const char* TriggerNumericAboveUpperWarning =
20 "Telemetry.1.0.TriggerNumericAboveUpperWarning";
21constexpr const char* TriggerNumericBelowLowerCritical =
22 "Telemetry.1.0.TriggerNumericBelowLowerCritical";
23constexpr const char* TriggerNumericBelowLowerWarning =
24 "Telemetry.1.0.TriggerNumericBelowLowerWarning";
25constexpr const char* TriggerNumericBelowUpperCritical =
26 "Telemetry.1.0.TriggerNumericBelowUpperCritical";
27constexpr const char* TriggerNumericReadingNormal =
28 "Telemetry.1.0.TriggerNumericReadingNormal";
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020029} // namespace redfish_message_ids
30
Szymon Dompkef763c9e2021-03-12 09:19:22 +010031namespace numeric
32{
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010033class LogToJournal : public interfaces::TriggerAction
34{
35 public:
Szymon Dompkef763c9e2021-03-12 09:19:22 +010036 LogToJournal(::numeric::Type type, double val) : type(type), threshold(val)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010037 {}
38
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020039 void commit(const std::string& triggerId, const ThresholdName thresholdName,
40 const std::string& sensorName, const Milliseconds timestamp,
41 const TriggerValue value) override;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010042
43 private:
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020044 const ::numeric::Type type;
45 const double threshold;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010046};
47
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020048class LogToRedfishEventLog : public interfaces::TriggerAction
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010049{
50 public:
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020051 LogToRedfishEventLog(::numeric::Type type, double val) :
52 type(type), threshold(val)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010053 {}
54
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020055 void commit(const std::string& triggerId, const ThresholdName thresholdName,
56 const std::string& sensorName, const Milliseconds timestamp,
57 const TriggerValue value) override;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010058
59 private:
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020060 const ::numeric::Type type;
61 const double threshold;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010062
Michal Orzel8018a3b2024-06-26 14:14:16 +020063 const char* getRedfishMessageId(const double value) const;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010064};
Szymon Dompke20013012021-07-23 09:54:20 +020065
66void fillActions(
67 std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf,
68 const std::vector<TriggerAction>& ActionsEnum, ::numeric::Type type,
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010069 double thresholdValue, boost::asio::io_context& ioc,
Szymon Dompke94f71c52021-12-10 07:16:33 +010070 const std::shared_ptr<std::vector<std::string>>& reportIds);
Szymon Dompkef763c9e2021-03-12 09:19:22 +010071} // namespace numeric
72
73namespace discrete
74{
75class LogToJournal : public interfaces::TriggerAction
76{
77 public:
Patrick Williams3a1c2972023-05-10 07:51:04 -050078 explicit LogToJournal(::discrete::Severity severity) : severity(severity) {}
Szymon Dompkef763c9e2021-03-12 09:19:22 +010079
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020080 void commit(const std::string& triggerId, const ThresholdName thresholdName,
81 const std::string& sensorName, const Milliseconds timestamp,
82 const TriggerValue value) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010083
84 private:
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020085 const ::discrete::Severity severity;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010086};
87
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020088class LogToRedfishEventLog : public interfaces::TriggerAction
Szymon Dompkef763c9e2021-03-12 09:19:22 +010089{
90 public:
Michal Orzel8018a3b2024-06-26 14:14:16 +020091 explicit LogToRedfishEventLog() {}
Szymon Dompkef763c9e2021-03-12 09:19:22 +010092
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020093 void commit(const std::string& triggerId, const ThresholdName thresholdName,
94 const std::string& sensorName, const Milliseconds timestamp,
95 const TriggerValue value) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010096};
97
Szymon Dompke20013012021-07-23 09:54:20 +020098void fillActions(
99 std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf,
100 const std::vector<TriggerAction>& ActionsEnum,
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100101 ::discrete::Severity severity, boost::asio::io_context& ioc,
Szymon Dompke94f71c52021-12-10 07:16:33 +0100102 const std::shared_ptr<std::vector<std::string>>& reportIds);
Szymon Dompke20013012021-07-23 09:54:20 +0200103
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100104namespace onChange
105{
106class LogToJournal : public interfaces::TriggerAction
107{
108 public:
Patrick Williams3a1c2972023-05-10 07:51:04 -0500109 LogToJournal() {}
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100110
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +0200111 void commit(const std::string& triggerId, const ThresholdName thresholdName,
112 const std::string& sensorName, const Milliseconds timestamp,
113 const TriggerValue value) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100114};
115
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +0200116class LogToRedfishEventLog : public interfaces::TriggerAction
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100117{
118 public:
Patrick Williams3a1c2972023-05-10 07:51:04 -0500119 LogToRedfishEventLog() {}
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100120
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +0200121 void commit(const std::string& triggerId, const ThresholdName thresholdName,
122 const std::string& sensorName, const Milliseconds timestamp,
123 const TriggerValue value) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100124};
Szymon Dompke20013012021-07-23 09:54:20 +0200125
126void fillActions(
127 std::vector<std::unique_ptr<interfaces::TriggerAction>>& actionsIf,
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100128 const std::vector<TriggerAction>& ActionsEnum, boost::asio::io_context& ioc,
Szymon Dompke94f71c52021-12-10 07:16:33 +0100129 const std::shared_ptr<std::vector<std::string>>& reportIds);
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100130} // namespace onChange
131
132} // namespace discrete
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100133
134class UpdateReport : public interfaces::TriggerAction
135{
136 public:
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100137 UpdateReport(boost::asio::io_context& ioc,
Szymon Dompke94f71c52021-12-10 07:16:33 +0100138 std::shared_ptr<std::vector<std::string>> ids) :
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100139 ioc(ioc),
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100140 reportIds(std::move(ids))
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100141 {}
142
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +0200143 void commit(const std::string& triggerId, const ThresholdName thresholdName,
144 const std::string& sensorName, const Milliseconds timestamp,
145 const TriggerValue value) override;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100146
147 private:
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100148 boost::asio::io_context& ioc;
Szymon Dompke94f71c52021-12-10 07:16:33 +0100149 std::shared_ptr<std::vector<std::string>> reportIds;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100150};
151} // namespace action