Class: MonitorTypeDir
- Inherits:
-
MonitorTypeThreshold
- Object
- MonitorType
- MonitorTypeThreshold
- MonitorTypeDir
- Defined in:
- lib/monitor_type/dir.rb
Overview
A directory class for checking how many files are in a directory
Instance Method Summary collapse
- #derived_value ⇒ Object
-
#extract_params ⇒ Object
Extract parameters.
- #setup ⇒ Object
Methods inherited from MonitorTypeThreshold
Methods inherited from MonitorType
#alert, #initialize, #process, #run, #teardown
Constructor Details
This class inherits a constructor from MonitorTypeThreshold
Instance Method Details
#derived_value ⇒ Object
38 39 40 |
# File 'lib/monitor_type/dir.rb', line 38 def derived_value Dir.glob("#{@path}/*").length end |
#extract_params ⇒ Object
Extract parameters
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/monitor_type/dir.rb', line 8 def extract_params if @params[:path].nil? string = "*** Dir parameter missing, path\n" \ '*** :path => <path to directory to be monitored>' fail MonitorTypeParameterMissingError, string end @path = @params[:path] @context_sentence = "Checking number of files in, #{@path}" end |
#setup ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/monitor_type/dir.rb', line 19 def setup input_dir = Dir.new(@path) @path = input_dir.path @params[:dir] = input_dir rescue Errno::ENOENT str = "***** Directory does not exist, #{@path}.\n" \ "***** Create the directory, #{@path}, and try again.\n" \ "***** eg, mkdir #{@path}" raise MonitorTypeExceptionHandled, str rescue Errno::ENOTDIR str = '***** The specified path does not point to a ' \ "directory, #{@path}.\n" \ '***** Either repoint path to a directory, ' \ "or remove, #{@path}, and create it as a directory.\n" \ "***** eg, rm #{@path} && mkdir #{@path}" raise MonitorTypeExceptionHandled, str end |