Class: MonitorType_Dir
- Inherits:
-
MonitorType_Threshold
- Object
- MonitorType
- MonitorType_Threshold
- MonitorType_Dir
- Defined in:
- lib/MonitorType/Dir.rb
Instance Method Summary collapse
-
#initialize(params) ⇒ MonitorType_Dir
constructor
A new instance of MonitorType_Dir.
- #process ⇒ Object
- #sanitise ⇒ Object
Methods inherited from MonitorType_Threshold
Methods inherited from MonitorType
Constructor Details
#initialize(params) ⇒ MonitorType_Dir
Returns a new instance of MonitorType_Dir.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/MonitorType/Dir.rb', line 25 def initialize( params ) super( params ) if params[:path].nil? then puts "*** Dir parameter missing, path" puts "*** :path => <path to directory to be monitored>" abort end @path = params[:path] self.sanitise rescue MonitorTypeExceptionHandled => e puts e. abort() end |
Instance Method Details
#process ⇒ Object
39 40 41 42 |
# File 'lib/MonitorType/Dir.rb', line 39 def process number_of_files = Dir.glob( "#{@path}/*" ).length self.check( number_of_files, "Checking number of files in, #{@path}" ) end |
#sanitise ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/MonitorType/Dir.rb', line 5 def sanitise inputDir = Dir.new( @path ) @path = inputDir.path if !File.writable?( @path ) then puts "*** Warning. Directory is not writable, #{@path}." puts "*** Warning. Make the directory, #{@path}, writable and try again." end rescue Errno::ENOENT => e string = "***** Directory does not exist, #{@path}.\n" string = "#{string}***** Create the directory, #{@path}, and try again.\n" string = "#{string}***** eg, mkdir #{@path}" raise MonitorTypeExceptionHandled.new(string) rescue Errno::ENOTDIR => e string = "***** The specified path does not point to a directory, #{@path}.\n" string = "#{string}***** Either repoint path to a directory, or remove, #{@path}, and create it as a directory.\n" string = "#{string}***** eg, rm #{@path} && mkdir #{@path}" raise MonitorTypeExceptionHandled.new(string) end |