Class: MonitorTypeDrive

Inherits:
MonitorTypeThreshold show all
Defined in:
lib/monitor_type/drive.rb

Overview

MonitorType Drive

Instance Method Summary collapse

Methods inherited from MonitorTypeThreshold

#check, #initialize, #process

Methods inherited from MonitorType

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

Constructor Details

This class inherits a constructor from MonitorTypeThreshold

Instance Method Details

#derived_valueObject



42
43
44
# File 'lib/monitor_type/drive.rb', line 42

def derived_value
  ((Filesystem.stat(@path).blocks_available.to_f / Filesystem.stat(@path).blocks.to_f) * 100).round(2)
end

#extract_paramsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/monitor_type/drive.rb', line 7

def extract_params
  if @params[:path].nil?
    string = "*** Drive parameter missing, drive\n" \
             '*** :drive => <name of the drive to be monitored>'
    fail MonitorTypeParameterMissingError, string
  end
  @path = @params[:path]

  log "#{@process_name}", "result: #{(@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0}"

  if @params[:min].nil?
    string = "*** Min parameter missing, min\n" \
             '*** :min => <the minimum amount of free space on ' \
             'the drive to be monitored>'
    fail MonitorTypeParameterMissingError, string
  end

  log '*** Max value will be ignored, setting to nil' unless @params[:max].nil?
  @max = nil

  @context_sentence = 'Checking that available drive space is greater ' \
                      "than min, #{@process_name}"
end

#setupObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/monitor_type/drive.rb', line 31

def setup
  # Check that the path exists
  Filesystem.stat(@path)

rescue
  string = "*** Unable to mount the specifed path\n" \
           "*** path: #{@path}\n" \
           "*** Please fix the error and run again\n"
  raise MonitorTypeExceptionHandled, string
end