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
7 , std::string
const & sev
8 , std::vector<std::string>
const & sources
9 , std::vector<std::string>
const & categories
10 , std::string
const & regex
11 , std::string
const & test
12 ,
bool persistent_cond
21 : description_ ( desc )
22 , severity_(get_sev_from_string(sev))
29 , match_type ( MATCH_REGEX )
33 , tc ( at_least ? occur : occur+1 )
34 , at_least_ ( at_least )
38 , t_group ( target_group )
39 , persistent_ ( persistent_cond )
54 , notify_on_source ( )
55 , notify_on_target ( )
56 , notify_on_status ( )
57 , catched_messages ( 0 )
60 std::vector<std::string>::const_iterator it = sources.begin();
61 while(it!=sources.end())
70 e_srcs.push_back(regex_t(*it));
71 srcs_str.append(*it).append(
", ");
76 srcs_str.resize(srcs_str.size()-2);
79 it = categories.begin();
80 while(it!=categories.end())
89 e_cats.push_back(regex_t(*it));
90 cats_str.append(*it).append(
", ");
95 cats_str.resize(cats_str.size()-2);
98 if (regex.empty() || (regex.compare(
"*")==0))
99 match_type = MATCH_ANY;
101 match_type = MATCH_REGEX;
104 if( !parse_condition_test( test, test_expr) )
105 throw std::runtime_error(
"condition test function parse failed");
109 ma_condition::reset( )
112 catched_messages = 0;
115 void ma_condition::init( )
117 hitmap.set_parent(
this);
121 ma_condition::match(
qt_mf_msg const & msg
129 if (sev_<severity_)
return false;
130 if (!match_srcs())
return false;
131 if (!match_cats())
return false;
134 if (!match_body())
return false;
140 if (!match_test())
return false;
143 unsigned int result = hitmap.capture(msg, src_, tgt_, what_);
145 TLOG(TLVL_DEBUG) <<
"cond::match() result = " << result <<
" src = " << src_;
148 if (result & STATUS_CHANGE) status.push_back(
this);
149 if (result & SOURCE_CHANGE) source.push_back(
this);
150 if (result & TARGET_CHANGE) target.push_back(
this);
159 bool ma_condition::event(
size_t src,
size_t tgt, time_t t, conds_t & status )
161 if ( hitmap.event(src, tgt, t) )
164 status.push_back(
this);
171 void ma_condition::extract_fields (
qt_mf_msg const & msg)
174 get_source_from_msg(src_, msg);
175 cat_ = msg.
cat().toStdString();
176 bdy_ = msg.
text(
false).toStdString();
179 void ma_condition::update_fields ( )
189 bool ma_condition::match_srcs ( )
191 if (any_src)
return true;
193 size_t imax = e_srcs.size();
195 for (
size_t i=0; i<imax; ++i)
197 if (boost::regex_match(src_, what_, e_srcs[i]))
return true;
203 bool ma_condition::match_cats ( )
205 if (any_cat)
return true;
207 size_t imax = e_cats.size();
209 for (
size_t i=0; i<imax; ++i)
211 if (boost::regex_match(cat_, what_, e_cats[i]))
return true;
217 bool ma_condition::match_body ( )
219 if (match_type == MATCH_ANY)
222 if (boost::regex_search(bdy_, what_, e))
226 if( t_group > what_.size() )
227 throw std::runtime_error(
"match_body: target group does not exit");
229 tgt_ = std::string(what_[t_group].first, what_[t_group].second);
238 bool ma_condition::match_test ( )
240 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