class Threshold::Thresholds

Attributes

file[RW]
readonly[RW]

Public Class Methods

new(thresholds = []) click to toggle source
# File lib/threshold/thresholds.rb, line 17
def initialize(thresholds = [])
  @thresholds = thresholds
end

Public Instance Methods

&(an0ther) click to toggle source

& (union) Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 162
def &(an0ther)
  Thresholds.new(@thresholds & an0ther.to_a)
end
+(an0ther) click to toggle source

+ (concat) Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 151
def +(an0ther)
  Thresholds.new(@thresholds + an0ther.to_a)
end
-(an0ther) click to toggle source
  • (Difference)

Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 168
def -(an0ther)
  Thresholds.new(@thresholds - an0ther.to_a)
end
event_filters(&blk) click to toggle source

Returns a new Threshold Object with just event_filters

# File lib/threshold/thresholds.rb, line 182
def event_filters(&blk)
  if block_given?
    self.event_filters.select(&blk)
  else
    Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::EventFilter"})
  end
end
flush() click to toggle source

Write changes to the file

# File lib/threshold/thresholds.rb, line 22
def flush
  begin
    valid_existing_file?(@file)
    raise ReadOnlyThresholdsFile if @readonly
    hash = current_hash
    file = File.open(@file, 'w+')
    raise ThresholdAtomicLockFailure, 'The @file state/hash changed before we could flush the file' unless stored_hash == hash
    file.write self.sort.to_s
    file.close

  rescue NonExistantThresholdFile
    raise ReadOnlyThresholdsFile if @readonly
    file = File.open(@file, 'w')
    file.write self.sort.to_s
    file.close
  end

  stored_hash=current_hash
  return true
end
loadfile() click to toggle source

Append in the thresholds.conf file to current collection

# File lib/threshold/thresholds.rb, line 50
def loadfile
  valid_existing_file?(@file)

  results = Threshold::Parser.new(@file)
  @stored_hash= results.filehash
  #puts stored_hash
  results.caps.each do |result|
    builder = Threshold::Builder.new(result)
    self << builder.build
  end

end
loadfile!() click to toggle source

Clears current collection and Read in the thresholds.conf file

# File lib/threshold/thresholds.rb, line 44
def loadfile!
  @thresholds.clear
  loadfile
end
rate_filters(&blk) click to toggle source

Returns a new Threshold Object with just rate_filters

# File lib/threshold/thresholds.rb, line 191
def rate_filters(&blk)
  if block_given?
    self.rate_filters.select(&blk)
  else
    Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::RateFilter"})
  end
end
reject(&blk) click to toggle source

Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 119
def reject(&blk)
  if block_given?
    Thresholds.new(@thresholds.reject(&blk))
  else
    Thresholds.new(@thresholds.reject)
  end
end
reverse() click to toggle source

Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 109
def reverse
  Thresholds.new(@thresholds.reverse)
end
select(&blk) click to toggle source

Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 128
def select(&blk)
  if block_given?
    Thresholds.new(@thresholds.select(&blk))
  else
    Thresholds.new(@thresholds.select)
  end
end
shuffle() click to toggle source

Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 114
def shuffle
  Thresholds.new(@thresholds.shuffle)
end
sort() click to toggle source

Array(@thresholds) Creates a new Array on @threshold.sort so.. direct forwardable delegation fails. Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 104
def sort
  Thresholds.new(@thresholds.sort)
end
stored_hash() click to toggle source

The calculated hash of the threshold.conf file at load time.

# File lib/threshold/thresholds.rb, line 92
def stored_hash
  @stored_hash
end
suppressions(&blk) click to toggle source

Returns a new Threshold Object with just suppressions

# File lib/threshold/thresholds.rb, line 173
def suppressions(&blk)
  if block_given?
    self.suppressions.select(&blk)
  else
    Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::Suppression"})
  end
end
to_a() click to toggle source
# File lib/threshold/thresholds.rb, line 95
    def to_a
  @thresholds
end
to_s(skip = false) click to toggle source

Printer Pass (true) to_s to skip the printing of InternalObjects.comment

# File lib/threshold/thresholds.rb, line 80
def to_s(skip = false)
  output = ""

  raise InvalidThresholdsObject, "Container object has unknown objects" unless valid?

  self.each do |threshold|
    output << threshold.to_s(skip) + "\n"
  end
  return output
end
uniq(&blk) click to toggle source

Uniques by default to printable output

Returns a new Threshold Object
# File lib/threshold/thresholds.rb, line 138
def uniq(&blk)
  if block_given?
    Thresholds.new(@thresholds.uniq(&blk))
  else
    Thresholds.new(@thresholds.uniq{ |lineitem| lineitem.to_s(true) })
  end
end
valid?() click to toggle source

Check if all objects in the Threshold Instance report .valid?

# File lib/threshold/thresholds.rb, line 64
def valid?
  begin
    self.each do |threshold|
      if threshold.respond_to?(:valid?)
        return false unless threshold.valid?
      else
        raise InvalidThresholdsObject, "Container object has unknown objects"
      end
    end
    return true
  rescue InvalidThresholdsObject
    return false
  end
end
|(an0ther) click to toggle source

| (intersect) Returns a new Threshold Object

# File lib/threshold/thresholds.rb, line 157
def |(an0ther)
  Thresholds.new(@thresholds | an0ther.to_a)
end

Private Instance Methods

current_hash() click to toggle source
# File lib/threshold/thresholds.rb, line 206
def current_hash
  file = File.open(@file, 'rb+')
  file.flock(File::LOCK_EX)
  hash = Digest::MD5.file @file
  file.close
  return hash
end
stored_hash=(foo) click to toggle source
# File lib/threshold/thresholds.rb, line 202
def stored_hash=(foo)
  @stored_hash=foo
end
valid_existing_file?(file) click to toggle source
# File lib/threshold/thresholds.rb, line 214
def valid_existing_file?(file)
  if file !=nil
    raise NonExistantThresholdFile, "Missing threshold.conf" unless (File.file?(file) and File.exists?(file))
  else
    raise MissingThresholdFileConfiguration, "Missing threshold.conf path. See README for Usage."
  end
  return true
end