2013-03-13 20:46:35 +01:00
|
|
|
require 'helper'
|
|
|
|
|
2013-03-16 16:13:13 +01:00
|
|
|
class TestNSCA < Test::Unit::TestCase
|
2013-04-08 19:46:42 +02:00
|
|
|
class TestChecks
|
|
|
|
extend NSCA::Checks
|
2013-04-09 16:19:13 +02:00
|
|
|
PD1 = perfdata :pd1_in_sec, :s, 10, 20, 0, 30
|
|
|
|
PD2 = perfdata :pd2_in_1, 1, 0.99, 0.98, 0, 1
|
|
|
|
PD3 = perfdata :pd3_count, :c, 3, 5, 0
|
|
|
|
T0 = check 'TestNSCA0', 'uxnags01-sbe.net.mobilkom.at'
|
|
|
|
T1 = check 'TestNSCA1', 'uxnags01-sbe.net.mobilkom.at', [PD1, PD2]
|
|
|
|
T2 = check :TestNSCA2, 'uxnags01-sbe.net.mobilkom.at', [PD1, PD2, PD3]
|
2013-04-08 19:46:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'our test server' do
|
|
|
|
should 'receive data. NSCA-server should run on localhost 5777. if not, ignore this test. password=abcdefghijkl' do
|
|
|
|
PD1 = TestChecks::PD1
|
|
|
|
PD2 = TestChecks::PD2
|
|
|
|
PD3 = TestChecks::PD3
|
|
|
|
T0 = TestChecks::T0
|
|
|
|
T1 = TestChecks::T1
|
|
|
|
T2 = TestChecks::T2
|
|
|
|
|
2013-04-08 20:38:11 +02:00
|
|
|
checks = []
|
|
|
|
checks << TestChecks::T0.new( 1, "0123456789"*51+"AB")
|
|
|
|
|
2013-04-08 19:46:42 +02:00
|
|
|
pd1 = PD1.new 3
|
|
|
|
pd2 = PD2.new 0.9996
|
|
|
|
pd3 = PD3.new 2
|
2013-04-08 20:38:11 +02:00
|
|
|
checks << TestChecks::T1.new( nil, "Should be OK", [pd1, pd2, pd3])
|
|
|
|
|
|
|
|
NSCA::destinations << NSCA::Client.new( 'localhost', 5667, password: 'abcdefghijkl')
|
|
|
|
NSCA::send *checks
|
2013-04-08 19:46:42 +02:00
|
|
|
end
|
|
|
|
end
|
2013-03-16 16:13:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestNSCA::ReturnCode < Test::Unit::TestCase
|
|
|
|
context 'return code' do
|
|
|
|
should( 'be 0 == OK') { assert NSCA::ReturnCode.find(0) == NSCA::ReturnCode::OK }
|
|
|
|
should( 'be 1 == WARNING') { assert NSCA::ReturnCode.find(1) == NSCA::ReturnCode::WARNING }
|
|
|
|
should( 'be 2 == CRITICAL') { assert NSCA::ReturnCode.find(2) == NSCA::ReturnCode::CRITICAL }
|
|
|
|
should( 'be 3 == UNKNOWN') { assert NSCA::ReturnCode.find(3) == NSCA::ReturnCode::UNKNOWN }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestNSCA::Helper < Test::Unit::TestCase
|
|
|
|
context 'class gen name' do
|
|
|
|
should 'generate class names' do
|
|
|
|
assert :Total_run_check_measure == NSCA::Helper.class_name_gen( 'total run check measure')
|
|
|
|
end
|
|
|
|
|
|
|
|
should 'do not generate class names, if no letter' do
|
|
|
|
assert nil == NSCA::Helper.class_name_gen( '123 321, 43 _ ?')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestNSCA::PerformanceData < Test::Unit::TestCase
|
|
|
|
should 'set a subclass for new PerfData-types' do
|
2013-04-08 19:46:42 +02:00
|
|
|
NSCA::PerformanceData.create 'subclass test'
|
2013-03-16 16:13:13 +01:00
|
|
|
assert_nothing_raised NameError do
|
|
|
|
assert NSCA::PerformanceData::Subclass_test, "No subclass created."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def perfdata *a
|
2013-04-08 19:46:42 +02:00
|
|
|
NSCA::PerformanceData.new *a
|
2013-03-16 16:13:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Created NSCA::PerformanceData-subclasses' do
|
|
|
|
should 'be the same like returned' do
|
2013-04-08 19:46:42 +02:00
|
|
|
cl = NSCA::PerformanceData.create 'returned and subclass the same test'
|
2013-03-16 16:13:13 +01:00
|
|
|
assert cl == NSCA::PerformanceData::Returned_and_subclass_the_same_test, 'Classes are not the same.'
|
|
|
|
end
|
|
|
|
should 'have a unit if given' do
|
|
|
|
assert :s == perfdata( 'have an unit test', :s).unit, "Not s as unit"
|
|
|
|
end
|
|
|
|
should 'have not a unit if not given' do
|
|
|
|
assert nil == perfdata( 'have not an unit test', nil).unit, "Not nil as unit"
|
|
|
|
end
|
|
|
|
should 'have a warn thresh if given' do
|
|
|
|
assert 3 == perfdata( 'have a warn test', nil, 3).warn, "Not 3 as warn"
|
|
|
|
end
|
|
|
|
should 'have not a warn thresh if not given' do
|
|
|
|
assert nil == perfdata( 'have not a warn test', nil, nil).warn, "Not nil as warn"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-04-08 19:46:42 +02:00
|
|
|
class TestNSCA::Client < Test::Unit::TestCase
|
2013-03-16 16:13:13 +01:00
|
|
|
should '' do
|
2013-04-08 19:46:42 +02:00
|
|
|
NSCA::Client
|
2013-03-16 16:13:13 +01:00
|
|
|
end
|
2013-03-13 20:46:35 +01:00
|
|
|
end
|