[Why] Enhanced monitoring function. Regular expressions can be used in query's value. query can be {"job_id": "z9.*"}
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/monitoring/filter.cr | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/monitoring/filter.cr b/src/monitoring/filter.cr index bc6f901..d520e6e 100644 --- a/src/monitoring/filter.cr +++ b/src/monitoring/filter.cr @@ -56,13 +56,21 @@ class Filter
def match_query(query : Hash(String, JSON::Any), msg : Hash(String, JSON::Any)) query.each do |key, value| + return false unless msg.has_key?(key) + value = value.as_a - if value.includes?(nil) - return false unless msg.has_key?(key) - else - return false unless value.includes?(msg[key]?) - end + next if value.includes?(nil) + next if value.includes?(msg[key]?) + + return false unless regular_match(value, msg[key]?.to_s) end return true end + + private def regular_match(rules, string) + rules.each do |rule| + return true if string =~ /#{rule}/ + end + return false + end end
next if value.includes?(nil)
next if value.includes?(msg[key]?)
Why not use: next if value.includes?(nil) || value.includes?(msg[key]?)
As an array name, "value" may be confused.
Thanks, RenWen
end return true endreturn false unless regular_match(value, msg[key]?.to_s)
- private def regular_match(rules, string)
- rules.each do |rule|
return true if string =~ /#{rule}/
- end
- return false
- end
end
2.23.0