nagios-zfs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
@@ -0,0 +1 @@
1
+ 1.9.3-p385
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nagios-zfs.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'cucumber' do
5
+ watch(%r{^bin/.+$})
6
+ watch(%r{^features/.+\.feature$})
7
+ watch(%r{^features/support/.+$}) { 'features' }
8
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
9
+ end
10
+
11
+ guard :rspec do
12
+ watch(%r{^spec/.+_spec\.rb$})
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
14
+ watch('lib/nagios/zfs.rb') { "spec" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Björn Albers
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Nagios-ZFS
2
+
3
+ Check ZFS Zpool health and capacity via Nagios.
4
+
5
+ **NOTE: This is an early prototype!**
6
+
7
+ ## Installation
8
+
9
+ Install it via RubyGems:
10
+
11
+ $ gem install nagios-zfs
12
+
13
+ ## Usage
14
+
15
+ Nagios-ZFS provices ships with a binary to check the status of your ZFS
16
+ Zpools.
17
+
18
+ $ check_zpool --help
19
+
20
+ A Zpool is in a critical state if the pool capacity jumps over a certain
21
+ rate (performance usually starts to suck near 80%) or when the pool is
22
+ faulted.
23
+ The status will be warning if your Zpool is degraded (not implemented
24
+ yet!) or if the capacity breaks your warning threshold.
25
+ Take a look at the features...
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
34
+
35
+ ## Copyright
36
+
37
+ Copyright (c) 2013 Björn Albers
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nagios/zfs'
4
+
5
+ Nagios::ZFS::ZpoolPlugin.new.check!
@@ -0,0 +1,27 @@
1
+ Feature: Check zpool capacity
2
+
3
+ In order to sleep well
4
+ As the "data storage guy"
5
+ I want to check the used capacity of my ZFS storage pools.
6
+
7
+ Background:
8
+ Given the zpool "tank" has a capacity of 80%
9
+
10
+ Scenario: Critical threshold reached
11
+ When I run `check_zpool -p tank -w 79 -c 80`
12
+ Then the status should be critical
13
+
14
+ Scenario: Warning threshold reached
15
+ When I run `check_zpool -p tank -w 80 -c 81`
16
+ Then the status should be warning
17
+
18
+ Scenario: Capacity below thresholds
19
+ When I run `check_zpool -p tank -w 81 -c 82`
20
+ Then the status should be ok
21
+
22
+ #NOTE: This currently does not work!
23
+ #Scenario: Unknown zpool name
24
+ #When I run `check_zpool -p foo -w 81 -c 82`
25
+ #Then the status should be unknown
26
+ #And the stdout should contain "unknown zpool foo"
27
+
@@ -0,0 +1,19 @@
1
+ Given(/^the zpool "(.*?)" has a capacity of (\d+)%$/) do |name, capacity|
2
+ cmd = "zpool list -H -o name,cap #{name}"
3
+ out = "#{name}\t#{capacity}%\n"
4
+ double_cmd(cmd, :puts => out)
5
+ end
6
+
7
+ Then(/^the status should be (unknown|critical|warning|ok)$/) do |status|
8
+ exit_status =
9
+ case status
10
+ when 'unknown' then 3
11
+ when 'critical' then 2
12
+ when 'warning' then 1
13
+ when 'ok' then 0
14
+ end
15
+ steps %Q(
16
+ Then the exit status should be #{exit_status}
17
+ And the stdout should contain "#{status.upcase}"
18
+ )
19
+ end
@@ -0,0 +1,2 @@
1
+ require 'aruba/cucumber'
2
+ require 'aruba-doubles/cucumber'
@@ -0,0 +1,5 @@
1
+ require 'nagiosplugin'
2
+ require 'mixlib/cli'
3
+ require 'nagios/zfs/version'
4
+ require 'nagios/zfs/zpool'
5
+ require 'nagios/zfs/zpool_plugin'
@@ -0,0 +1,5 @@
1
+ module Nagios
2
+ module ZFS
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Nagios
2
+ module ZFS
3
+ class Zpool
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ def capacity
9
+ query.split("\t").last[/^(\d+)/,1].to_i
10
+ end
11
+
12
+ def query
13
+ @query ||= `zpool list -H -o name,cap #{@name}`
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ module Nagios
2
+ module ZFS
3
+ class ZpoolPlugin < NagiosPlugin::Plugin
4
+ include Mixlib::CLI
5
+
6
+ option :zpool,
7
+ :short => '-p ZPOOL_NAME',
8
+ :long => '--pool ZPOOL_NAME'
9
+
10
+ option :critical,
11
+ :short => '-c CRITICAL_CAPACITY',
12
+ :short => '--critical CRITICAL_CAPACITY',
13
+ :proc => Proc.new { |config| config.to_i }
14
+
15
+ option :warning,
16
+ :short => '-w WARNING_CAPACITY',
17
+ :long => '--warning WARNING_CAPACITY',
18
+ :proc => Proc.new { |config| config.to_i }
19
+
20
+ def initialize
21
+ super
22
+ parse_options(argv)
23
+ end
24
+
25
+ def critical?
26
+ critical_capacity?
27
+ end
28
+
29
+ def warning?
30
+ warning_capacity?
31
+ end
32
+
33
+ # No explicite ok check.
34
+ def ok?
35
+ true
36
+ end
37
+
38
+ private
39
+
40
+ def critical_capacity?
41
+ zpool.capacity >= config[:critical]
42
+ end
43
+
44
+ def warning_capacity?
45
+ zpool.capacity >= config[:warning]
46
+ end
47
+
48
+ def zpool
49
+ @zpool ||= Zpool.new(config[:zpool])
50
+ end
51
+
52
+ # Array of command-line arguments
53
+ #
54
+ # This is only used for stubbing ARGV during tests which isn't so
55
+ # easy with mixlib-cli.
56
+ def argv
57
+ ARGV
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nagios/zfs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'nagios-zfs'
8
+ spec.version = Nagios::ZFS::VERSION
9
+ spec.authors = ['Björn Albers']
10
+ spec.email = ['bjoernalbers@googlemail.com']
11
+ spec.description = 'Check ZFS Zpool health and capacity via Nagios.'
12
+ spec.summary = "#{spec.name}-#{spec.version}"
13
+ spec.homepage = 'https://github.com/bjoernalbers/nagios-zfs'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'nagiosplugin', '~> 2.0'
22
+ spec.add_dependency 'mixlib-cli', '~> 1.3'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'guard-cucumber'
27
+ spec.add_development_dependency 'guard-rspec'
28
+ spec.add_development_dependency 'aruba'
29
+ spec.add_development_dependency 'aruba-doubles'
30
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ module Nagios
4
+ module ZFS
5
+ describe ZpoolPlugin do
6
+ let(:plugin) { ZpoolPlugin.new }
7
+ let(:argv) { [] }
8
+
9
+ before do
10
+ ZpoolPlugin.any_instance.stub(:argv).and_return(argv)
11
+ end
12
+
13
+ describe '#critical?' do
14
+ it 'returns true when capacity is critical' do
15
+ plugin.should_receive(:critical_capacity?).and_return(true)
16
+ expect(plugin.critical?).to be(true)
17
+ end
18
+
19
+ it 'returns false when capacity is not critical' do
20
+ plugin.should_receive(:critical_capacity?).and_return(false)
21
+ expect(plugin.critical?).to be(false)
22
+ end
23
+ end
24
+
25
+ describe '#critical_capacity?' do
26
+ let(:zpool) { double('zpool') }
27
+
28
+ before do
29
+ plugin.stub(:zpool).and_return(zpool)
30
+ plugin.stub(:config).and_return({:critical => 80})
31
+ end
32
+
33
+ it 'returns true when capacity exceeds critical threshold' do
34
+ zpool.should_receive(:capacity).and_return(80)
35
+ expect(plugin.send(:critical_capacity?)).to be(true)
36
+ end
37
+
38
+ it 'returns false when capacity does not exceed critical threshold' do
39
+ zpool.should_receive(:capacity).and_return(79)
40
+ expect(plugin.send(:critical_capacity?)).to be(false)
41
+ end
42
+ end
43
+
44
+ describe '#warning?' do
45
+ it 'returns true when capacity is warning' do
46
+ plugin.should_receive(:warning_capacity?).and_return(true)
47
+ expect(plugin.warning?).to be(true)
48
+ end
49
+
50
+ it 'returns false when capacity is not warning' do
51
+ plugin.should_receive(:warning_capacity?).and_return(false)
52
+ expect(plugin.warning?).to be(false)
53
+ end
54
+ end
55
+
56
+ describe '#warning_capacity?' do
57
+ let(:zpool) { double('zpool') }
58
+
59
+ before do
60
+ plugin.stub(:zpool).and_return(zpool)
61
+ plugin.stub(:config).and_return({:warning => 80})
62
+ end
63
+
64
+ it 'returns true when capacity exceeds warning threshold' do
65
+ zpool.should_receive(:capacity).and_return(80)
66
+ expect(plugin.send(:warning_capacity?)).to be(true)
67
+ end
68
+
69
+ it 'returns false when capacity does not exceed warning threshold' do
70
+ zpool.should_receive(:capacity).and_return(79)
71
+ expect(plugin.send(:warning_capacity?)).to be(false)
72
+ end
73
+ end
74
+
75
+ describe '#ok?' do
76
+ it 'always returns true' do
77
+ expect(plugin.ok?).to eq(true)
78
+ end
79
+ end
80
+
81
+ describe '#zpool' do
82
+ let(:zpool) { double('zpool') }
83
+
84
+ before do
85
+ plugin.stub(:config).and_return({:zpool => 'tank'})
86
+ end
87
+
88
+ it 'returns and caches the zpool' do
89
+ Zpool.should_receive(:new).with('tank').once.and_return(zpool)
90
+ expect(plugin.send(:zpool)).to eq(zpool)
91
+ expect(plugin.send(:zpool)).to eq(zpool)
92
+ end
93
+ end
94
+
95
+ describe '#config' do
96
+ %w(-p --pool).each do |opt|
97
+ name = 'tank'
98
+ context "with #{opt} #{name}" do
99
+ let(:argv) { [opt, name] }
100
+
101
+ it { expect(plugin.config[:zpool]).to eq(name) }
102
+ end
103
+ end
104
+
105
+ %w(-c --critical).each do |opt|
106
+ threshold = 42
107
+ context "with #{opt} #{threshold}" do
108
+ let(:argv) { [opt, threshold.to_s] }
109
+
110
+ it { expect(plugin.config[:critical]).to eq(threshold) }
111
+ end
112
+ end
113
+
114
+ %w(-w --warning).each do |opt|
115
+ threshold = 42
116
+ context "with #{opt} #{threshold}" do
117
+ let(:argv) { [opt, threshold.to_s] }
118
+
119
+ it { expect(plugin.config[:warning]).to eq(threshold) }
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Nagios
4
+ module ZFS
5
+ describe Zpool do
6
+ let(:zpool) { Zpool.new('tank') }
7
+
8
+ before do
9
+ Zpool.any_instance.stub(:`).and_return('')
10
+ end
11
+
12
+ describe '#capacity' do
13
+ it 'returns the capacity' do
14
+ zpool.should_receive(:query).and_return("tank\t87%\n")
15
+ expect(zpool.capacity).to eq(87)
16
+ end
17
+ end
18
+
19
+ describe '#query' do
20
+ it 'runs and caches the zpool query for the given pool' do
21
+ zpool.should_receive(:`).with('zpool list -H -o name,cap tank').
22
+ once.and_return('chunky bacon')
23
+ 2.times { expect(zpool.send(:query)).to eq('chunky bacon') }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ require 'nagios/zfs'
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nagios-zfs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Björn Albers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nagiosplugin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mixlib-cli
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-cucumber
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: aruba
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: aruba-doubles
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Check ZFS Zpool health and capacity via Nagios.
143
+ email:
144
+ - bjoernalbers@googlemail.com
145
+ executables:
146
+ - check_zpool
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .rbenv-version
152
+ - .rspec
153
+ - Gemfile
154
+ - Guardfile
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - bin/check_zpool
159
+ - features/check_zpool_capacity.feature
160
+ - features/step_definitions/dev_steps.rb
161
+ - features/support/env.rb
162
+ - lib/nagios/zfs.rb
163
+ - lib/nagios/zfs/version.rb
164
+ - lib/nagios/zfs/zpool.rb
165
+ - lib/nagios/zfs/zpool_plugin.rb
166
+ - nagios-zfs.gemspec
167
+ - spec/nagios/zfs/zpool_plugin_spec.rb
168
+ - spec/nagios/zfs/zpool_spec.rb
169
+ - spec/spec_helper.rb
170
+ homepage: https://github.com/bjoernalbers/nagios-zfs
171
+ licenses:
172
+ - MIT
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ segments:
184
+ - 0
185
+ hash: -4547917835531828401
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ segments:
193
+ - 0
194
+ hash: -4547917835531828401
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 1.8.23
198
+ signing_key:
199
+ specification_version: 3
200
+ summary: nagios-zfs-0.0.1
201
+ test_files:
202
+ - features/check_zpool_capacity.feature
203
+ - features/step_definitions/dev_steps.rb
204
+ - features/support/env.rb
205
+ - spec/nagios/zfs/zpool_plugin_spec.rb
206
+ - spec/nagios/zfs/zpool_spec.rb
207
+ - spec/spec_helper.rb