[ (meinberg_lantime_1, DiscoveryResult( [])), # GPS clocks are not covered here (meinberg_lantime_2, DiscoveryResult([('1', None)])), ]) def test_discovery_mbg_lantime_ng_refclock(check_manager, info, expected): check = check_manager.get_check("mbg_lantime_ng_refclock") discovery = DiscoveryResult(check.run_discovery(info)) assertDiscoveryResultsEqual(check, discovery, expected) @pytest.mark.parametrize("info,item,params,expected", [ (meinberg_lantime_2, '1', (3, 3), CheckResult([ BasicCheckResult( 0, 'Type: pzf600, Usage: primary, State: synchronized (LW sync)', None), BasicCheckResult(0, 'Field strength: 80%', [('field_strength', 80.0)]), BasicCheckResult(0, 'Correlation: 62%', [('correlation', 62.0)]), ])), ]) def test_check_mbg_lantime_ng_refclock(check_manager, info, item, params, expected): check = check_manager.get_check("mbg_lantime_ng_refclock") result = CheckResult(check.run_check(item, params, info)) assertCheckResultsEqual(result, expected) @pytest.mark.parametrize( "info,expected",
def test_fileinfo_min_max_age_levels(): # This test has the following purpose: # For each file attr (size or age) the levels 'min*', 'max*' are evaluated. # 'min*' is evaluated first and if 'max*' returns state '0' (eg. not set) # the service state is also '0'. check = Check("fileinfo") item = u'c:\\filetest\\check_mk.txt' parsed = check.run_parse([ [u'8'], [u'c:\\filetest\\check_mk.txt', u'7', u'5'], ]) size_result = BasicCheckResult( 0, "Size: 7 B", [ PerfValue('size', 7, None, None, None, None), ], ) # minage matches output_minage = check.run_check(item, { 'minage': (5, 1), }, parsed) # In 1.6.0 warn, crit of minage was added, but now we use the # generic check_levels function. assertCheckResultsEqual( CheckResult(output_minage), CheckResult([ size_result, BasicCheckResult( 1, "Age: 3.00 s (warn/crit below 5.00 s/1.00 s)", [ PerfValue('age', 3, None, None, None, None), ], ), ])) # maxage matches output_maxage = check.run_check(item, { 'maxage': (1, 2), }, parsed) assertCheckResultsEqual( CheckResult(output_maxage), CheckResult([ size_result, BasicCheckResult( 2, "Age: 3.00 s (warn/crit at 1.00 s/2.00 s)", [ PerfValue('age', 3, 1, 2, None, None), ], ), ])) # both match # This should never happen (misconfiguration), but test the order # of min* vs. max* and perfdata (always take the upper levels) # In 1.6.0 levels text of minage was added, but now we use the # generic check_levels function. output_both = check.run_check(item, { 'minage': (5, 1), 'maxage': (1, 2), }, parsed) assertCheckResultsEqual( CheckResult(output_both), CheckResult([ size_result, BasicCheckResult( 2, "Age: 3.00 s (warn/crit at 1.00 s/2.00 s)", [ PerfValue('age', 3, 1, 2, None, None), ], ), ]))
def test_winperf_if_teaming_performance_data(check_manager, monkeypatch): check = check_manager.get_check("winperf_if") monkeypatch.setitem(check.context, "host_extra_conf", lambda _, __: [{}]) monkeypatch.setitem(check.context, "_prepare_if_group_patterns_from_conf", lambda: {}) params_single = {'state': ['1'], 'speed': 10000000000} params_teamed = { 'aggregate': { 'item_type': 'index', 'group_patterns': { 'non-existent-testhost': { 'items': [], 'iftype': '6' } } }, 'state': ['1'], 'speed': 20000000000 } # Initalize counters monkeypatch.setattr('time.time', lambda: 0) parsed = winperf_if_teaming_parsed(time=0, out_octets=0) CheckResult(check.run_check(u'3', params_single, parsed)) CheckResult(check.run_check(u'8', params_single, parsed)) CheckResult(check.run_check(u'DAG-NET', params_teamed, parsed)) # winperf_if should use the timestamp of the parsed data. To check # that it does not use time.time by accident we set it to 20s instead # of 10s. If winperf_if would now use time.time the Out value would only # be 512 MB/s instead of 1 GB/s. monkeypatch.setattr('time.time', lambda: 20) parsed = winperf_if_teaming_parsed(time=10, out_octets=1024 * 1024 * 1024 * 10) result_3 = CheckResult(check.run_check(u'3', params_single, parsed)) result_8 = CheckResult(check.run_check(u'8', params_single, parsed)) result_dag_net = CheckResult(check.run_check(u'DAG-NET', params_teamed, parsed)) assertCheckResultsEqual( result_3, CheckResult([ BasicCheckResult( 0, u'[SLOT 6 Port 1 DAG] (Connected) MAC: A0:36:9F:B0:A3:60, 10 Gbit/s, In: 0.00 B/s (0.0%), Out: 1.00 GB/s (85.9%)', [ PerfValue('in', 0.0, None, None, 0, 1250000000.0), PerfValue('inucast', 0.0, None, None, None, None), PerfValue('innucast', 0.0, None, None, None, None), PerfValue('indisc', 0.0, None, None, None, None), PerfValue('inerr', 0.0, None, None, None, None), PerfValue('out', 1073741824.0, None, None, 0, 1250000000.0), PerfValue('outucast', 0.0, None, None, None, None), PerfValue('outnucast', 0.0, None, None, None, None), PerfValue('outdisc', 0.0, None, None, None, None), PerfValue('outerr', 0.0, None, None, None, None), PerfValue('outqlen', 0, None, None, None, None), ]) ])) assertCheckResultsEqual( result_8, CheckResult([ BasicCheckResult( 0, u'[SLOT 4 Port 2 DAG] (Connected) MAC: A0:36:9F:B0:B3:66, 10 Gbit/s, In: 0.00 B/s (0.0%), Out: 1.00 GB/s (85.9%)', [ PerfValue('in', 0.0, None, None, 0, 1250000000.0), PerfValue('inucast', 0.0, None, None, None, None), PerfValue('innucast', 0.0, None, None, None, None), PerfValue('indisc', 0.0, None, None, None, None), PerfValue('inerr', 0.0, None, None, None, None), PerfValue('out', 1073741824.0, None, None, 0, 1250000000.0), PerfValue('outucast', 0.0, None, None, None, None), PerfValue('outnucast', 0.0, None, None, None, None), PerfValue('outdisc', 0.0, None, None, None, None), PerfValue('outerr', 0.0, None, None, None, None), PerfValue('outqlen', 0, None, None, None, None), ]) ])) assertCheckResultsEqual( result_dag_net, CheckResult([ BasicCheckResult( 0, 'Teaming Status (up), Members: [8 (Connected), 3 (Connected)] 20 Gbit/s, In: 0.00 B/s (0.0%), Out: 2.00 GB/s (85.9%)', [ PerfValue('in', 0.0, None, None, 0, 2500000000.0), PerfValue('inucast', 0.0, None, None, None, None), PerfValue('innucast', 0.0, None, None, None, None), PerfValue('indisc', 0.0, None, None, None, None), PerfValue('inerr', 0.0, None, None, None, None), PerfValue('out', 2147483648.0, None, None, 0, 2500000000.0), PerfValue('outucast', 0.0, None, None, None, None), PerfValue('outnucast', 0.0, None, None, None, None), PerfValue('outdisc', 0.0, None, None, None, None), PerfValue('outerr', 0.0, None, None, None, None), PerfValue('outqlen', 0, None, None, None, None), ]) ]))
import pytest # type: ignore from checktestlib import BasicCheckResult, PerfValue, DiscoveryResult, assertDiscoveryResultsEqual # since both nfsmounts and cifsmounts use the parse, inventory # and check functions from network_fs.include unchanged we test # both checks here. pytestmark = pytest.mark.checks @pytest.mark.parametrize( "info,discovery_expected,check_expected", [ ( # no info [], [], (['', None, BasicCheckResult(3, ' not mounted', None)],)), ( # single mountpoint with data [[u'/ABCshare', u'ok', u'491520', u'460182', u'460182', u'65536']], [ ('/ABCshare', {}) ], [('/ABCshare', {}, BasicCheckResult(0, "6.4% used (1.91 GB of 30.00 GB)", None)), ('/ZZZshare', {}, BasicCheckResult(3, "/ZZZshare not mounted", None))]), ( # two mountpoints with empty data [[u'/AB', u'ok', u'-', u'-', u'-', u'-'], [u'/ABC', u'ok', u'-', u'-', u'-', u'-']], [ ('/AB', {}), ('/ABC', {}) ], [('/AB', {}, BasicCheckResult(0, "Mount seems OK", None)), ('/ABC', {}, BasicCheckResult(0, "Mount seems OK", None))]), ( # Mountpoint with spaces and permission denied [[u'/var/dba', u'export', u'Permission', u'denied'], [u'/var/dbaexport', u'ok', u'201326592', u'170803720', u'170803720', u'32768']], [ ('/var/dbaexport', {}), ('/var/dba export', {}) ], [('/var/dba export', {}, BasicCheckResult(2, 'Permission denied', None)), ('/var/dbaexport', {},
import pytest # type: ignore[import] from testlib import Check # type: ignore[import] from checktestlib import BasicCheckResult pytestmark = pytest.mark.checks @pytest.mark.parametrize( 'info,discoveries_expected,checks_expected', [ ( # internal temperature [[[u'2070', u'', u'']], []], [ ('ra32e_sensors', [('Internal', {})]), ('ra32e_sensors.humidity', []), ], [ ('ra32e_sensors', "Internal", {}, BasicCheckResult(0, u'20.7 °C', [('temp', 20.70)])), ('ra32e_sensors', "Heat Index", {}, BasicCheckResult(3, 'no data for sensor')), ('ra32e_sensors.humidity', "Internal", {}, BasicCheckResult( 3, 'no data for sensor')), ]), ( # internal humidity and heat index [[[u'', u'6000', u'2070']], []], [ ('ra32e_sensors', [('Heat Index', {})]), ('ra32e_sensors.humidity', [('Internal', {})]), ], [ ('ra32e_sensors', "Internal", {}, BasicCheckResult(3, 'no data for sensor')), ('ra32e_sensors', "Heat Index", {}, BasicCheckResult(0, u'20.7 °C', [('temp', 20.70)])), ('ra32e_sensors.humidity', "Internal", {}, BasicCheckResult(0, '60.0%', [('humidity', 60.0, None, None, 0, 100)])), ]),
def test_ra32e_power_check_nodata(check_manager): check = check_manager.get_check(RA32E_POWER) result = BasicCheckResult(*check.run_check(None, {}, [['']])) assert result.status == 3 assert 'unknown' in result.infotext
def test_ra32e_power_check_acpower(check_manager): check = check_manager.get_check(RA32E_POWER) result = BasicCheckResult(*check.run_check(None, {}, [['1']])) assert result.status == 0 assert 'AC/Utility' in result.infotext
size2 = Size( [u'201326592', u'170803720', u'170803720', u'32768'], None, # not in use None, # not in use "15.16% used (931.48 GB of 6.00 TB)", ) @pytest.mark.parametrize( "info,discovery_expected,check_expected", [ ( # no info [], [], ()), ( # single mountpoint with data [[u'/ABCshare', u'ok'] + size1.info], [('/ABCshare', {})], [ ('/ABCshare', {}, BasicCheckResult(0, size1.text, None)), ]), ( # two mountpoints with empty data [[u'/AB', u'ok', u'-', u'-', u'-', u'-'], [u'/ABC', u'ok', u'-', u'-', u'-', u'-']], [ ('/AB', {}), ('/ABC', {}) ], [('/AB', {}, BasicCheckResult(0, "Mount seems OK", None)), ('/ABC', {}, BasicCheckResult(0, "Mount seems OK", None))]), ( # Mountpoint with spaces and permission denied [[u'/var/dba', u'export', u'Permission', u'denied'], [u'/var/dbaexport', u'ok'] + size2.info], [ ('/var/dbaexport', {}), ('/var/dba export', {}) ], [('/var/dba export', {}, BasicCheckResult(2, 'Permission denied', None)), ('/var/dbaexport', {}, BasicCheckResult(0, size2.text, None)) ]),