Module: NagiosCheck::ClassMethods

Defined in:
lib/nagios_check.rb

Instance Method Summary collapse

Instance Method Details

#check_options!(options) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/nagios_check.rb', line 106

def check_options!(options)
  @option_specs.each do |name, spec|
    _, option_params, _ = spec
    if option_params[:mandatory] && options.send(name).nil? 
      raise MissingOption.new(name)
    end
  end
end

#defaultsObject



84
85
86
# File 'lib/nagios_check.rb', line 84

def defaults
  @defaults
end

#enable_critical(*args) ⇒ Object



94
95
96
97
98
# File 'lib/nagios_check.rb', line 94

def enable_critical(*args)
  on("-c RANGE", *args) do |value| 
    self.options.c = NagiosCheck::Range.new(value) 
  end
end

#enable_timeout(*args) ⇒ Object



100
101
102
103
104
# File 'lib/nagios_check.rb', line 100

def enable_timeout(*args)
  on("-t TIMEOUT", *args) do |value| 
    self.options.t = value.to_f 
  end
end

#enable_warning(*args) ⇒ Object



88
89
90
91
92
# File 'lib/nagios_check.rb', line 88

def enable_warning(*args)
  on("-w RANGE", *args) do |value| 
    self.options.w = NagiosCheck::Range.new(value) 
  end
end

#on(*args, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/nagios_check.rb', line 72

def on(*args, &block)
  name = option_name(args.first)
  option_params = {
    :mandatory => args.delete(:mandatory) ? true : false
  }
  if args.last.respond_to? :has_key? 
    option_params.merge! args.pop
  end
  @defaults[name] = option_params[:default] if option_params.has_key? :default
  @option_specs[name] = [args, option_params,  block]
end