[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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/monitoring/filter.cr b/src/monitoring/filter.cr index bc6f901..5ddd547 100644 --- a/src/monitoring/filter.cr +++ b/src/monitoring/filter.cr @@ -56,12 +56,20 @@ 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]?) + next if value.includes?(nil) + next if value.includes?(msg[key]?) + + flag = false + value.each do |val| + if msg[key]?.to_s =~ /#{val}/ + flag = true + break + end end + return false unless flag end return true end