2026-05-09 11:23:45 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @file alarm_handler.hpp
|
|
|
|
|
|
* @brief 处理报警信息
|
|
|
|
|
|
* 1.将队列的报警信息存入数据库
|
|
|
|
|
|
* 2.向页面发送mq
|
|
|
|
|
|
* @author your name (you@domain.com)
|
|
|
|
|
|
* @version 0.1
|
|
|
|
|
|
* @date 2024-05-06
|
|
|
|
|
|
*
|
|
|
|
|
|
* Copyright: Baosight Co. Ltd.
|
|
|
|
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
#include <eqpalg/table_struct/fv_result_latest.h>
|
|
|
|
|
|
#include <eqpalg/table_struct/t_rule_record_time.h>
|
|
|
|
|
|
#include <eqpalg/table_struct/t_rule_result.h>
|
|
|
|
|
|
#include <glob/ProxyMag.h>
|
|
|
|
|
|
#include <log4cplus/LOG.h>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include <mix_cc/json.h>
|
|
|
|
|
|
#include <mix_cc/sql.h>
|
|
|
|
|
|
#include <mix_cc/sql/database/db2_t.h>
|
|
|
|
|
|
#include <mix_cc/type/mix_time.h>
|
|
|
|
|
|
class AlarmHandler {
|
|
|
|
|
|
private:
|
2026-05-09 13:30:09 +08:00
|
|
|
|
MessageICEPrx message_queue_proxy_;
|
|
|
|
|
|
std::unique_ptr<LOG> logger_;
|
2026-05-09 11:23:45 +08:00
|
|
|
|
public:
|
|
|
|
|
|
AlarmHandler() {
|
|
|
|
|
|
logger_ = std::make_unique<LOG>("AlarmHandler");
|
|
|
|
|
|
message_queue_proxy_ = ProxyMag::GetAppICEPrx("baosight/zmqp");
|
|
|
|
|
|
}
|
|
|
|
|
|
~AlarmHandler() {}
|
|
|
|
|
|
int store_alarm(const string &alarm_info) {
|
|
|
|
|
|
mix_cc::json js1 = mix_cc::json::parse(alarm_info);
|
|
|
|
|
|
mix_cc::mix_time_t rule_lmt;
|
|
|
|
|
|
mix_cc::mix_time_t rule_lst;
|
|
|
|
|
|
string ruleid = js1.at("rule").at("id").get<string>();
|
|
|
|
|
|
T_RULE_RECORD_TIME t_rule_record_time;
|
|
|
|
|
|
auto select_statement =
|
|
|
|
|
|
select(t_rule_record_time.tos(), t_rule_record_time.rule_tom())
|
|
|
|
|
|
.from(t_rule_record_time)
|
|
|
|
|
|
.where(t_rule_record_time.ruleId() =
|
|
|
|
|
|
js1.at("rule").at("id").get<string>());
|
|
|
|
|
|
|
|
|
|
|
|
auto tos_tom_maybe =
|
|
|
|
|
|
mix_cc::sql::exec<db2_t, T_RULE_RECORD_TIME>(select_statement);
|
|
|
|
|
|
if (tos_tom_maybe.is_just()) {
|
|
|
|
|
|
auto tos_tom = tos_tom_maybe.unsafe_get_just();
|
|
|
|
|
|
if (tos_tom.size() == 0) {
|
|
|
|
|
|
logger_->Error() << "t_rule_record_time表格无记录" << endl;
|
|
|
|
|
|
rule_lmt = mix_cc::mix_time_t(std::chrono::system_clock::now());
|
|
|
|
|
|
rule_lst = mix_cc::mix_time_t(std::chrono::system_clock::now());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
rule_lmt = tos_tom[0].rule_tom;
|
|
|
|
|
|
rule_lst = tos_tom[0].tos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger_->Error() << "t_rule_record_time表格查询失败" << endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool is_200_status = false;
|
|
|
|
|
|
FV_RESULT_LATEST frl;
|
|
|
|
|
|
auto select_sql =
|
|
|
|
|
|
select(frl.statuscode())
|
|
|
|
|
|
.from(frl)
|
|
|
|
|
|
.where(frl.ruleId() == ruleid, frl.statuscode().operator>(199),
|
|
|
|
|
|
frl.statuscode().operator<(210));
|
|
|
|
|
|
auto select_rt_maybe =
|
|
|
|
|
|
mix_cc::sql::exec<db2_t, FV_RESULT_LATEST>(select_sql);
|
|
|
|
|
|
if (select_rt_maybe.is_just()) {
|
|
|
|
|
|
auto select_rt = select_rt_maybe.unsafe_get_just();
|
|
|
|
|
|
if (!select_rt.empty()) {
|
|
|
|
|
|
is_200_status = true;
|
|
|
|
|
|
logger_->Debug() << "ruleid:" << ruleid << "|跟踪中------" << std::endl;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger_->Debug() << "ruleid:" << ruleid << "|无200,201,203"
|
|
|
|
|
|
<< std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger_->Error() << "ruleid:" << ruleid << "查询失败!" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
T_RULE_RESULT rr;
|
|
|
|
|
|
|
|
|
|
|
|
int rank =
|
|
|
|
|
|
js1.at("result")[0].at("key").get<std::string>() == "ERROR" ? 1 : 0;
|
|
|
|
|
|
if (is_200_status) {
|
|
|
|
|
|
short status = 200;
|
|
|
|
|
|
auto num = exec<db2_t, size_t>(insert_into(rr).set(
|
|
|
|
|
|
rr.ruleId() = js1.at("rule").at("id").get<string>(),
|
|
|
|
|
|
rr.ruleName() = js1.at("rule").at("name").get<string>(),
|
|
|
|
|
|
rr.ruleGroup() = js1.at("rule").at("group").get<string>(),
|
|
|
|
|
|
rr.ruleBtime() = mix_cc::mix_time_t(
|
|
|
|
|
|
js1.at("rule").at("rulebtime").get<int64_t>(), true),
|
|
|
|
|
|
rr.ruleEtime() = mix_cc::mix_time_t(
|
|
|
|
|
|
js1.at("rule").at("ruleetime").get<int64_t>(), true),
|
|
|
|
|
|
rr.dealResult() = 0, rr.result() = js1.at("result").dump(),
|
|
|
|
|
|
rr.ruleLastMTime() = rule_lmt, rr.ruleLastSTime() = rule_lst,
|
|
|
|
|
|
rr.rank() = rank, rr.statuscode() = status));
|
|
|
|
|
|
|
|
|
|
|
|
if (num.is_nothing()) {
|
|
|
|
|
|
logger_->Error() << "数据库存储异常" << endl;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
auto num = exec<db2_t, size_t>(insert_into(rr).set(
|
|
|
|
|
|
rr.ruleId() = js1.at("rule").at("id").get<string>(),
|
|
|
|
|
|
rr.ruleName() = js1.at("rule").at("name").get<string>(),
|
|
|
|
|
|
rr.ruleGroup() = js1.at("rule").at("group").get<string>(),
|
|
|
|
|
|
rr.ruleBtime() = mix_cc::mix_time_t(
|
|
|
|
|
|
js1.at("rule").at("rulebtime").get<int64_t>(), true),
|
|
|
|
|
|
rr.ruleEtime() = mix_cc::mix_time_t(
|
|
|
|
|
|
js1.at("rule").at("ruleetime").get<int64_t>(), true),
|
|
|
|
|
|
rr.dealResult() = 0, rr.result() = js1.at("result").dump(),
|
|
|
|
|
|
rr.ruleLastMTime() = rule_lmt, rr.ruleLastSTime() = rule_lst,
|
|
|
|
|
|
rr.rank() = rank));
|
|
|
|
|
|
|
|
|
|
|
|
if (num.is_nothing()) {
|
|
|
|
|
|
logger_->Error() << "数据库存储异常" << endl;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
std::vector<unsigned char> seq((unsigned char *)alarm_info.c_str(),
|
|
|
|
|
|
(unsigned char *)alarm_info.c_str() +
|
|
|
|
|
|
alarm_info.length());
|
|
|
|
|
|
message_queue_proxy_->SendDataShort(911, seq, alarm_info.length());
|
|
|
|
|
|
} catch (::Ice::LocalException &e) {
|
|
|
|
|
|
logger_->Error() << "消息队列发送失败,请检查消息" << e.what() << endl;
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|