def test_cluster_missing_item(): section: Dict[str, Dict[str, local.LocalResult]] = { "node0": { "item": local.LocalResult( cached=None, item="Clustered service", state=0, text="Service is OK", perfdata=[], ) }, "node1": {}, } worst = local.cluster_check_local("item", Parameters({}), section) best = local.cluster_check_local( "item", Parameters({"outcome_on_cluster": "best"}), section) assert list(worst) == [ Result(state=state.OK, summary="[node0]: Service is OK"), ] assert list(best) == [ Result(state=state.OK, summary="[node0]: Service is OK"), ]
def test_cluster(): section: Dict[str, Dict[str, local.LocalResult]] = { "node0": { "item": local.LocalResult( cached=None, item="Clustered service", state=0, text="Service is OK", perfdata=[], ) }, "node1": { "item": local.LocalResult( cached=None, item="Clustered service", state=1, text="Service is WARN", perfdata=[], ) }, "node2": { "item": local.LocalResult( cached=None, item="Clustered service", state=2, text="Service is CRIT", perfdata=[], ) }, } worst = local.cluster_check_local("item", Parameters({}), section) best = local.cluster_check_local( "item", Parameters({"outcome_on_cluster": "best"}), section) assert list(worst) == [ Result(state=state.CRIT, summary="[node2]: Service is CRIT"), Result(state=state.OK, details="[node0]: Service is OK"), Result(state=state.WARN, details="[node1]: Service is WARN(!)"), ] assert list(best) == [ Result(state=state.OK, summary="[node0]: Service is OK"), Result(state=state.OK, details="[node1]: Service is WARN(!)"), Result(state=state.OK, details="[node2]: Service is CRIT(!!)"), ]
def test_check_mssql_transactionlogs(section): assert list( msdt.check_mssql_transactionlogs( 'MSSQL46.CorreLog_Report_T.CorreLog_Report_T_log', Parameters({}), section, None, ), ) == [ Result( state=state.OK, summary='Used: 16.0 MiB', ), Metric('data_size', 16777216.0, boundaries=(0, 2199023255552.0)), Result( state=state.OK, summary='Allocated used: 16.0 MiB', ), Result( state=state.OK, summary='Allocated: 256 MiB', ), Metric('allocated_size', 268435456.0, boundaries=(0, 2199023255552.0)), Result( state=state.OK, summary="Maximum size: 2.00 TiB", ), ]
def test_discovery_mssql_transactionlogs(section): section_db = msdb.parse_mssql_databases([ ['MSSQL46', 'master', 'ONLINE', 'SIMPLE', '0', '0'], ['MSSQL46', 'tempdb', 'ONLINE', 'SIMPLE', '0', '0'], ['MSSQL46', 'model', 'ONLINE', 'FULL', '0', '0'], ['MSSQL46', 'msdb', 'ONLINE', 'SIMPLE', '0', '0'], ['MSSQL46', 'NOC_CONFIG_T', 'ONLINE', 'FULL', '0', '0'], ['MSSQL46', 'DASH_CONFIG_T', 'ONLINE', 'FULL', '0', '0'], ['MSSQL46', 'NOC_ALARM_T', 'ONLINE', 'FULL', '0', '1'], ['MSSQL46', 'CorreLog_Report_T', 'ONLINE', 'FULL', '0', '0'], ['MSSQL46', 'test_autoclose', 'ONLINE', 'FULL', '1', '0'], ]) assert sorted( msdt.discover_mssql_transactionlogs([Parameters({})], section, section_db), key=lambda s: s.item, # type: ignore[attr-defined] ) == [ Service(item='MSSQL46.CorreLog_Report_T.CorreLog_Report_T_log'), Service(item='MSSQL46.DASH_CONFIG_T.DASH_CONFIG_T_log'), Service(item='MSSQL46.NOC_ALARM_T.NOC_ALARM_T_log'), Service(item='MSSQL46.NOC_CONFIG_T.NOC_CONFIG_T_log'), Service(item='MSSQL46.model.modellog'), Service(item='MSSQL46.test_autoclose.test_autoclose_log'), ]
def test_host_labels_ps_no_match_pattern(): section = ( 1, [ ( ps.ps_info("(root,4056,1512,0.0/52-04:56:05,5689)".split() ), # type: ignore[call-arg] ["/usr/lib/ssh/sshd"], ), ]) params = [ Parameters({ "default_params": {}, "descr": "SSH", "match": "~wat?", "label": DiscoveredHostLabels(HostLabel(u'marco', u'polo')), }), Parameters({}), ] assert list(ps.host_labels_ps(params, section)) == []
def test_check_warn_auto_shrink(section): assert list( check_mssql_databases("MSSQL_MSSQL46 NOC_ALARM_T", Parameters({}), section)) == [ Result(state=state.OK, summary="Status: ONLINE"), Result(state=state.OK, summary="Recovery: FULL"), Result(state=state.OK, summary="Auto close: off"), Result(state=state.WARN, summary="Auto shrink: on"), ]
def test_check_netscaler_vservers_clustered_best(clustered_vservers): assert list( _check_netscaler_vservers( Parameters({ "health_levels": (100.0, 0.1), "cluster_status": "best", }), clustered_vservers, ) ) == [ Result(state=state.OK, summary='Status: up (node1)', details='Status: up (node1)'), Result(state=state.OK, summary='Status: busy (node2)', details='Status: busy (node2)'), Result(state=state.WARN, summary='Health: 75.2% (warn/crit below 100%/0.10%)', details='Health: 75.2% (warn/crit below 100%/0.10%)'), Metric('health_perc', 75.2, levels=(None, None), boundaries=(0.0, 100.0)), Result( state=state.OK, summary='Type: loadbalancing, Protocol: ssl, Socket: 0.0.0.0:0', details='Type: loadbalancing, Protocol: ssl, Socket: 0.0.0.0:0'), Result(state=state.OK, summary='Request rate: 1/s', details='Request rate: 1/s'), Metric('request_rate', 1.0, levels=(None, None), boundaries=(None, None)), Result(state=state.OK, summary='In: 16.0 Bit/s', details='In: 16.0 Bit/s'), Metric('if_in_octets', 2.0, levels=(None, None), boundaries=(None, None)), Result(state=state.OK, summary='Out: 40.0 Bit/s', details='Out: 40.0 Bit/s'), Metric('if_out_octets', 5.0, levels=(None, None), boundaries=(None, None)), ]
def test_check_netscaler_vservers_clustered_worst(clustered_vservers): clustered_vservers[0]['service_state'] = ( 1, "transition to out of service", ) assert next( _check_netscaler_vservers( Parameters({ "health_levels": (100.0, 0.1), "cluster_status": "worst", }), clustered_vservers, )) == Result( state=state.WARN, summary='Status: transition to out of service (node1)', details='Status: transition to out of service (node1)', )
def test_check_f5_bigip_config_sync_v11_plus(section, result): assert list( check_f5_bigip_config_sync_v11_plus( Parameters(CONFIG_SYNC_DEFAULT_PARAMETERS), State(*section), )) == result
def test_check_error(section): assert list(check_mssql_databases("MSSQL_Mouse -", Parameters( {}), section)) == [ Result(state=state.CRIT, summary="We are out of cheese!"), ]
def test_cluster_check_f5_bigip_cluster_status(arg, result): assert list(cluster_check_f5_bigip_cluster_status(Parameters(arg[0]), arg[1])) == result