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, #initialize, #process

Methods inherited from MonitorType

#alert, #initialize, #process, #run, #teardown

Constructor Details

This class inherits a constructor from MonitorType_Threshold

Instance Method Details

#extractParamsObject

Extract parameters

Parameters:

  • path (String)

    Path to directory to check



9
10
11
12
13
14
15
16
17
18
# File 'lib/MonitorType/Dir.rb', line 9

def extractParams()
    if @params[:path].nil? then
        string = "*** Dir parameter missing, path\n"
        string = "#{string}*** :path => <path to directory to be monitored>"
        raise MonitorTypeParameterMissingError.new(string)
    end
    @path = @params[:path]

    @context_sentence = "Checking number of files in, #{@path}"
end

#getValueObject



38
39
40
# File 'lib/MonitorType/Dir.rb', line 38

def getValue
	return Dir.glob( "#{@path}/*" ).length
end

#setupObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/MonitorType/Dir.rb', line 21

def setup
       inputDir = Dir.new( @path )
	    @path = inputDir.path
       @params[:dir] = inputDir

       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