sensu-plugin 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu-handler.rb CHANGED
@@ -68,13 +68,15 @@ module Sensu
68
68
  occurrences = @event['check']['occurrences'] || 1
69
69
  interval = @event['check']['interval'] || 30
70
70
  refresh = @event['check']['refresh'] || 1800
71
- if @event['occurrences'] < occurrences
72
- bail 'not enough occurrences'
73
- end
74
- if @event['occurrences'] > occurrences && @event['action'] == 'create'
75
- number = refresh.fdiv(interval).to_i
76
- unless number == 0 || @event['occurrences'] % number == 0
77
- bail 'only handling every ' + number.to_s + ' occurrences'
71
+ if @event['action'] == 'create'
72
+ if @event['occurrences'] < occurrences
73
+ bail 'not enough occurrences'
74
+ end
75
+ if @event['occurrences'] > occurrences
76
+ number = refresh.fdiv(interval).to_i
77
+ unless number == 0 || @event['occurrences'] % number == 0
78
+ bail 'only handling every ' + number.to_s + ' occurrences'
79
+ end
78
80
  end
79
81
  end
80
82
  end
@@ -84,11 +86,12 @@ module Sensu
84
86
  end
85
87
 
86
88
  def filter_silenced
87
- stashes = {
88
- 'client' => '/silence/' + @event['client']['name'],
89
- 'check' => '/silence/' + @event['client']['name'] + '/' + @event['check']['name']
90
- }
91
- stashes.each do |scope, path|
89
+ stashes = [
90
+ ['client', '/silence/' + @event['client']['name']],
91
+ ['check', '/silence/' + @event['client']['name'] + '/' + @event['check']['name']],
92
+ ['check', '/silence/all/' + @event['check']['name']]
93
+ ]
94
+ stashes.each do |(scope, path)|
92
95
  begin
93
96
  timeout(2) do
94
97
  if stash_exists?(path)
data/lib/sensu-plugin.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  module Plugin
3
- VERSION = "0.1.7"
3
+ VERSION = "0.2.0"
4
4
  EXIT_CODES = {
5
5
  'OK' => 0,
6
6
  'WARNING' => 1,
@@ -8,9 +8,9 @@ module Sensu
8
8
 
9
9
  attr_accessor :argv
10
10
 
11
- def initialize
12
- super
13
- self.argv = self.parse_options
11
+ def initialize(argv=ARGV)
12
+ super()
13
+ self.argv = self.parse_options(argv)
14
14
  end
15
15
 
16
16
  # Implementing classes should override this to produce appropriate
@@ -28,6 +28,17 @@ module Sensu
28
28
  end
29
29
  end
30
30
 
31
+ class Statsd < Sensu::Plugin::CLI
32
+ def output(*args)
33
+ if args[0].is_a?(Exception) || args[1].nil?
34
+ puts args[0].to_s
35
+ else
36
+ type = args[2] || 'kv'
37
+ puts [args[0..1].join(':'), type].join('|')
38
+ end
39
+ end
40
+ end
41
+
31
42
  end
32
43
  end
33
44
  end
@@ -28,3 +28,22 @@ class TestGraphiteMetricExternal < MiniTest::Unit::TestCase
28
28
  end
29
29
 
30
30
  end
31
+
32
+ class TestStatsdMetricExternal < MiniTest::Unit::TestCase
33
+ include SensuPluginTestHelper
34
+
35
+ def setup
36
+ set_script 'external/statsd-output'
37
+ end
38
+
39
+ def test_statsd
40
+ lines = run_script.split("\n")
41
+ assert lines.size == 2
42
+ lines.each do |line|
43
+ assert line.split('|').size == 2
44
+ assert line.split('|').first.split(':').size == 2
45
+ end
46
+ end
47
+
48
+ end
49
+
@@ -9,22 +9,36 @@ class TestFilterExternal < MiniTest::Unit::TestCase
9
9
  set_script 'external/handle-filter'
10
10
  end
11
11
 
12
- def test_resolve_not_enough_occurrences
12
+ def test_create_not_enough_occurrences
13
13
  event = {
14
14
  'client' => { 'name' => 'test' },
15
15
  'check' => { 'name' => 'test', 'occurrences' => 2 },
16
- 'occurrences' => 1
16
+ 'occurrences' => 1,
17
+ 'action' => 'create'
17
18
  }
18
19
  output = run_script_with_input(JSON.generate(event))
19
20
  assert_equal(0, $?.exitstatus)
20
21
  assert_match(/^not enough occurrences/, output)
21
22
  end
22
23
 
23
- def test_resolve_enough_occurrences
24
+ def test_create_enough_occurrences
24
25
  event = {
25
26
  'client' => { 'name' => 'test' },
26
27
  'check' => { 'name' => 'test', 'occurrences' => 2 },
27
- 'occurrences' => 3
28
+ 'occurrences' => 2,
29
+ 'action' => 'create'
30
+ }
31
+ output = run_script_with_input(JSON.generate(event))
32
+ assert_equal(0, $?.exitstatus)
33
+ assert_match(/^Event:/, output)
34
+ end
35
+
36
+ def test_resolve_not_enough_occurrences
37
+ event = {
38
+ 'client' => { 'name' => 'test' },
39
+ 'check' => { 'name' => 'test', 'occurrences' => 2 },
40
+ 'occurrences' => 1,
41
+ 'action' => 'resolve'
28
42
  }
29
43
  output = run_script_with_input(JSON.generate(event))
30
44
  assert_equal(0, $?.exitstatus)
@@ -79,17 +93,6 @@ class TestFilterExternal < MiniTest::Unit::TestCase
79
93
  assert_match(/^Event:/, output)
80
94
  end
81
95
 
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
-
93
96
  def test_dependency_event_exists
94
97
  event = {
95
98
  'client' => { 'name' => 'test' },
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: 21
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 7
10
- version: 0.1.7
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
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-03-14 00:00:00 -07:00
19
+ date: 2013-09-30 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -89,15 +89,15 @@ extra_rdoc_files: []
89
89
 
90
90
  files:
91
91
  - lib/sensu-handler.rb
92
- - lib/sensu-plugin.rb
93
92
  - lib/sensu-plugin/check/cli.rb
94
93
  - lib/sensu-plugin/cli.rb
95
94
  - lib/sensu-plugin/metric/cli.rb
96
95
  - lib/sensu-plugin/utils.rb
96
+ - lib/sensu-plugin.rb
97
97
  - test/external_check_test.rb
98
98
  - test/external_handler_test.rb
99
- - test/handle_filter_test.rb
100
99
  - test/external_metric_test.rb
100
+ - test/handle_filter_test.rb
101
101
  - test/helper.rb
102
102
  has_rdoc: true
103
103
  homepage: https://github.com/sonian/sensu-plugin
@@ -136,6 +136,6 @@ summary: Sensu Plugins
136
136
  test_files:
137
137
  - test/external_check_test.rb
138
138
  - test/external_handler_test.rb
139
- - test/handle_filter_test.rb
140
139
  - test/external_metric_test.rb
140
+ - test/handle_filter_test.rb
141
141
  - test/helper.rb