checks: @perfdatas should user symbols as keys. +test
This commit is contained in:
parent
f7b6f4d63b
commit
ee60209b3c
2 changed files with 17 additions and 6 deletions
|
@ -107,7 +107,7 @@ module NSCA
|
|||
end
|
||||
|
||||
def push *perfdatas
|
||||
perfdatas.each {|perfdata| @perfdatas[perfdata.label] = perfdata }
|
||||
perfdatas.each {|perfdata| @perfdatas[perfdata.label.to_sym] = perfdata }
|
||||
@perfdatas
|
||||
end
|
||||
|
||||
|
@ -122,6 +122,7 @@ module NSCA
|
|||
|
||||
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
|
||||
|
||||
|
@ -146,11 +147,7 @@ module NSCA
|
|||
def determine_return_code
|
||||
self.class.perfdatas.map do |label, pdc|
|
||||
pd = @perfdatas[label]
|
||||
if pd
|
||||
pd.return_code
|
||||
else
|
||||
-1
|
||||
end
|
||||
pd ? pd.return_code : -1
|
||||
end.max
|
||||
end
|
||||
|
||||
|
|
|
@ -227,4 +227,18 @@ class TestNSCA::Check < Test::Unit::TestCase
|
|||
assert_equal ce1_data, ce2_data
|
||||
end
|
||||
end
|
||||
|
||||
context 'Perfdatas in Checks' do
|
||||
should 'be saved as symbol-key' do
|
||||
PH = NSCA::PerformanceData.new 'simplename', :ms
|
||||
CH = NSCA::Check.new 'a check with perfdata', 'hostname', [PH]
|
||||
assert_equal PH, CH.perfdatas[:'simplename']
|
||||
ch = CH.new
|
||||
assert_equal nil, ch['simplename']
|
||||
assert_equal nil, ch[:simplename]
|
||||
a = 0
|
||||
ch.measure( 'simplename') { 0.upto( 10000) { a += 1 } }
|
||||
assert_equal ch['simplename'], ch[:simplename]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue