Sha256: 50239c2fa94d0cb1028b3be69a106db74fc31ac210e0930b489fd35aca6b1819

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

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

class CheckZFS < Nagios::Probe
  def zpools
    output = `zpool list -H -o name,health 2>&1`
    raise output unless $?.success?
    output.split("\n")
  end
  
  def health_by_pool
    @health_by_pool ||= zpools.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

1 entries across 1 versions & 1 rubygems

Version Path
check_zfs-0.0.3 bin/check_zfs