class NSCA::Check::Base
Attributes
hostname[R]
perfdatas[R]
service[R]
perfdatas[R]
return_code[RW]
status[RW]
timestamp[RW]
Public Class Methods
clone( opts = nil)
click to toggle source
# File lib/nsca/check.rb, line 192 def clone( opts = nil) ::Class.new( self).init opts ? to_h.merge( opts) : to_h end
critical( status = nil, perfdatas = nil)
click to toggle source
# File lib/nsca/check.rb, line 185 def critical( status = nil, perfdatas = nil) new.warning status, perfdatas end
Also aliased as: crit
init(*args)
click to toggle source
# File lib/nsca/check.rb, line 173 def init *args a, o = args, args.last.is_a?( Hash) ? args.pop : {} service, hostname = nil, perfdatas = nil @service, @hostname, @perfdatas = a[0]||o[:service], a[1]||o[:hostname]||`hostname`.chomp, {} perfdatas = a[2]||o[:perfdatas] perfdatas.each {|pd| @perfdatas[pd.to_sym] = pd } if perfdatas self end
new(return_code = nil, status = nil, perfdatas = nil, timestamp = nil)
click to toggle source
# File lib/nsca/check.rb, line 86 def initialize return_code = nil, status = nil, perfdatas = nil, timestamp = nil @perfdatas = {} init return_code, status, perfdatas, timestamp || Time.now end
ok( status = nil, perfdatas = nil)
click to toggle source
# File lib/nsca/check.rb, line 182 def ok( status = nil, perfdatas = nil) new.ok status, perfdatas end
to_a()
click to toggle source
# File lib/nsca/check.rb, line 189 def to_a() [service, hostname, perfdatas.dup] end
to_h()
click to toggle source
# File lib/nsca/check.rb, line 190 def to_h() {service: service, hostname: hostname, perfdatas: perfdatas.values} end
to_sym()
click to toggle source
# File lib/nsca/check.rb, line 191 def to_sym() "#{hostname}|#{service}".to_sym end
unknown( status = nil, perfdatas = nil)
click to toggle source
# File lib/nsca/check.rb, line 187 def unknown( status = nil, perfdatas = nil) new.unknown status, perfdatas end
warning( status = nil, perfdatas = nil)
click to toggle source
# File lib/nsca/check.rb, line 183 def warning( status = nil, perfdatas = nil) new.warning status, perfdatas end
Also aliased as: warn
Public Instance Methods
[](perfdata_label)
click to toggle source
# File lib/nsca/check.rb, line 104 def [] perfdata_label pd = @perfdatas[perfdata_label.to_sym] pd && pd.value end
[]=(perfdata_label, value)
click to toggle source
# File lib/nsca/check.rb, line 123 def []= perfdata_label, value return push value if value.is_a? PerformanceData::Base perfdata_label = perfdata_label.to_sym @perfdatas[perfdata_label] = perfdata_for( perfdata_label).new value end
critical( *args)
click to toggle source
# File lib/nsca/check.rb, line 143 def critical( *args) init ReturnCode::CRITICAL, *args end
Also aliased as: crit
determine_return_code()
click to toggle source
# File lib/nsca/check.rb, line 147 def determine_return_code self.class.perfdatas.map do |label, pdc| pd = @perfdatas[label] pd ? pd.return_code : -1 end.max end
hostname()
click to toggle source
# File lib/nsca/check.rb, line 160 def hostname() self.class.hostname end
init(return_code = nil, status = nil, perfdatas = nil, timestamp = nil)
click to toggle source
# File lib/nsca/check.rb, line 91 def init return_code = nil, status = nil, perfdatas = nil, timestamp = nil @return_code = return_code if return_code @status = status if status case perfdatas when Hash perfdatas.each &method( :[]) when Array push *perfdatas end @timestamp = timestamp if timestamp self end
measure(perfdata_label, &block)
click to toggle source
# File lib/nsca/check.rb, line 135 def measure perfdata_label, &block push perfdata_for( perfdata_label).measure( &block) end
ok( *args)
click to toggle source
# File lib/nsca/check.rb, line 140 def ok( *args) init ReturnCode::OK, *args end
perfdata_for(label)
click to toggle source
# File lib/nsca/check.rb, line 114 def perfdata_for label if label.is_a? PerformanceData::Base label else label = label.to_sym self.class.perfdatas[label] || PerformanceData::Base.new( label) end end
push(*perfdatas)
click to toggle source
# File lib/nsca/check.rb, line 109 def push *perfdatas perfdatas.each {|perfdata| @perfdatas[perfdata.label.to_sym] = perfdata } @perfdatas end
retcode()
click to toggle source
# File lib/nsca/check.rb, line 154 def retcode rc = return_code || determine_return_code (0..3).include?(rc) ? rc : 3 end
send()
click to toggle source
# File lib/nsca/check.rb, line 138 def send() NSCA::send self end
service()
click to toggle source
# File lib/nsca/check.rb, line 159 def service() self.class.service end
text()
click to toggle source
# File lib/nsca/check.rb, line 129 def text r = "#{status || ReturnCode.find(retcode)}" r += " | #{perfdatas.each_value.map( &:to_s).join ' '}" unless perfdatas.empty? r end
to_a()
click to toggle source
# File lib/nsca/check.rb, line 161 def to_a() [timestamp, retcode, hostname, service, text] end
to_h()
click to toggle source
# File lib/nsca/check.rb, line 162 def to_h {timestamp: timestamp, return_code: retcode, hostname: hostname, server: service, status: text} end
to_packet(version = nil)
click to toggle source
# File lib/nsca/check.rb, line 166 def to_packet version = nil version ||= PacketV3 version.new timestamp, retcode, hostname, service, text end
unknown( *args)
click to toggle source
# File lib/nsca/check.rb, line 145 def unknown( *args) init ReturnCode::UNKNOWN, *args end
warning( *args)
click to toggle source
# File lib/nsca/check.rb, line 141 def warning( *args) init ReturnCode::WARNING, *args end
Also aliased as: warn