60 lines
2.0 KiB
C++
60 lines
2.0 KiB
C++
#include "mix_cc/json.h"
|
|
#include "mix_cc/type/mix_time.h"
|
|
#include <cmath>
|
|
#include <eqpalg/utility/build_alarm_info.h>
|
|
namespace utility {
|
|
using std::string;
|
|
|
|
AlarmInfo build_alarm_info(const string &alarm_level, const string &ruleId,
|
|
const string &name, const string &group,
|
|
const std::string &alarm_content,
|
|
const mix_cc::time_range_t &time_range) {
|
|
AlarmInfo ret;
|
|
// 设置 key - result
|
|
ret.content[0]["key"] = alarm_level;
|
|
ret.content[0]["result"] = alarm_content;
|
|
ret.content[0]["alarm_time"] =
|
|
mix_cc::mix_time_t(time_range.get_right()).to_milliseconds();
|
|
// 设置报警基本信息
|
|
ret.alarmed = true;
|
|
ret.alarm_start_time = time_range.get_left();
|
|
ret.alarm_end_time = time_range.get_right(); // 2021-10-27
|
|
ret.cfg_info.id = ruleId;
|
|
ret.cfg_info.name = name;
|
|
ret.cfg_info.group = group;
|
|
ret.cfg_info.descName = alarm_content;
|
|
ret.cfg_info.remark = alarm_content;
|
|
return ret;
|
|
}
|
|
|
|
AlarmInfo
|
|
build_alarm_info(const string &alarm_level, const string &ruleId,
|
|
const string &name, const string &group,
|
|
const std::string &alarm_content,
|
|
const std::vector<double> &value,
|
|
const std::vector<mix_cc::float_range_t> &desire_range,
|
|
const mix_cc::time_range_t &time_range) {
|
|
// 设置原始报警信息
|
|
auto ret = build_alarm_info(alarm_level, ruleId, name, group, alarm_content,
|
|
time_range);
|
|
auto dr_array = mix_cc::json::array();
|
|
for (const auto &x : desire_range) {
|
|
dr_array.push_back(x.to_array());
|
|
}
|
|
// 为原始报警信息添加更多信息
|
|
ret.content[0]["value"] = value;
|
|
ret.content[0]["desire_range"] = dr_array;
|
|
return ret;
|
|
}
|
|
|
|
string get_msg_level(double limit_down, double limit_up, double value) {
|
|
if (value < limit_down) {
|
|
return value < limit_down - fabs(limit_down * 0.3) ? "ERROR" : "WARN";
|
|
} else {
|
|
return value > limit_up + fabs(limit_up * 0.3) ? "ERROR" : "WARN";
|
|
}
|
|
return "NULL";
|
|
}
|
|
|
|
} // namespace utility
|