nagios-zfs 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
@@ -2,8 +2,6 @@
2
2
 
3
3
  Check ZFS Zpool health and capacity via Nagios.
4
4
 
5
- **NOTE: This is an early prototype!**
6
-
7
5
  ## Installation
8
6
 
9
7
  Install it via RubyGems:
@@ -18,11 +16,16 @@ Zpools.
18
16
  $ check_zpool --help
19
17
 
20
18
  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
19
+ rate (performance usually starts to suck at 80%) or when the pool is
22
20
  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...
21
+ The status will be warning if your Zpool is degraded or if the capacity
22
+ breaks your warning threshold.
23
+ Take a look at the
24
+ [features](https://github.com/bjoernalbers/nagios-zfs/tree/master/features)
25
+ ...
26
+
27
+ This plugin works successfully under Oracle Solaris 11 (ZFS VERSION:
28
+ 11.11,REV=2009.11.11).
26
29
 
27
30
  ## Contributing
28
31
 
@@ -20,8 +20,8 @@ Feature: Check zpool capacity
20
20
  Then the status should be ok
21
21
 
22
22
  Scenario: Display actual capacity
23
- When I run `check_zpool -p tank -w 79 -c 80`
24
- Then the stdout should contain "tank 80%"
23
+ When I run `check_zpool -p tank -w 81 -c 82`
24
+ Then the stdout should contain "80%"
25
25
 
26
26
  #NOTE: This currently does not work!
27
27
  #Scenario: Unknown zpool name
@@ -0,0 +1,19 @@
1
+ Feature: Check zpool health
2
+
3
+ In order to sleep well
4
+ As the "data storage guy"
5
+ I want to check the health of my ZFS storage pools.
6
+
7
+ Scenario Outline:
8
+ Given the zpool "tank" has a capacity of 80%
9
+ And the health from zpool "tank" is "<health>"
10
+ When I run `check_zpool -p tank -w 81 -c 82`
11
+ Then the status should be <status>
12
+ And the stdout should contain "<health>"
13
+
14
+ Examples:
15
+ | health | status |
16
+ | FAULTED | critical |
17
+ | DEGRADED | warning |
18
+ | ONLINE | ok |
19
+ | SICK | unknown |
@@ -1,9 +1,18 @@
1
+ Before do
2
+ @aruba_timeout_seconds = 10
3
+ end
4
+
1
5
  Given(/^the zpool "(.*?)" has a capacity of (\d+)%$/) do |name, capacity|
2
6
  cmd = "zpool list -H -o name,cap #{name}"
3
7
  out = "#{name}\t#{capacity}%\n"
4
8
  double_cmd(cmd, :puts => out)
5
9
  end
6
10
 
11
+ Given(/^the health from zpool "(.*?)" is "(.*?)"$/) do |name, health|
12
+ cmd = "zpool list -H -o health #{name}"
13
+ double_cmd(cmd, :puts => "#{health}\n")
14
+ end
15
+
7
16
  Then(/^the status should be (unknown|critical|warning|ok)$/) do |status|
8
17
  exit_status =
9
18
  case status
@@ -1,5 +1,5 @@
1
1
  module Nagios
2
2
  module ZFS
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -1,6 +1,8 @@
1
1
  module Nagios
2
2
  module ZFS
3
3
  class Zpool
4
+ KNOWN_POOL_HEALTHS = %(ONLINE DEGRADED FAULTED)
5
+
4
6
  attr_reader :name
5
7
 
6
8
  def initialize(name)
@@ -13,7 +15,14 @@ module Nagios
13
15
  end
14
16
 
15
17
  def query
16
- @query ||= `zpool list -H -o name,cap #{@name}`
18
+ @query ||= `zpool list -H -o name,cap #{name}`
19
+ end
20
+
21
+ def health
22
+ @health ||= `zpool list -H -o health #{name}`.strip
23
+ raise "unknown health: #{@health}" unless
24
+ KNOWN_POOL_HEALTHS.include?(@health)
25
+ @health
17
26
  end
18
27
  end
19
28
  end
@@ -24,11 +24,11 @@ module Nagios
24
24
  end
25
25
 
26
26
  def critical?
27
- critical_capacity?
27
+ critical_capacity? || critical_health?
28
28
  end
29
29
 
30
30
  def warning?
31
- warning_capacity?
31
+ warning_capacity? || warning_health?
32
32
  end
33
33
 
34
34
  # No explicite ok check.
@@ -37,7 +37,7 @@ module Nagios
37
37
  end
38
38
 
39
39
  def message
40
- "#{zpool.name} #{zpool.capacity}%"
40
+ "#{zpool.name} #{zpool.health} (#{zpool.capacity}%)"
41
41
  end
42
42
 
43
43
  private
@@ -50,6 +50,14 @@ module Nagios
50
50
  zpool.capacity >= config[:warning]
51
51
  end
52
52
 
53
+ def critical_health?
54
+ zpool.health == 'FAULTED'
55
+ end
56
+
57
+ def warning_health?
58
+ zpool.health == 'DEGRADED'
59
+ end
60
+
53
61
  def zpool
54
62
  @zpool ||= Zpool.new(config[:zpool])
55
63
  end
@@ -14,20 +14,64 @@ module Nagios
14
14
  let(:argv) { [] }
15
15
 
16
16
  it 'raises an error without pool name' do
17
+ ZpoolPlugin.any_instance.stub(:puts) # Don't mess up our spec output.
17
18
  expect { plugin }.to raise_error(SystemExit)
18
19
  end
19
20
  end
20
21
 
21
22
  describe '#critical?' do
22
- it 'returns true when capacity is critical' do
23
+ before do
24
+ plugin.stub(:critical_capacity?).and_return(false)
25
+ plugin.stub(:critical_health?).and_return(false)
26
+ end
27
+
28
+ it 'is true when capacity is critical' do
23
29
  plugin.should_receive(:critical_capacity?).and_return(true)
24
30
  expect(plugin.critical?).to be(true)
25
31
  end
26
32
 
27
- it 'returns false when capacity is not critical' do
33
+ it 'is true when health is critical' do
34
+ plugin.should_receive(:critical_health?).and_return(true)
35
+ expect(plugin.critical?).to be(true)
36
+ end
37
+
38
+ it 'is false when capacity is not critical' do
28
39
  plugin.should_receive(:critical_capacity?).and_return(false)
29
40
  expect(plugin.critical?).to be(false)
30
41
  end
42
+
43
+ it 'is false when health is not critical' do
44
+ plugin.should_receive(:critical_health?).and_return(false)
45
+ expect(plugin.critical?).to be(false)
46
+ end
47
+
48
+ end
49
+
50
+ describe '#warning?' do
51
+ before do
52
+ plugin.stub(:warning_capacity?).and_return(false)
53
+ plugin.stub(:warning_health?).and_return(false)
54
+ end
55
+
56
+ it 'is true when capacity is warning' do
57
+ plugin.should_receive(:warning_capacity?).and_return(true)
58
+ expect(plugin.warning?).to be(true)
59
+ end
60
+
61
+ it 'is true when health is warning' do
62
+ plugin.should_receive(:warning_health?).and_return(true)
63
+ expect(plugin.warning?).to be(true)
64
+ end
65
+
66
+ it 'is false when capacity is not warning' do
67
+ plugin.should_receive(:warning_capacity?).and_return(false)
68
+ expect(plugin.warning?).to be(false)
69
+ end
70
+
71
+ it 'is false when health is not warning' do
72
+ plugin.should_receive(:warning_health?).and_return(false)
73
+ expect(plugin.warning?).to be(false)
74
+ end
31
75
  end
32
76
 
33
77
  describe '#critical_capacity?' do
@@ -38,29 +82,17 @@ module Nagios
38
82
  plugin.stub(:config).and_return({:critical => 80})
39
83
  end
40
84
 
41
- it 'returns true when capacity exceeds critical threshold' do
85
+ it 'is true when capacity exceeds critical threshold' do
42
86
  zpool.should_receive(:capacity).and_return(80)
43
87
  expect(plugin.send(:critical_capacity?)).to be(true)
44
88
  end
45
89
 
46
- it 'returns false when capacity does not exceed critical threshold' do
90
+ it 'is false when capacity does not exceed critical threshold' do
47
91
  zpool.should_receive(:capacity).and_return(79)
48
92
  expect(plugin.send(:critical_capacity?)).to be(false)
49
93
  end
50
94
  end
51
95
 
52
- describe '#warning?' do
53
- it 'returns true when capacity is warning' do
54
- plugin.should_receive(:warning_capacity?).and_return(true)
55
- expect(plugin.warning?).to be(true)
56
- end
57
-
58
- it 'returns false when capacity is not warning' do
59
- plugin.should_receive(:warning_capacity?).and_return(false)
60
- expect(plugin.warning?).to be(false)
61
- end
62
- end
63
-
64
96
  describe '#warning_capacity?' do
65
97
  let(:zpool) { double('zpool') }
66
98
 
@@ -69,17 +101,49 @@ module Nagios
69
101
  plugin.stub(:config).and_return({:warning => 80})
70
102
  end
71
103
 
72
- it 'returns true when capacity exceeds warning threshold' do
104
+ it 'is true when capacity exceeds warning threshold' do
73
105
  zpool.should_receive(:capacity).and_return(80)
74
106
  expect(plugin.send(:warning_capacity?)).to be(true)
75
107
  end
76
108
 
77
- it 'returns false when capacity does not exceed warning threshold' do
109
+ it 'is false when capacity does not exceed warning threshold' do
78
110
  zpool.should_receive(:capacity).and_return(79)
79
111
  expect(plugin.send(:warning_capacity?)).to be(false)
80
112
  end
81
113
  end
82
114
 
115
+ describe '#critical_health?' do
116
+ let(:zpool) { double('zpool') }
117
+
118
+ before { plugin.stub(:zpool).and_return(zpool) }
119
+
120
+ it 'is true with a faulted pool' do
121
+ zpool.should_receive(:health).and_return('FAULTED')
122
+ expect(plugin.send(:critical_health?)).to be(true)
123
+ end
124
+
125
+ it 'is false without a faulted pool' do
126
+ zpool.should_receive(:health).and_return('DEGRADED')
127
+ expect(plugin.send(:critical_health?)).to be(false)
128
+ end
129
+ end
130
+
131
+ describe '#warning_health?' do
132
+ let(:zpool) { double('zpool') }
133
+
134
+ before { plugin.stub(:zpool).and_return(zpool) }
135
+
136
+ it 'is true with a degraded pool' do
137
+ zpool.should_receive(:health).and_return('DEGRADED')
138
+ expect(plugin.send(:warning_health?)).to be(true)
139
+ end
140
+
141
+ it 'is false without a degraded pool' do
142
+ zpool.should_receive(:health).and_return('ONLINE')
143
+ expect(plugin.send(:warning_health?)).to be(false)
144
+ end
145
+ end
146
+
83
147
  describe '#ok?' do
84
148
  it 'always returns true' do
85
149
  expect(plugin.ok?).to eq(true)
@@ -87,12 +151,13 @@ module Nagios
87
151
  end
88
152
 
89
153
  describe '#message' do
90
- it 'includes the pool name and capcity' do
154
+ it 'includes the pool name, health and capcity' do
91
155
  zpool = double('zpool')
92
156
  zpool.should_receive(:name).and_return('tank')
157
+ zpool.should_receive(:health).and_return('ONLINE')
93
158
  zpool.should_receive(:capacity).and_return(42)
94
159
  plugin.stub(:zpool).and_return(zpool)
95
- expect(plugin.message).to eq('tank 42%')
160
+ expect(plugin.message).to eq('tank ONLINE (42%)')
96
161
  end
97
162
  end
98
163
 
@@ -35,6 +35,21 @@ module Nagios
35
35
  2.times { expect(zpool.send(:query)).to eq('chunky bacon') }
36
36
  end
37
37
  end
38
+
39
+ describe '#health' do
40
+ it 'returns and caches the health by command-line' do
41
+ zpool.should_receive(:`).with('zpool list -H -o health tank').
42
+ once.and_return("ONLINE\n")
43
+ 2.times { expect(zpool.health).to eq('ONLINE') }
44
+ end
45
+
46
+ it 'raises an error with an unknown health' do
47
+ zpool.stub(:`).and_return("SICK\n")
48
+ expect { zpool.health }.to raise_error /unknown health: SICK/
49
+ end
50
+
51
+ it 'raises an error when the command returns a non-zero exit code'
52
+ end
38
53
  end
39
54
  end
40
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios-zfs
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:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-08 00:00:00.000000000 Z
12
+ date: 2013-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nagiosplugin
@@ -157,6 +157,7 @@ files:
157
157
  - Rakefile
158
158
  - bin/check_zpool
159
159
  - features/check_zpool_capacity.feature
160
+ - features/check_zpool_health.feature
160
161
  - features/step_definitions/dev_steps.rb
161
162
  - features/support/env.rb
162
163
  - lib/nagios/zfs.rb
@@ -182,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
183
  version: '0'
183
184
  segments:
184
185
  - 0
185
- hash: -2614810607798314703
186
+ hash: -1902865877853825615
186
187
  required_rubygems_version: !ruby/object:Gem::Requirement
187
188
  none: false
188
189
  requirements:
@@ -191,15 +192,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  segments:
193
194
  - 0
194
- hash: -2614810607798314703
195
+ hash: -1902865877853825615
195
196
  requirements: []
196
197
  rubyforge_project:
197
198
  rubygems_version: 1.8.23
198
199
  signing_key:
199
200
  specification_version: 3
200
- summary: nagios-zfs-0.1.1
201
+ summary: nagios-zfs-0.2.0
201
202
  test_files:
202
203
  - features/check_zpool_capacity.feature
204
+ - features/check_zpool_health.feature
203
205
  - features/step_definitions/dev_steps.rb
204
206
  - features/support/env.rb
205
207
  - spec/nagios/zfs/zpool_plugin_spec.rb