diff --git a/lib/nsca/check.rb b/lib/nsca/check.rb index cb19767..569d950 100644 --- a/lib/nsca/check.rb +++ b/lib/nsca/check.rb @@ -126,7 +126,7 @@ module NSCA end def text - r = "#{status || ReturnCode.find(return_code)}" + r = "#{status || ReturnCode.find(retcode)}" r += " | #{perfdatas.each_value.map( &:to_s).join ' '}" unless perfdatas.empty? r end @@ -171,7 +171,7 @@ module NSCA 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`, {} + @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 diff --git a/test/test_nsca.rb b/test/test_nsca.rb index 83c2264..18f987f 100644 --- a/test/test_nsca.rb +++ b/test/test_nsca.rb @@ -169,6 +169,24 @@ class TestNSCA::PerformanceData < Test::Unit::TestCase end class TestNSCA::Check < Test::Unit::TestCase + context 'Data' do + should 'also be empty' do + CF = NSCA::Check.new 'empty data' + cf = CF.new + hostname = `hostname`.chomp + assert_equal [cf.timestamp, 3, hostname, 'empty data', 'UNKNOWN'], cf.to_a + end + + should 'have default a timestamp. ~ -10s..10s' do + CG = NSCA::Check.new 'default timestamp' + cg = CG.new + now = Time.now + range = Time.at(now-10) .. Time.at(now+10) + assert range.begin <= cg.timestamp && cg.timestamp <= range.end, + "Not a valid timestamp ~now: #{cg.timestamp}" + end + end + context 'Subclasses' do should 'be created by NSCA::Check.create' do CA = NSCA::Check.create 'a uniq name'