class Threshold::RateFilter

Attributes

apply_to[RW]
comment[RW]
count[RW]
gid[RW]
new_action[RW]
seconds[RW]
sid[RW]
timeout[RW]
track_by[RW]

Public Class Methods

new(line="") click to toggle source
# File lib/threshold/rate_filter.rb, line 106
def initialize(line="")
  transform(line) unless line.empty?
end

Public Instance Methods

state() click to toggle source

State does not track comments

# File lib/threshold/rate_filter.rb, line 132
def state
  [@gid, @sid, @track_by, @count, @seconds, @new_action, @timeout, @apply_to]
end
to_s(skip = false) click to toggle source
# File lib/threshold/rate_filter.rb, line 110
def to_s(skip = false)

  if self.valid?
    if apply_to == nil then
      if comment?(skip)
        "rate_filter gen_id #{@gid}, sig_id #{@sid}, track by_#{@track_by}, count #{@count}, seconds #{@seconds}, new_action #{@new_action}, timeout #{@timeout} #{@comment}"
      else
        "rate_filter gen_id #{@gid}, sig_id #{@sid}, track by_#{@track_by}, count #{@count}, seconds #{@seconds}, new_action #{@new_action}, timeout #{@timeout}"
      end
    else
      if comment?(skip)
        "rate_filter gen_id #{@gid}, sig_id #{@sid}, count #{@count}, seconds #{@seconds}, new_action #{@new_action}, timeout #{@timeout} apply_to #{@apply_to} #{@comment}"
      else
        "rate_filter gen_id #{@gid}, sig_id #{@sid}, count #{@count}, seconds #{@seconds}, new_action #{@new_action}, timeout #{@timeout} apply_to #{@apply_to}"
      end
    end
  else
    raise InvalidRateFilterObject, 'Rate Filter did not validate'
  end
end

Private Instance Methods

transform(result) click to toggle source
# File lib/threshold/rate_filter.rb, line 138
def transform(result)
  begin
    self.gid = result["GID"].compact.first.to_i
    self.sid = result["SID"].compact.first.to_i
    self.track_by = result["TRACK"].compact.first.split('_')[1]

    self.count = result["COUNT"].compact.first.to_i
    self.seconds = result["SECONDS"].compact.first.to_i
    self.timeout = result["TIMEOUT"].compact.first.to_i
    self.new_action = result["NEW_ACTION"].compact.first

    if result.key("IPCIDR")
      self.apply_to = result["IPCIDR"].compact.first
    end
    if result.key?("COMMENT")
      self.comment = result["COMMENT"].compact.first.strip
    end
    raise InvalidRateFilterObject unless self.valid?
  rescue
    raise InvalidRateFilterObject, 'Failed transformation from parser'
  end
end