-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix #1512] add not in
comparison into Trigger Agent
#1545
[fix #1512] add not in
comparison into Trigger Agent
#1545
Conversation
@@ -11,7 +11,7 @@ class TriggerAgent < Agent | |||
|
|||
The `type` can be one of #{VALID_COMPARISON_TYPES.map { |t| "`#{t}`" }.to_sentence} and compares with the `value`. Note that regex patterns are matched case insensitively. If you want case sensitive matching, prefix your pattern with `(?-i)`. | |||
|
|||
The `value` can be a single value or an array of values. In the case of an array, if one or more values match then the rule matches. | |||
The `value` can be a single value or an array of values (all values must be stored as strings). In the case of an array, if one or more values match then the rule matches. *Warning*: avoid using `field!=value` with arrays, you should use `not in` instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe "(in which case, all items in the array must be strings)"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More complete re-write:
The value
can be a single value or an array of values. In the case of an array, all items must be strings, and if one or more values match, then the rule matches. Note: avoid using field!=value
with arrays, you should use not in
instead.
Thanks @andrey-yantsen, would you mind updating the spec too? |
Updating spec was a great idea :) |
Maybe just this? rule_values.any? do |rule_value|
if rule['type'] == "regex"
value_at_path.to_s =~ Regexp.new(rule_value, Regexp::IGNORECASE)
elsif rule['type'] == "!regex"
value_at_path.to_s !~ Regexp.new(rule_value, Regexp::IGNORECASE)
elsif rule['type'] == "field>value"
value_at_path.to_f > rule_value.to_f
elsif rule['type'] == "field>=value"
value_at_path.to_f >= rule_value.to_f
elsif rule['type'] == "field<value"
value_at_path.to_f < rule_value.to_f
elsif rule['type'] == "field<=value"
value_at_path.to_f <= rule_value.to_f
elsif rule['type'] == "field==value"
value_at_path.to_s == rule_value.to_s
elsif rule['type'] == "field!=value"
value_at_path.to_s != rule_value.to_s
elsif rule['type'] == 'in'
rule_values.include?(value_at_path.to_s)
elsif rule['type'] == 'not in'
!rule_values.include?(value_at_path.to_s)
else
raise "Invalid type of #{rule['type']} in TriggerAgent##{id}"
end
end I added |
I can not agree with it :) It's quite strange to compare entire list inside |
You're right, I misunderstood. Want to add |
Actually |
Yea, that's a good point. I'm tired this evening. We don't need it :) |
Ok :) |
Thanks @andrey-yantsen, works great! |
Add
not in
comparison for doing!=
on arrays. Also warning about!=
and arrays was added.Fixes #1512.