trigger_actions.cpp (d960e1f37e72115fdd8ec0163c99bb19e0487b91) | trigger_actions.cpp (f763c9e3bbe0f86a4a41e7bb0dc70bffde0af9b2) |
---|---|
1#include "trigger_actions.hpp" 2 3#include <phosphor-logging/log.hpp> 4 5#include <ctime> 6 7namespace action 8{ 9 | 1#include "trigger_actions.hpp" 2 3#include <phosphor-logging/log.hpp> 4 5#include <ctime> 6 7namespace action 8{ 9 |
10namespace 11{ 12std::string timestampToString(uint64_t timestamp) 13{ 14 std::time_t t = static_cast<time_t>(timestamp); 15 std::array<char, sizeof("YYYY-MM-DDThh:mm:ssZ")> buf = {}; 16 size_t size = 17 std::strftime(buf.data(), buf.size(), "%FT%TZ", std::gmtime(&t)); 18 if (size == 0) 19 { 20 throw std::runtime_error("Failed to parse timestamp to string"); 21 } 22 return std::string(buf.data(), size); 23} 24} // namespace 25 26namespace numeric 27{ 28 |
|
10static const char* getDirection(double value, double threshold) 11{ 12 if (value < threshold) 13 { 14 return "decreasing"; 15 } 16 if (value > threshold) 17 { 18 return "increasing"; 19 } 20 throw std::runtime_error("Invalid value"); 21} 22 23const char* LogToJournal::getType() const 24{ 25 switch (type) 26 { | 29static const char* getDirection(double value, double threshold) 30{ 31 if (value < threshold) 32 { 33 return "decreasing"; 34 } 35 if (value > threshold) 36 { 37 return "increasing"; 38 } 39 throw std::runtime_error("Invalid value"); 40} 41 42const char* LogToJournal::getType() const 43{ 44 switch (type) 45 { |
27 case numeric::Type::upperCritical: | 46 case ::numeric::Type::upperCritical: |
28 return "UpperCritical"; | 47 return "UpperCritical"; |
29 case numeric::Type::lowerCritical: | 48 case ::numeric::Type::lowerCritical: |
30 return "LowerCritical"; | 49 return "LowerCritical"; |
31 case numeric::Type::upperWarning: | 50 case ::numeric::Type::upperWarning: |
32 return "UpperWarning"; | 51 return "UpperWarning"; |
33 case numeric::Type::lowerWarning: | 52 case ::numeric::Type::lowerWarning: |
34 return "LowerWarning"; 35 } 36 throw std::runtime_error("Invalid type"); 37} 38 39void LogToJournal::commit(const std::string& sensorName, uint64_t timestamp, 40 double value) 41{ | 53 return "LowerWarning"; 54 } 55 throw std::runtime_error("Invalid type"); 56} 57 58void LogToJournal::commit(const std::string& sensorName, uint64_t timestamp, 59 double value) 60{ |
42 std::time_t t = static_cast<time_t>(timestamp); 43 std::array<char, sizeof("YYYY-MM-DDThh:mm:ssZ")> buf = {}; 44 size_t size = 45 std::strftime(buf.data(), buf.size(), "%FT%TZ", std::gmtime(&t)); 46 if (size == 0) 47 { 48 throw std::runtime_error("Failed to parse timestamp to string"); 49 } 50 | |
51 std::string msg = std::string(getType()) + 52 " numeric threshold condition is met on sensor " + 53 sensorName + ", recorded value " + std::to_string(value) + | 61 std::string msg = std::string(getType()) + 62 " numeric threshold condition is met on sensor " + 63 sensorName + ", recorded value " + std::to_string(value) + |
54 ", timestamp " + std::string(buf.data(), size) + | 64 ", timestamp " + timestampToString(timestamp) + |
55 ", direction " + 56 std::string(getDirection(value, threshold)); 57 58 phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str()); 59} 60 61const char* LogToRedfish::getMessageId() const 62{ 63 switch (type) 64 { | 65 ", direction " + 66 std::string(getDirection(value, threshold)); 67 68 phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str()); 69} 70 71const char* LogToRedfish::getMessageId() const 72{ 73 switch (type) 74 { |
65 case numeric::Type::upperCritical: | 75 case ::numeric::Type::upperCritical: |
66 return "OpenBMC.0.1.0.NumericThresholdUpperCritical"; | 76 return "OpenBMC.0.1.0.NumericThresholdUpperCritical"; |
67 case numeric::Type::lowerCritical: | 77 case ::numeric::Type::lowerCritical: |
68 return "OpenBMC.0.1.0.NumericThresholdLowerCritical"; | 78 return "OpenBMC.0.1.0.NumericThresholdLowerCritical"; |
69 case numeric::Type::upperWarning: | 79 case ::numeric::Type::upperWarning: |
70 return "OpenBMC.0.1.0.NumericThresholdUpperWarning"; | 80 return "OpenBMC.0.1.0.NumericThresholdUpperWarning"; |
71 case numeric::Type::lowerWarning: | 81 case ::numeric::Type::lowerWarning: |
72 return "OpenBMC.0.1.0.NumericThresholdLowerWarning"; 73 } 74 throw std::runtime_error("Invalid type"); 75} 76 77void LogToRedfish::commit(const std::string& sensorName, uint64_t timestamp, 78 double value) 79{ 80 phosphor::logging::log<phosphor::logging::level::INFO>( 81 "Threshold value is exceeded", 82 phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", getMessageId()), 83 phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%f,%llu,%s", 84 sensorName.c_str(), value, timestamp, 85 getDirection(value, threshold))); 86} 87 | 82 return "OpenBMC.0.1.0.NumericThresholdLowerWarning"; 83 } 84 throw std::runtime_error("Invalid type"); 85} 86 87void LogToRedfish::commit(const std::string& sensorName, uint64_t timestamp, 88 double value) 89{ 90 phosphor::logging::log<phosphor::logging::level::INFO>( 91 "Threshold value is exceeded", 92 phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", getMessageId()), 93 phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%f,%llu,%s", 94 sensorName.c_str(), value, timestamp, 95 getDirection(value, threshold))); 96} 97 |
98} // namespace numeric 99 100namespace discrete 101{ 102const char* LogToJournal::getSeverity() const 103{ 104 switch (severity) 105 { 106 case ::discrete::Severity::ok: 107 return "OK"; 108 case ::discrete::Severity::warning: 109 return "Warning"; 110 case ::discrete::Severity::critical: 111 return "Critical"; 112 } 113 throw std::runtime_error("Invalid severity"); 114} 115 116void LogToJournal::commit(const std::string& sensorName, uint64_t timestamp, 117 double value) 118{ 119 std::string msg = std::string(getSeverity()) + 120 " discrete threshold condition is met on sensor " + 121 sensorName + ", recorded value " + std::to_string(value) + 122 ", timestamp " + timestampToString(timestamp); 123 124 phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str()); 125} 126 127const char* LogToRedfish::getMessageId() const 128{ 129 switch (severity) 130 { 131 case ::discrete::Severity::ok: 132 return "OpenBMC.0.1.0.DiscreteThresholdOk"; 133 case ::discrete::Severity::warning: 134 return "OpenBMC.0.1.0.DiscreteThresholdWarning"; 135 case ::discrete::Severity::critical: 136 return "OpenBMC.0.1.0.DiscreteThresholdCritical"; 137 } 138 throw std::runtime_error("Invalid severity"); 139} 140 141void LogToRedfish::commit(const std::string& sensorName, uint64_t timestamp, 142 double value) 143{ 144 phosphor::logging::log<phosphor::logging::level::INFO>( 145 "Discrete treshold condition is met", 146 phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", getMessageId()), 147 phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%f,%llu", 148 sensorName.c_str(), value, timestamp)); 149} 150 151namespace onChange 152{ 153void LogToJournal::commit(const std::string& sensorName, uint64_t timestamp, 154 double value) 155{ 156 std::string msg = "Value changed on sensor " + sensorName + 157 ", recorded value " + std::to_string(value) + 158 ", timestamp " + timestampToString(timestamp); 159 160 phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str()); 161} 162 163void LogToRedfish::commit(const std::string& sensorName, uint64_t timestamp, 164 double value) 165{ 166 const char* messageId = "OpenBMC.0.1.0.DiscreteThresholdOnChange"; 167 phosphor::logging::log<phosphor::logging::level::INFO>( 168 "Uncondtional discrete threshold triggered", 169 phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageId), 170 phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%f,%llu", 171 sensorName.c_str(), value, timestamp)); 172} 173} // namespace onChange 174} // namespace discrete 175 |
|
88void UpdateReport::commit(const std::string&, uint64_t, double) 89{ 90 for (const auto& name : reportNames) 91 { 92 reportManager.updateReport(name); 93 } 94} 95} // namespace action | 176void UpdateReport::commit(const std::string&, uint64_t, double) 177{ 178 for (const auto& name : reportNames) 179 { 180 reportManager.updateReport(name); 181 } 182} 183} // namespace action |