1 #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
2 #include "ErrorHandler/MessageAnalyzer/ma_parse.h"
4 using namespace novadaq::errorhandler;
6 ma_condition::ma_condition(std::string
const& desc, std::string
const& sev, std::vector<std::string>
const& sources, std::vector<std::string>
const& categories, std::string
const& regex, std::string
const& test,
bool persistent_cond,
int occur,
bool at_least,
int timespan,
bool per_source,
bool per_target,
int target_group,
ma_timing_events& events)
8 , severity_(get_sev_from_string(sev))
15 , match_type(MATCH_REGEX)
19 , tc(at_least ? occur : occur + 1)
24 , t_group(target_group)
25 , persistent_(persistent_cond)
46 std::vector<std::string>::const_iterator it = sources.begin();
47 while (it != sources.end())
56 e_srcs.push_back(regex_t(*it));
57 srcs_str.append(*it).append(
", ");
62 srcs_str.resize(srcs_str.size() - 2);
65 it = categories.begin();
66 while (it != categories.end())
75 e_cats.push_back(regex_t(*it));
76 cats_str.append(*it).append(
", ");
81 cats_str.resize(cats_str.size() - 2);
84 if (regex.empty() || (regex.compare(
"*") == 0))
85 match_type = MATCH_ANY;
87 match_type = MATCH_REGEX;
90 if (!parse_condition_test(test, test_expr))
91 throw std::runtime_error(
"condition test function parse failed");
94 void ma_condition::reset()
100 void ma_condition::init()
102 hitmap.set_parent(
this);
105 bool ma_condition::match(
qt_mf_msg const& msg, conds_t& status, conds_t& source, conds_t& target)
110 if (sev_ < severity_)
return false;
111 if (!match_srcs())
return false;
112 if (!match_cats())
return false;
115 if (!match_body())
return false;
121 if (!match_test())
return false;
124 unsigned int result = hitmap.capture(msg, src_, tgt_, what_);
126 TLOG(TLVL_DEBUG) <<
"cond::match() result = " << result <<
" src = " << src_;
129 if (result & STATUS_CHANGE) status.push_back(
this);
130 if (result & SOURCE_CHANGE) source.push_back(
this);
131 if (result & TARGET_CHANGE) target.push_back(
this);
140 bool ma_condition::event(
size_t src,
size_t tgt, time_t t, conds_t& status)
142 if (hitmap.event(src, tgt, t))
145 status.push_back(
this);
152 void ma_condition::extract_fields(
qt_mf_msg const& msg)
155 get_source_from_msg(src_, msg);
156 cat_ = msg.
cat().toStdString();
157 bdy_ = msg.
text(
false).toStdString();
160 void ma_condition::update_fields()
170 bool ma_condition::match_srcs()
172 if (any_src)
return true;
174 size_t imax = e_srcs.size();
176 for (
size_t i = 0; i < imax; ++i)
178 if (boost::regex_match(src_, what_, e_srcs[i]))
return true;
184 bool ma_condition::match_cats()
186 if (any_cat)
return true;
188 size_t imax = e_cats.size();
190 for (
size_t i = 0; i < imax; ++i)
192 if (boost::regex_match(cat_, what_, e_cats[i]))
return true;
198 bool ma_condition::match_body()
200 if (match_type == MATCH_ANY)
203 if (boost::regex_search(bdy_, what_, e))
207 if (t_group > what_.size())
208 throw std::runtime_error(
"match_body: target group does not exit");
210 tgt_ = std::string(what_[t_group].first, what_[t_group].second);
219 bool ma_condition::match_test()
221 return test_expr.evaluate(
this);
Qt wrapper around MessageFacility message
sev_code_t sev() const
Get the severity of the message
QString const & text(bool mode) const
Get the text of the message
QString const & cat() const
Get the category of the message