Class: CheckFromFile::Check
- Inherits:
-
Nagios::Plugin
- Object
- Nagios::Plugin
- CheckFromFile::Check
- Defined in:
- lib/check_from_file/check.rb
Instance Method Summary collapse
- #check ⇒ Object
- #critical? ⇒ Boolean
-
#initialize(options) ⇒ Check
constructor
A new instance of Check.
- #message ⇒ Object
- #ok? ⇒ Boolean
- #warning? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Check
6 7 8 9 10 |
# File 'lib/check_from_file/check.rb', line 6 def initialize() = @warning = false @critical = false end |
Instance Method Details
#check ⇒ Object
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([file]).mtime).to_i case when @age >= [:file_age_critical] @stale = @critical = true break when @age >= [:file_age_warning] @stale = @warning = true break end end @return = File.read([:return]).to_i @stdout = File.read([:stdout]) @stderr = File.read([: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 |
#message ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/check_from_file/check.rb', line 43 def 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 |