#include #include #include #include MeterBound::MeterBound(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("MeterBound:" + rule_name_, AUTO_CATCH_PID)); } MeterBound::~MeterBound() {} /** * @brief 重写 init * * @return int */ int MeterBound::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 MeterBound::reload_config() { string tmp_exp = rule_json_.at("alarm_option").at("value").at(1).get(); exp_str_ = get_macro_replaced_exp(tmp_exp); error_up_ = rule_json_.at("alarm_option").at("error_up").at(1).get(); error_down_ = rule_json_.at("alarm_option").at("error_down").at(1).get(); error_str_ = rule_json_.at("interval").at("error").at(1).get(); if (exp_act_ == nullptr && exp_str_ != "") { exp_act_ = std::make_unique(exp_str_, &mm_vars); } return 0; } AlarmInfo MeterBound::mon_proc() { this->value_ = this->exp_act_->evaluate(); if (this->value_ > this->error_up_) { //报警时间 依赖query_time_range_ 设置 this->query_time_range_.set_left(this->query_time_range_.get_right() - this->delay_time_); std::stringstream ss1; std::stringstream ss2; ss1 << fixed << setprecision(2) << this->value_; ss2 << fixed << setprecision(2) << this->error_up_; string msg = this->rule_name_ + " " + this->error_str_ + ":" + ss1.str() + "大于" + ss2.str(); this->logger_->Debug() << msg << std::endl; return utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_, "MeterBound", msg, query_time_range_); } else if (this->value_ < this->error_down_) { //报警时间 依赖query_time_range_ 设置 this->query_time_range_.set_left(this->query_time_range_.get_right() - this->delay_time_); std::stringstream ss1; std::stringstream ss2; ss1 << fixed << setprecision(2) << this->value_; ss2 << fixed << setprecision(2) << this->error_down_; string msg = this->rule_name_ + " " + this->error_str_ + ":" + ss1.str() + "小于" + ss2.str(); this->logger_->Debug() << msg << std::endl; return utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_, "MeterBound", msg, query_time_range_); } return AlarmInfo{}; } mix_cc::json MeterBound::exec_cron() {} AlarmInfo MeterBound::cron_proc() {} void MeterBound::reset_dev_data() { auto reSult = m_memclient.Insert(this->Jkey_.c_str(), this->Jvalue_.c_str()); auto reSult2 = m_memclient.Insert(string(this->Jkey_ + "_id").c_str(), this->rule_id_.c_str()); if (1 != reSult || 1 != reSult2) { this->logger_->Debug() << "m_memclient.Insert异常[0,set data " "fail;-1,key=null or value=null]: Insert1:" << reSult << " Insert2:" << reSult2 << endl; } }