class Threshold::Thresholds
Attributes
Public Class Methods
# File lib/threshold/thresholds.rb, line 17 def initialize(thresholds = []) @thresholds = thresholds end
Public Instance Methods
& (union) Returns a new Threshold
Object
# File lib/threshold/thresholds.rb, line 162 def &(an0ther) Thresholds.new(@thresholds & an0ther.to_a) end
+ (concat) Returns a new Threshold
Object
# File lib/threshold/thresholds.rb, line 151 def +(an0ther) Thresholds.new(@thresholds + an0ther.to_a) end
-
(Difference)
Returns a new Threshold
Object
# File lib/threshold/thresholds.rb, line 168 def -(an0ther) Thresholds.new(@thresholds - an0ther.to_a) end
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
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
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
Clears current collection and Read in the thresholds.conf file
# File lib/threshold/thresholds.rb, line 44 def loadfile! @thresholds.clear loadfile end
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
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
Returns a new Threshold
Object
# File lib/threshold/thresholds.rb, line 109 def reverse Thresholds.new(@thresholds.reverse) end
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
Returns a new Threshold
Object
# File lib/threshold/thresholds.rb, line 114 def shuffle Thresholds.new(@thresholds.shuffle) end
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
The calculated hash of the threshold.conf file at load time.
# File lib/threshold/thresholds.rb, line 92 def stored_hash @stored_hash end
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
# File lib/threshold/thresholds.rb, line 95 def to_a @thresholds end
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
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
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
| (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
# 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
# File lib/threshold/thresholds.rb, line 202 def stored_hash=(foo) @stored_hash=foo end
# 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