Class: NagiosPlugin::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/nagiosplugin/plugin.rb

Defined Under Namespace

Classes: StatusError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.critical(message) ⇒ Object

Raise critical StatusError with message

Parameters:

  • message (String)

    the exeption message



57
# File 'lib/nagiosplugin/plugin.rb', line 57

make :critical

.ok(message) ⇒ Object

Raise ok StatusError with message

Parameters:

  • message (String)

    the exeption message



55
# File 'lib/nagiosplugin/plugin.rb', line 55

make :ok

.run(*args) ⇒ Object

Create new instance and run it.



37
38
39
# File 'lib/nagiosplugin/plugin.rb', line 37

def run(*args)
  self.new(*args).run
end

.unknown(message) ⇒ Object

Raise unknown StatusError with message

Parameters:

  • message (String)

    the exeption message



58
# File 'lib/nagiosplugin/plugin.rb', line 58

make :unknown

.warning(message) ⇒ Object

Raise warning StatusError with message

Parameters:

  • message (String)

    the exeption message



56
# File 'lib/nagiosplugin/plugin.rb', line 56

make :warning

Instance Method Details

#checkObject

Overwrite this check method and call a status method within.



61
62
63
# File 'lib/nagiosplugin/plugin.rb', line 61

def check
  unknown 'please overwrite the method `check` in your class'
end

#runObject

Run check and return result in a nagios-compatible format.

It will…

  • execute your check method

  • output the result in a nagios-compatible format (SERVICE STATUS: Message)

  • exit according to the status



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nagiosplugin/plugin.rb', line 71

def run
  check
rescue StatusError => e
rescue => e
  e = StatusError.new(:unknown, ([e.to_s, nil] + e.backtrace).join("\n"))
else
  e = StatusError.new(:unknown, 'no status method was called')
ensure
  puts [self.class.name.upcase, e.to_s].join(' ')
  exit e.to_i
end