Sha256: 2d9ed751f61efbd7b8cfb2a6d627f8354984cf1da6fd857430b63460cbe0fa2e

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

#!/usr/bin/env ruby -w

begin
  require 'nagiosplugin'
rescue LoadError
  require 'rubygems'
  require 'nagiosplugin'
end


class ZFS < NagiosPlugin::Plugin
  # Check the ZFS status (required method by nagiosplugin)
  def check
    critical(output) if !pools(:faulted).empty?
    warning(output) if !pools(:degraded).empty?
    ok(output) if pools(:online).count == pools.count
  end

  # @return [String] the summarized check result
  def output
    s = []
    [:faulted, :degraded, :online].each do |health|
      s << "#{pools(health).count} #{health.to_s.upcase}" unless pools(health).empty?
    end
    s.join(", ")
  end

  private

  def pools(health = nil)
    (health && health_by_pool.select { |p,h| h == health.to_s.upcase } ) || health_by_pool
  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 zpools
    out = `zpool list -H -o name,health 2>&1`
    raise out unless $?.success?
    out.split("\n")
  end
end


ZFS.run

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
check_zfs-0.2.1 bin/check_zfs
check_zfs-0.2.0 bin/check_zfs