sensu-plugin 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu-handler.rb CHANGED
@@ -1,11 +1,20 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'sensu-plugin/utils'
4
+ require 'mixlib/cli'
4
5
 
5
6
  module Sensu
6
7
 
7
8
  class Handler
8
9
  include Sensu::Plugin::Utils
10
+ include Mixlib::CLI
11
+
12
+ attr_accessor :argv
13
+
14
+ def initialize(argv = ARGV)
15
+ super()
16
+ self.argv = parse_options(argv)
17
+ end
9
18
 
10
19
  # Implementing classes should override this.
11
20
 
data/lib/sensu-plugin.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  module Plugin
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  EXIT_CODES = {
5
5
  'OK' => 0,
6
6
  'WARNING' => 1,
@@ -57,7 +57,9 @@ module Sensu
57
57
  rescue SystemExit => e
58
58
  exit e.status
59
59
  rescue Exception => e
60
- check.critical "Check failed to run: #{e.message}, #{e.backtrace}"
60
+ # This can't call check.critical, as the check may have failed to construct
61
+ puts "Check failed to run: #{e.message}, #{e.backtrace}"
62
+ exit 2
61
63
  end
62
64
  check.warning "Check did not exit! You should call an exit code method."
63
65
  end
@@ -48,4 +48,8 @@ class TestCheckExternal < MiniTest::Unit::TestCase
48
48
  assert $?.exitstatus == 0 && output.include?('argv = foo')
49
49
  end
50
50
 
51
+ def test_bad_commandline
52
+ output = run_script '--doesnotexist'
53
+ assert $?.exitstatus == 2 && output.include?('doesnotexist') && output.include?('invalid option')
54
+ end
51
55
  end
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require 'json'
4
+
5
+ class TestHandlerArgumentExternal < MiniTest::Unit::TestCase
6
+ include SensuPluginTestHelper
7
+
8
+ def test_default
9
+ set_script 'external/handle-argument'
10
+ output = run_script_with_input(JSON.generate({}))
11
+ assert $?.exitstatus == 0 && output =~ /Value:\sfoo/
12
+ end
13
+
14
+ def test_short
15
+ set_script 'external/handle-argument -t bar'
16
+ output = run_script_with_input(JSON.generate({}))
17
+ assert $?.exitstatus == 0 && output =~ /Value:\sbar/
18
+ end
19
+
20
+ def test_long
21
+ set_script 'external/handle-argument --test bar'
22
+ output = run_script_with_input(JSON.generate({}))
23
+ assert $?.exitstatus == 0 && output =~ /Value:\sbar/
24
+ end
25
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.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-11-19 00:00:00 -08:00
19
+ date: 2014-05-02 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -95,6 +95,7 @@ files:
95
95
  - lib/sensu-plugin/utils.rb
96
96
  - lib/sensu-plugin.rb
97
97
  - test/external_check_test.rb
98
+ - test/external_handler_argument_test.rb
98
99
  - test/external_handler_test.rb
99
100
  - test/external_metric_test.rb
100
101
  - test/handle_filter_test.rb
@@ -135,6 +136,7 @@ specification_version: 3
135
136
  summary: Sensu Plugins
136
137
  test_files:
137
138
  - test/external_check_test.rb
139
+ - test/external_handler_argument_test.rb
138
140
  - test/external_handler_test.rb
139
141
  - test/external_metric_test.rb
140
142
  - test/handle_filter_test.rb