Sha256: a01e938becbe1a89b734a8ead13f50becffa91df76ce62cc4d706ee650bee539

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

#!/usr/bin/env ruby -w
require 'nagios-probe'

class CheckZFS < Nagios::Probe
  def health_by_pool
    @health_by_pool ||= `zpool list -H -o name,health`.split("\n").inject({}) do |pools,line|
      name, health = line.split("\t")
      pools[name] = health
      pools
    end
  end
  
  def pools(health = nil)
    (health && health_by_pool.select { |p,h| h == health.to_s.upcase } ) || health_by_pool
  end
  
  def check_crit
    !pools(:faulted).empty?
  end

  def check_warn
    !pools(:degraded).empty?
  end

  def check_ok
    pools(:online).count == pools.count
  end

  def info
    s = []
    [:faulted, :degraded, :online].each do |health|
      s << "#{pools(health).count} #{health.to_s.upcase}" unless pools(health).empty?
    end
    s.join(", ")
  end
  
  alias :crit_message :info
  alias :warn_message :info
  alias :ok_message   :info
end

begin
  options = {} # Nagios::Probe constructor accepts a single optional param that is assigned to @opts
  probe = CheckZFS.new(options)
  probe.run
rescue Exception => e
  puts "Unknown: " + e
  exit Nagios::UNKNOWN
end

puts probe.message
exit probe.retval

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
check_zfs-0.0.2 bin/check_zfs
check_zfs-0.0.1 bin/check_zfs