Class: MonitorType_Dir

Inherits:
MonitorType_Threshold show all
Defined in:
lib/MonitorType/Dir.rb

Overview

A directory class for checking how many files are in a directory

Instance Method Summary collapse

Methods inherited from MonitorType_Threshold

#check

Methods inherited from MonitorType

#alert, #run

Constructor Details

#initialize(params) ⇒ MonitorType_Dir

Constructor: Extract parameters

Parameters:

  • path (String)

    Path to directory to check



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/MonitorType/Dir.rb', line 29

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.message
       abort()
end

Instance Method Details

#processObject



43
44
45
46
# File 'lib/MonitorType/Dir.rb', line 43

def process
	number_of_files = Dir.glob( "#{@path}/*" ).length
	self.check( number_of_files, "Checking number of files in, #{@path}" )
end

#sanitiseObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/MonitorType/Dir.rb', line 6

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