Advertisement
trishoar

check_nf_conntrack.rb

Sep 11th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.62 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. #TH v0.1 10/09/2014
  3. #check nf_contrack_table usage script
  4.  
  5. require 'rubygems'
  6. require 'snmp'
  7.  
  8. class SNMP_check
  9.    attr_reader :responce
  10.  
  11.   def initialize (host, community, crit, warn)
  12.     @host = host
  13.     @community = community
  14.     @crit = crit.to_f
  15.     @warn = warn.to_f
  16.   end
  17.  
  18.   def poll
  19.     begin
  20.       SNMP::Manager.open(:host => @host, :Community => @community) do |pollServer|
  21.         (nf_max, nf_count) = \
  22.         pollServer.get_value ["1.3.6.1.4.1.8072.1.3.2.3.1.1.16.110.102.95.99.111.110.110.116.114.97.99.107.95.109.97.120",
  23.                               "1.3.6.1.4.1.8072.1.3.2.3.1.1.18.110.102.95.99.111.110.110.116.114.97.99.107.95.99.111.117.110.116"]
  24.         @responce = (nf_count.to_f/nf_max.to_f) * 100
  25.       end
  26.     rescue
  27.       print("SNMP problem. No data received from host.\n")
  28.       exit 3
  29.     end
  30.   end
  31.  
  32.   def check
  33.     if @responce > @crit
  34.       printf("Contrack Critical - " "%.02f", "#@responce")
  35.       print "%\n"
  36.       exit 2
  37.     elsif @responce < @crit and @responce > @warn
  38.       printf("Contrack Warning - " "%.02f", "#@responce")
  39.       print "%\n"
  40.       exit 1
  41.     else
  42.       printf("Contrack Ok - " "%.02f", "#@responce")
  43.       print "%\n"
  44.       exit 0
  45.     end
  46.   end
  47.  
  48. end
  49.  
  50. host = ARGV[0]
  51. community = ARGV[1]
  52. warn = ARGV[2].to_i
  53. crit = ARGV[3].to_i
  54.  
  55. if ARGV.length < 1
  56. puts "Usage: host community warn critical"
  57. elsif crit <= warn
  58.   puts "Warning must be less than critical"
  59.   exit 3
  60. elsif
  61.   crit > 100
  62.   puts "Critical should be less than 100%"
  63. else
  64.   server = SNMP_check.new(host, community, crit, warn)
  65.   server.poll
  66.   server.check
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement