Sha256: 5a98d08b2e499654ca2025835a4630f9fee3c401cd10438df0ae2deadd9656e3

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

#
#   check-netfilter-conntrack
#
# DESCRIPTION:
#   Check netfilter connection tracking table condition
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#   $ ./check-netfilter-conntrack.rb --warning 60 --critical 90
#
# NOTES:
#   - If you need to check the conntrack table of a specific linux
#     network namespace (e.g in a docker context), run this check as
#     `nsenter --net=<file> check-netfilter-conntrack.rb` to use the
#     network namespace which `<file>`'s descriptor indicates.
#
# LICENSE:
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'

#
# Check Netfilter connection tracking table condition
#
class CheckNetfilterConntrack < Sensu::Plugin::Check::CLI
  option :warning,
         description: 'Warn if conntrack table is filled more than PERC%',
         short: '-w PERC',
         long: '--warning PERC',
         default: 80,
         proc: proc(&:to_i)

  option :critical,
         description: 'Critical if conntrack table is filled more than PERC%',
         short: '-c PERC',
         long: '--critical PERC',
         default: 90,
         proc: proc(&:to_i)

  def nf_conntrack_max
    File.read('/proc/sys/net/netfilter/nf_conntrack_max').to_i
  end

  def nf_conntrack_count
    File.read('/proc/sys/net/netfilter/nf_conntrack_count').to_i
  end

  def run
    max = nf_conntrack_max
    count = nf_conntrack_count
    percentage = (count.to_f / max.to_f) * 100

    message "Table is at #{percentage.round(1)}% (#{count}/#{max})"

    critical if percentage >= config[:critical]
    warning if percentage >= config[:warning]
    ok
  rescue StandardError
    warning "Can't read conntrack information."
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sensu-plugins-network-checks-4.1.1 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-4.1.0 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-4.0.0 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-3.2.1 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-3.2.0 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-3.1.2 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-3.1.1 bin/check-netfilter-conntrack.rb
sensu-plugins-network-checks-3.1.0 bin/check-netfilter-conntrack.rb