nagios_check 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -64,6 +64,16 @@ If the value returned by `do_some_check` is between 0 and 4 inclusive the result
64
64
 
65
65
  If the check method lasts more than 10 seconds, it times out and the returned value is UNKNOWN.
66
66
 
67
+ An alternative shorter way of writting the above check would be:
68
+
69
+ ```ruby
70
+ def check
71
+ time(value_name: 'duration' do
72
+ do_some_check(options.host, options.port)
73
+ end
74
+ end
75
+ ```
76
+
67
77
  License
68
78
  -------
69
79
  Released under the MIT License. See the [MIT-LICENSE][license] file for further details.
@@ -0,0 +1,14 @@
1
+ require 'benchmark'
2
+
3
+ module NagiosCheck
4
+ module Chronometer
5
+ def time(opts = {}, &block)
6
+ raise ArgumentError, "block is mandatory for method time" if block.nil?
7
+ time = Benchmark.realtime { block.call }
8
+ if opts[:value_name]
9
+ store_value(opts[:value_name], time)
10
+ end
11
+ time
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module NagiosCheck
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/nagios_check.rb CHANGED
@@ -4,8 +4,11 @@ require 'ostruct'
4
4
  require 'timeout'
5
5
 
6
6
  require 'nagios_check/range'
7
+ require 'nagios_check/chronometer'
7
8
 
8
9
  module NagiosCheck
10
+ include Chronometer
11
+
9
12
  attr_reader :options
10
13
  attr_accessor :message
11
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -57,6 +57,7 @@ files:
57
57
  - README.md
58
58
  - Rakefile
59
59
  - lib/nagios_check.rb
60
+ - lib/nagios_check/chronometer.rb
60
61
  - lib/nagios_check/range.rb
61
62
  - lib/nagios_check/version.rb
62
63
  - nagios_check.gemspec