check: text can be generated, also if no return_code given (retcode will be used). hostname-call must be chompd. tests

master
Denis Knauf 2013-04-11 14:23:32 +02:00
parent 4b8cc9eef8
commit 8b0f1f9015
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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'