Sha256: 05183720de52dad00fe9f5aa403b5161aca1f881b68adce584cfdcdcf60c00e4

Contents?: true

Size: 1.6 KB

Versions: 51

Compression:

Stored size: 1.6 KB

Contents

class Riemann::Babbler::Plugin::Mdadm < Riemann::Babbler::Plugin

  def init
    plugin.set_default(:service, 'mdadm')
    plugin.set_default(:interval, 60)
    plugin.states.set_default(:critical, 1)
  end

  def run_plugin
    File.exists? '/proc/mdstat'
  end

  def rm_bracket(text)
    text.gsub('[', '').gsub(']', '')
  end

  def mdadm_status_well?(text)
    text.gsub(/U/, '').empty?
  end

  def collect
    file   = File.read('/proc/mdstat').split("\n")
    status = Array.new
    file.each_with_index do |line, index|
      next unless line.include?('blocks')

      device = file[index-1].split(':')[0].strip

      mdstatus = rm_bracket(line.split(' ').last) # UUU
      next if mdadm_status_well?(mdstatus)        # пропускаем все збс
      if mdstatus == plugin.states.send(device).to_s # пропускаем если стейт зафикисирован в конфиге
        status << { :service => plugin.service + " #{device}", :metric => 1, :state => 'ok', :description => "mdadm failed device #{device}, but disabled in config" }
        next
      end

      status << { :service => plugin.service + " #{device}", :metric => 1, :description => "mdadm failed device #{device}: #{get_failed_parts(device)}" }
    end
    status
  end

  def get_failed_parts (device)
    begin
      failed_parts = []
      Dir["/sys/block/#{device}/md/dev-*"].each do |p|
        state = File.read("#{p}/state").strip
        next unless state != 'in_sync'
        p.gsub!(/.+\/dev-/, '')
        failed_parts << "#{p} (#{state})"
      end
      failed_parts.join(', ')
    rescue
      nil
    end
  end

end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
riemann-babbler-2.0.0pre11 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre10 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre9 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre8 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre7 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre6 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre5 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre4 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre3 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre2 lib/riemann/babbler/plugins/mdadm.rb
riemann-babbler-2.0.0pre1 lib/riemann/babbler/plugins/mdadm.rb