|
@@ -71,6 +71,28 @@ describe Agents::TriggerAgent do
|
|
}.should change { Event.count }.by(1)
|
|
}.should change { Event.count }.by(1)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ it "handles array of regex" do
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "a222b"
|
|
|
|
+ @checker.options['rules'][0] = {
|
|
|
|
+ 'type' => "regex",
|
|
|
|
+ 'value' => ["a\\db", "a\\Wb"],
|
|
|
|
+ 'path' => "foo.bar.baz",
|
|
|
|
+ }
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should_not change { Event.count }
|
|
|
|
+
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "a2b"
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should change { Event.count }.by(1)
|
|
|
|
+
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "a b"
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should change { Event.count }.by(1)
|
|
|
|
+ end
|
|
|
|
+
|
|
it "handles negated regex" do
|
|
it "handles negated regex" do
|
|
@event.payload['foo']['bar']['baz'] = "a2b"
|
|
@event.payload['foo']['bar']['baz'] = "a2b"
|
|
@checker.options['rules'][0] = {
|
|
@checker.options['rules'][0] = {
|
|
@@ -89,6 +111,24 @@ describe Agents::TriggerAgent do
|
|
}.should change { Event.count }.by(1)
|
|
}.should change { Event.count }.by(1)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ it "handles array of negated regex" do
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "a2b"
|
|
|
|
+ @checker.options['rules'][0] = {
|
|
|
|
+ 'type' => "!regex",
|
|
|
|
+ 'value' => ["a\\db", "a2b"],
|
|
|
|
+ 'path' => "foo.bar.baz",
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should_not change { Event.count }
|
|
|
|
+
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "a3b"
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should change { Event.count }.by(1)
|
|
|
|
+ end
|
|
|
|
+
|
|
it "puts can extract values into the message based on paths" do
|
|
it "puts can extract values into the message based on paths" do
|
|
@checker.receive([@event])
|
|
@checker.receive([@event])
|
|
Event.last.payload['message'].should == "I saw 'a2b' from Joe"
|
|
Event.last.payload['message'].should == "I saw 'a2b' from Joe"
|
|
@@ -109,6 +149,21 @@ describe Agents::TriggerAgent do
|
|
}.should_not change { Event.count }
|
|
}.should_not change { Event.count }
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ it "handles array of numerical comparisons" do
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "5"
|
|
|
|
+ @checker.options['rules'].first['value'] = [6, 3]
|
|
|
|
+ @checker.options['rules'].first['type'] = "field<value"
|
|
|
|
+
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should change { Event.count }.by(1)
|
|
|
|
+
|
|
|
|
+ @checker.options['rules'].first['value'] = [4, 3]
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should_not change { Event.count }
|
|
|
|
+ end
|
|
|
|
+
|
|
it "handles exact comparisons" do
|
|
it "handles exact comparisons" do
|
|
@event.payload['foo']['bar']['baz'] = "hello world"
|
|
@event.payload['foo']['bar']['baz'] = "hello world"
|
|
@checker.options['rules'].first['type'] = "field==value"
|
|
@checker.options['rules'].first['type'] = "field==value"
|
|
@@ -124,6 +179,21 @@ describe Agents::TriggerAgent do
|
|
}.should change { Event.count }.by(1)
|
|
}.should change { Event.count }.by(1)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ it "handles array of exact comparisons" do
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "hello world"
|
|
|
|
+ @checker.options['rules'].first['type'] = "field==value"
|
|
|
|
+
|
|
|
|
+ @checker.options['rules'].first['value'] = ["hello there", "hello universe"]
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should_not change { Event.count }
|
|
|
|
+
|
|
|
|
+ @checker.options['rules'].first['value'] = ["hello world", "hello universe"]
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should change { Event.count }.by(1)
|
|
|
|
+ end
|
|
|
|
+
|
|
it "handles negated comparisons" do
|
|
it "handles negated comparisons" do
|
|
@event.payload['foo']['bar']['baz'] = "hello world"
|
|
@event.payload['foo']['bar']['baz'] = "hello world"
|
|
@checker.options['rules'].first['type'] = "field!=value"
|
|
@checker.options['rules'].first['type'] = "field!=value"
|
|
@@ -140,6 +210,22 @@ describe Agents::TriggerAgent do
|
|
}.should change { Event.count }.by(1)
|
|
}.should change { Event.count }.by(1)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ it "handles array of negated comparisons" do
|
|
|
|
+ @event.payload['foo']['bar']['baz'] = "hello world"
|
|
|
|
+ @checker.options['rules'].first['type'] = "field!=value"
|
|
|
|
+ @checker.options['rules'].first['value'] = ["hello world", "hello world"]
|
|
|
|
+
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should_not change { Event.count }
|
|
|
|
+
|
|
|
|
+ @checker.options['rules'].first['value'] = ["hello there", "hello world"]
|
|
|
|
+
|
|
|
|
+ lambda {
|
|
|
|
+ @checker.receive([@event])
|
|
|
|
+ }.should change { Event.count }.by(1)
|
|
|
|
+ end
|
|
|
|
+
|
|
it "does fine without dots in the path" do
|
|
it "does fine without dots in the path" do
|
|
@event.payload = { 'hello' => "world" }
|
|
@event.payload = { 'hello' => "world" }
|
|
@checker.options['rules'].first['type'] = "field==value"
|
|
@checker.options['rules'].first['type'] = "field==value"
|