Sha256: e5e769820122775ea2beec581a139325ed5cbe88d68a89cf99623caee11c795c

Contents?: true

Size: 1.02 KB

Versions: 20

Compression:

Stored size: 1.02 KB

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').split("\n").map do |x|
      x[0] == "#" ? nil : delete_counters(x) # delete counters and comments
    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

20 entries across 20 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.8.4 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.8.3 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.8.2 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.8.1 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.8.0 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.6.0 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.9 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.8 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.7 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.6 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.5 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.4 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.3 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.2 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.1 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.5.0 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.5 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.4 lib/riemann/babbler/plugins/iptables.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/plugins/iptables.rb