Sha256: e4314247e300f8cf9688231f0cb64c340cc574f1e66b5db1afbad6037e45ed40
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
module NagiosPlugin class Plugin class << self # Create new instance and run it. def run(*args) self.new(*args).run end private # @macro [status] message # @method $1(message) # Raise $1 StatusError with message # @param [String] message the exeption message def make(status) define_method(status) do |message| raise StatusError.new(status, message) end end end make :ok make :warning make :critical make :unknown # Overwrite this check method and call a status method within. def check unknown 'please overwrite the `check` method in your class' end # 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 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nagiosplugin-1.1.2 | lib/nagiosplugin/plugin.rb |
nagiosplugin-1.1.1 | lib/nagiosplugin/plugin.rb |
nagiosplugin-1.1.0 | lib/nagiosplugin/plugin.rb |