nagiosplugin 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,18 @@
1
1
  module NagiosPlugin
2
2
  class Plugin
3
- # All allowed statuses sorted by their corresponding exit status.
4
- STATUS = [:ok, :warning, :critical, :unknown]
5
3
 
6
4
  # A custom status error which will be raised through the status methods.
7
5
  class StatusError < StandardError
8
- # @param [Symbol] status the status (must be {NagiosPlugin::Plugin::STATUS a valid status})
6
+
7
+ # All allowed statuses sorted by their corresponding exit status.
8
+ STATUS = [:ok, :warning, :critical, :unknown]
9
+
10
+ # @param [Symbol] status the status (must be {NagiosPlugin::Plugin::StatusError::STATUS a valid status})
9
11
  # @param [String] message the message you want to display
10
12
  def initialize(status, message)
11
13
  @status, @message = status.to_sym, message
12
14
  end
13
15
 
14
- # @return [Symbol] the status
15
- def status
16
- (STATUS.include?(@status) && @status) || STATUS.last
17
- end
18
-
19
16
  # @return [String] the status and message
20
17
  def to_s
21
18
  "#{status.to_s.upcase}: #{@message}"
@@ -25,28 +22,42 @@ module NagiosPlugin
25
22
  def to_i
26
23
  STATUS.find_index(status)
27
24
  end
25
+
26
+ private
27
+
28
+ # @return [Symbol] the status (:unknown if invalid)
29
+ def status
30
+ (STATUS.include?(@status) && @status) || STATUS.last
31
+ end
28
32
  end
29
33
 
30
34
  class << self
35
+
31
36
  # Create new instance and run it.
32
37
  def run(*args)
33
38
  self.new(*args).run
34
39
  end
35
- end
36
40
 
37
- # The methods for each status.
38
- #
39
- # They should be called in your check method and will raise an appropriate
40
- # StatusError.
41
- #
42
- # @param [String] message
43
- STATUS.each do |status|
44
- define_method(status) do |message|
45
- raise StatusError.new(status, message)
41
+ private
42
+
43
+ # @macro [status] message
44
+ # @method $1(message)
45
+ # Raise $1 StatusError with message
46
+ # @scope class
47
+ # @param [String] message the exeption message
48
+ def make(status)
49
+ define_method(status) do |message|
50
+ raise StatusError.new(status, message)
51
+ end
46
52
  end
47
53
  end
48
54
 
49
- # Overwrite this check method and call a status method within!
55
+ make :ok
56
+ make :warning
57
+ make :critical
58
+ make :unknown
59
+
60
+ # Overwrite this check method and call a status method within.
50
61
  def check
51
62
  unknown 'please overwrite the method `check` in your class'
52
63
  end
@@ -1,3 +1,3 @@
1
1
  module NagiosPlugin
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagiosplugin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Bj\xC3\xB6rn Albers"
@@ -158,7 +158,7 @@ rubyforge_project:
158
158
  rubygems_version: 1.8.11
159
159
  signing_key:
160
160
  specification_version: 3
161
- summary: nagiosplugin-1.0.1
161
+ summary: nagiosplugin-1.0.2
162
162
  test_files:
163
163
  - features/plugin_output.feature
164
164
  - features/steps/dev_steps.rb