Module: NagiosCheck::ClassMethods

Defined in:
lib/nagios_check.rb

Instance Method Summary collapse

Instance Method Details

#check_options!(options) ⇒ Object



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

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



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

def defaults
  @defaults
end

#enable_critical(*args) ⇒ Object



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

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

#enable_timeout(*args) ⇒ Object



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

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

#enable_warning(*args) ⇒ Object



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

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

#on(*args, &block) ⇒ Object



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

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