Sha256: 66b0642814dc75518cd43a583bbd7ea9690bc5fff100367af2d6a79ba7c89494

Contents?: true

Size: 1006 Bytes

Versions: 9

Compression:

Stored size: 1006 Bytes

Contents

class Riemann::Babbler::Plugin::Iptables < Riemann::Babbler::Plugin

  def init
    plugin.set_default(:service, 'iptables')
    plugin.set_default(:rules_file, '/etc/network/iptables')
    plugin.set_default(:interval, 60)
  end

  def run_plugin
    File.exists? plugin.rules_file
  end

  def delete_counters(str)
    str.gsub(/\[\d+\:\d+\]/, '').strip
  end

  def collect

    current_rules = shell('iptables-save | grep -v "^#"').split("\n").map do |x|
      delete_counters(x)
    end.compact.join("\n")

    saved_rules = File.read(plugin.rules_file).split("\n").map do |x|
      x[0] == "#" ? nil : delete_counters(x) # delete counters and comments
    end.compact.join("\n")

    status =  current_rules == saved_rules ? 'ok' : 'critical'
    {
        :service => "#{plugin.service} #{plugin.rules_file}",
        :state => status, #  status 'ok' will be minimized
        :description => "#{plugin.service} rules different between file: #{plugin.rules_file} and iptables-save"
    }

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
riemann-babbler-2.1.3.1 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.3 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.2 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.1 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.0 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.0.9 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.0.8 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.0.7 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.0.6.1 lib/riemann/babbler/plugins/iptables.rb