check_zfs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in check_zfs.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Björn Albers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # check_zfs
2
+
3
+ Monitor the health of your ZFS pools with Nagios
4
+
5
+ TODO: link to nagios, zfs and nagios-plugin guidelines
6
+
7
+ ## Installation
8
+
9
+ `gem install check_zfs`
10
+
11
+ ## Usage
12
+
13
+ `check_zfs`
14
+
15
+ TODO: Add config example for nagios!
16
+ TODO: Show command in action!
17
+
18
+ ## Caveats
19
+
20
+ TODO: Add note about tested platform(s)!
21
+
22
+ ## Note on Patches/Pull Requests
23
+
24
+ * Fork the project.
25
+ * Make your feature addition or bug fix.
26
+ * Add tests for it. This is important so I don't break it in a
27
+ future version unintentionally. Note: the existing tests may fail
28
+ * Commit, do not mess with Rakefile, gemspec or History.
29
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
30
+ * Send me a pull request. Bonus points for topic branches.
31
+
32
+ ## Copyright
33
+
34
+ Copyright (c) 2011 Björn Albers. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new(:features) do |t|
6
+ t.cucumber_opts = "--format pretty"
7
+ end
8
+
9
+ task :default => :features
data/bin/check_zfs ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby -w
2
+ require 'nagios-probe'
3
+
4
+ class CheckZFS < Nagios::Probe
5
+ def health_by_pool
6
+ @health_by_pool ||= `zpool list -H -o name,health`.split("\n").inject({}) do |pools,line|
7
+ name, health = line.split("\t")
8
+ pools[name] = health
9
+ pools
10
+ end
11
+ end
12
+
13
+ def pools(health = nil)
14
+ (health && health_by_pool.select { |p,h| h == health.to_s.upcase } ) || health_by_pool
15
+ end
16
+
17
+ def check_crit
18
+ !pools(:faulted).empty?
19
+ end
20
+
21
+ def check_warn
22
+ !pools(:degraded).empty?
23
+ end
24
+
25
+ def check_ok
26
+ pools(:online).count == pools.count
27
+ end
28
+
29
+ def info
30
+ s = []
31
+ [:faulted, :degraded, :online].each do |health|
32
+ s << "#{pools(health).count} #{health.to_s.upcase}" unless pools(health).empty?
33
+ end
34
+ s.join(", ")
35
+ end
36
+
37
+ alias :crit_message :info
38
+ alias :warn_message :info
39
+ alias :ok_message :info
40
+ end
41
+
42
+ begin
43
+ options = {} # Nagios::Probe constructor accepts a single optional param that is assigned to @opts
44
+ probe = CheckZFS.new(options)
45
+ probe.run
46
+ rescue Exception => e
47
+ puts "Unknown: " + e
48
+ exit Nagios::UNKNOWN
49
+ end
50
+
51
+ puts probe.message
52
+ exit probe.retval
data/check_zfs.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'check_zfs'
5
+ s.version = '0.0.1'
6
+ s.authors = ["Björn Albers"]
7
+ s.email = ["bjoernalbers@googlemail.com"]
8
+ s.description = 'Monitor the health of your ZFS pools with Nagios'
9
+ s.summary = "#{s.name}-#{s.version}"
10
+ s.homepage = 'https://github.com/bjoernalbers/check_zfs'
11
+
12
+ s.add_dependency 'nagios-probe', '>= 0.1.2'
13
+
14
+ s.add_development_dependency 'cucumber', '>= 1.0.2'
15
+ s.add_development_dependency 'aruba', '>= 0.4.6'
16
+ s.add_development_dependency 'aruba-doubles', '>= 0.0.2'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,26 @@
1
+ Feature: Check ZFS
2
+
3
+ In order to notified before it's to late
4
+ As an agile System-Administrator
5
+ I want the health of my ZFS pools monitored with Nagios by check_zfs
6
+
7
+ Scenario Outline: Exit status and stdout
8
+ Given a double of "zpool" with stdout:
9
+ """
10
+ rpool <rpool>
11
+ tank <tank>
12
+ tank2 <tank2>
13
+ """
14
+ When I run `check_zfs`
15
+ Then the exit status should be <exit>
16
+ And the stdout should contain exactly:
17
+ """
18
+ <stdout>
19
+
20
+ """
21
+
22
+ Examples:
23
+ | rpool | tank | tank2 | exit | stdout |
24
+ | ONLINE | ONLINE | ONLINE | 0 | OK: 3 ONLINE |
25
+ | ONLINE | DEGRADED | ONLINE | 1 | Warning: 1 DEGRADED, 2 ONLINE |
26
+ | ONLINE | DEGRADED | FAULTED | 2 | Critical: 1 FAULTED, 1 DEGRADED, 1 ONLINE |
@@ -0,0 +1,2 @@
1
+ require 'aruba/cucumber'
2
+ require 'aruba-doubles/cucumber'
data/lib/check_zfs.rb ADDED
@@ -0,0 +1 @@
1
+ # Load nothing - just keep the file here to keep bundler happy.
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_zfs
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Bj\xC3\xB6rn Albers"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nagios-probe
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 31
29
+ segments:
30
+ - 0
31
+ - 1
32
+ - 2
33
+ version: 0.1.2
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: cucumber
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 19
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 2
49
+ version: 1.0.2
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: aruba
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ - 4
64
+ - 6
65
+ version: 0.4.6
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: aruba-doubles
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 27
77
+ segments:
78
+ - 0
79
+ - 0
80
+ - 2
81
+ version: 0.0.2
82
+ type: :development
83
+ version_requirements: *id004
84
+ description: Monitor the health of your ZFS pools with Nagios
85
+ email:
86
+ - bjoernalbers@googlemail.com
87
+ executables:
88
+ - check_zfs
89
+ extensions: []
90
+
91
+ extra_rdoc_files: []
92
+
93
+ files:
94
+ - .gitignore
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - bin/check_zfs
100
+ - check_zfs.gemspec
101
+ - features/check_zfs.feature
102
+ - features/support/env.rb
103
+ - lib/check_zfs.rb
104
+ homepage: https://github.com/bjoernalbers/check_zfs
105
+ licenses: []
106
+
107
+ post_install_message:
108
+ rdoc_options: []
109
+
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.8
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: check_zfs-0.0.1
137
+ test_files:
138
+ - features/check_zfs.feature
139
+ - features/support/env.rb