sensu-plugin 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sensu-handler.rb +1 -1
- data/lib/sensu-plugin.rb +1 -1
- data/test/handle_filter_test.rb +53 -5
- data/test/helper.rb +3 -2
- metadata +18 -4
data/lib/sensu-handler.rb
CHANGED
@@ -73,7 +73,7 @@ module Sensu
|
|
73
73
|
end
|
74
74
|
if @event['occurrences'] > occurrences && @event['action'] == 'create'
|
75
75
|
number = refresh.fdiv(interval).to_i
|
76
|
-
unless @event['occurrences'] % number == 0
|
76
|
+
unless number == 0 || @event['occurrences'] % number == 0
|
77
77
|
bail 'only handling every ' + number.to_s + ' occurrences'
|
78
78
|
end
|
79
79
|
end
|
data/lib/sensu-plugin.rb
CHANGED
data/test/handle_filter_test.rb
CHANGED
@@ -12,7 +12,7 @@ class TestFilterExternal < MiniTest::Unit::TestCase
|
|
12
12
|
def test_resolve_not_enough_occurrences
|
13
13
|
event = {
|
14
14
|
'client' => { 'name' => 'test' },
|
15
|
-
'check' => { 'name' => 'test', 'occurrences' => 2},
|
15
|
+
'check' => { 'name' => 'test', 'occurrences' => 2 },
|
16
16
|
'occurrences' => 1
|
17
17
|
}
|
18
18
|
output = run_script_with_input(JSON.generate(event))
|
@@ -23,7 +23,7 @@ class TestFilterExternal < MiniTest::Unit::TestCase
|
|
23
23
|
def test_resolve_enough_occurrences
|
24
24
|
event = {
|
25
25
|
'client' => { 'name' => 'test' },
|
26
|
-
'check' => { 'name' => 'test', 'occurrences' => 2},
|
26
|
+
'check' => { 'name' => 'test', 'occurrences' => 2 },
|
27
27
|
'occurrences' => 3
|
28
28
|
}
|
29
29
|
output = run_script_with_input(JSON.generate(event))
|
@@ -31,17 +31,65 @@ class TestFilterExternal < MiniTest::Unit::TestCase
|
|
31
31
|
assert_match(/^Event:/, output)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def test_refresh_enough_occurrences
|
35
35
|
event = {
|
36
36
|
'client' => { 'name' => 'test' },
|
37
|
-
'check' => { 'name' => 'test'
|
38
|
-
'occurrences' =>
|
37
|
+
'check' => { 'name' => 'test' },
|
38
|
+
'occurrences' => 60,
|
39
|
+
'action' => 'create'
|
39
40
|
}
|
40
41
|
output = run_script_with_input(JSON.generate(event))
|
41
42
|
assert_equal(0, $?.exitstatus)
|
42
43
|
assert_match(/^Event:/, output)
|
43
44
|
end
|
44
45
|
|
46
|
+
def test_refresh_not_enough_occurrences
|
47
|
+
event = {
|
48
|
+
'client' => { 'name' => 'test' },
|
49
|
+
'check' => { 'name' => 'test' },
|
50
|
+
'occurrences' => 59,
|
51
|
+
'action' => 'create'
|
52
|
+
}
|
53
|
+
output = run_script_with_input(JSON.generate(event))
|
54
|
+
assert_equal(0, $?.exitstatus)
|
55
|
+
assert_match(/^only handling every/, output)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_refresh_bypass
|
59
|
+
event = {
|
60
|
+
'client' => { 'name' => 'test' },
|
61
|
+
'check' => { 'name' => 'test', 'refresh' => 0 },
|
62
|
+
'occurrences' => 59,
|
63
|
+
'action' => 'create'
|
64
|
+
}
|
65
|
+
output = run_script_with_input(JSON.generate(event))
|
66
|
+
assert_equal(0, $?.exitstatus)
|
67
|
+
assert_match(/^Event:/, output)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_refresh_less_than_interval
|
71
|
+
event = {
|
72
|
+
'client' => { 'name' => 'test' },
|
73
|
+
'check' => { 'name' => 'test', 'refresh' => 30 },
|
74
|
+
'occurrences' => 59,
|
75
|
+
'action' => 'create'
|
76
|
+
}
|
77
|
+
output = run_script_with_input(JSON.generate(event))
|
78
|
+
assert_equal(0, $?.exitstatus)
|
79
|
+
assert_match(/^Event:/, output)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_resolve_not_enough_occurrences
|
83
|
+
event = {
|
84
|
+
'client' => { 'name' => 'test' },
|
85
|
+
'check' => { 'name' => 'test', 'occurrences' => 2 },
|
86
|
+
'occurrences' => 1
|
87
|
+
}
|
88
|
+
output = run_script_with_input(JSON.generate(event))
|
89
|
+
assert_equal(0, $?.exitstatus)
|
90
|
+
assert_match(/^not enough occurrences/, output)
|
91
|
+
end
|
92
|
+
|
45
93
|
def test_dependency_event_exists
|
46
94
|
event = {
|
47
95
|
'client' => { 'name' => 'test' },
|
data/test/helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
gem 'minitest' if RUBY_VERSION < '1.9.0'
|
2
3
|
require 'minitest/autorun'
|
3
4
|
|
4
5
|
module SensuPluginTestHelper
|
@@ -8,13 +9,13 @@ module SensuPluginTestHelper
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def run_script(*args)
|
11
|
-
IO.popen([@script] + args, 'r+') do |child|
|
12
|
+
IO.popen(([@script] + args).join(' '), 'r+') do |child|
|
12
13
|
child.read
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def run_script_with_input(input, *args)
|
17
|
-
IO.popen([@script] + args, 'r+') do |child|
|
18
|
+
IO.popen(([@script] + args).join(' '), 'r+') do |child|
|
18
19
|
child.puts input
|
19
20
|
child.close_write
|
20
21
|
child.read
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Decklin Foster
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-03-14 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,20 @@ dependencies:
|
|
63
63
|
version: "0"
|
64
64
|
type: :development
|
65
65
|
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: minitest
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
66
80
|
description: Plugins and helper libraries for Sensu, a monitoring framework
|
67
81
|
email:
|
68
82
|
- decklin@red-bean.com
|