eis/eqpalg/.do_not_use/otheralg/alarm_monitor.cpp

73 lines
2.6 KiB
C++

#include <eqpalg/algs/alarm_monitor.h>
#include <eqpalg/exp_macro/get_macro_replaced_exp.h>
#include <eqpalg/utility/build_alarm_info.h>
AlarmMonitor::AlarmMonitor(const string& name, const mix_cc::json& rule_json,
const string& ruleId, size_t dims)
: Exp(name, rule_json, ruleId, dims) {
logger_.reset(new LOG("AlarmMonitor:" + rule_name_, AUTO_CATCH_PID));
}
AlarmMonitor::~AlarmMonitor() {}
/**
* @brief 重写 init
*
* @return int
*/
int AlarmMonitor::init() {
int ret = 0;
try {
AlgBase::init();
reload_config();
} catch (const std::exception& e) {
std::throw_with_nested(
mix_cc::Exception(-1, "load error", BOOST_CURRENT_LOCATION));
}
return ret;
}
int AlarmMonitor::reload_config() {
string tmp_exp =
rule_json_.at("alarm_option").at("alarm_start").at(1).get<std::string>();
exp_str_ = get_macro_replaced_exp(tmp_exp);
if (exp_act_ == nullptr && exp_str_ != "") {
exp_act_ =
std::make_unique<mix_cc::matheval::Expression>(exp_str_, &mm_vars);
}
tmp_exp =
rule_json_.at("alarm_option").at("alarm_end").at(1).get<std::string>();
exp_str_ = get_macro_replaced_exp(tmp_exp);
if (exp_feedback_ == nullptr && exp_str_ != "") {
exp_feedback_ =
std::make_unique<mix_cc::matheval::Expression>(exp_str_, &mm_vars);
}
error_str_ = rule_json_.at("interval").at("error").at(1).get<std::string>();
return 0;
}
AlarmInfo AlarmMonitor::mon_proc() {
if (this->exp_act_->evaluate()) {
//报警时间 依赖query_time_range_ 设置
this->query_time_range_.set_left(this->query_time_range_.get_right() -
this->delay_time_);
string msg = this->rule_name_ + this->error_str_ + " 开始";
this->logger_->Debug() << this->rule_name_ << " 报警开始" << std::endl;
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
"AlarmMonitor", msg, query_time_range_);
}
if (this->exp_feedback_->evaluate()) {
//报警时间 依赖query_time_range_ 设置
this->query_time_range_.set_left(this->query_time_range_.get_right() -
this->delay_time_);
string msg = this->rule_name_ + this->error_str_ + " 结束";
this->logger_->Debug() << this->rule_name_ << " 报警结束" << std::endl;
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
"AlarmMonitor", msg, query_time_range_);
}
return AlarmInfo{};
}
mix_cc::json AlarmMonitor::exec_cron() {}
AlarmInfo AlarmMonitor::cron_proc() {}