Class: CheckFromFile::Check

Inherits:
Nagios::Plugin
  • Object
show all
Defined in:
lib/check_from_file/check.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Check



6
7
8
9
10
# File 'lib/check_from_file/check.rb', line 6

def initialize(options)
  @options = options
  @warning = false
  @critical = false
end

Instance Method Details

#checkObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/check_from_file/check.rb', line 25

def check
  [:return, :stdout, :stderr].each do |file|
    @age = (Time.now - File.stat(@options[file]).mtime).to_i
    case
    when @age >= @options[:file_age_critical]
      @stale = @critical = true
      break
    when @age >= @options[:file_age_warning]
      @stale = @warning = true
      break
    end
  end

  @return = File.read(@options[:return]).to_i
  @stdout = File.read(@options[:stdout])
  @stderr = File.read(@options[:stderr])
end

#critical?Boolean



12
13
14
15
# File 'lib/check_from_file/check.rb', line 12

def critical?
  @critical = true unless @return == 0
  return @critical
end

#messageObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/check_from_file/check.rb', line 43

def message
  return "One or more output files are #{@age} seconds old!" if @stale

  ret = "Command: #{@options[:command]} returned "
  if @critical
    ret << "#{@return}, STDOUT: #{@stdout}, STDERR: #{@stderr}"
  else
    ret << "successfully"
  end
  return ret
end

#ok?Boolean



21
22
23
# File 'lib/check_from_file/check.rb', line 21

def ok?
  true
end

#warning?Boolean



17
18
19
# File 'lib/check_from_file/check.rb', line 17

def warning?
  return @warning
end