def test_no_thresholds(mock_print, exit, thresholds, run_check, get_perfdata,
                       get_single_float, get_instance_rate_path,
                       calculate_rate, check_thresholds_and_exit,
                       logging_utils):
    logger = FakeLogger()
    logging_utils.Logger.return_value = logger

    returned_thresholds = 'thresholds'
    thresholds.return_value = returned_thresholds

    perfdata = 'theperfdata'
    get_perfdata.return_value = perfdata

    float_value = 1.234
    get_single_float.return_value = float_value

    hostname = 'therealhost'
    oid = 'somefakeoid'
    target_type = 'thetypeoftarget'

    check_snmp_numeric.main(
        ['--hostname', hostname, '--oid', oid, '--target-type', target_type])

    check_thresholds_and_exit.assert_called_once_with(
        float_value,
        returned_thresholds,
        perfdata,
        False,
    )

    thresholds.assert_called_once_with("", "", "", "", logger)
def test_rate(mock_print, exit, thresholds, run_check, get_perfdata,
              get_single_float, get_instance_rate_path, calculate_rate,
              check_thresholds_and_exit, logging_utils):
    logger = FakeLogger()
    logging_utils.Logger.return_value = logger

    run_check_result = 'checkresult'
    run_check.return_value = run_check_result

    returned_thresholds = 'thresholds'
    thresholds.return_value = returned_thresholds

    instance_rate_storage_path = 'instancestoragepath'
    get_instance_rate_path.return_value = instance_rate_storage_path

    perfdata = 'theperfdata'
    get_perfdata.return_value = perfdata

    float_value = 1.234
    get_single_float.return_value = float_value

    rate_result = 0.123
    calculate_rate.return_value = rate_result

    hostname = 'therealhost'
    oid = 'somefakeoid'
    target_type = 'thetypeoftarget'

    check_snmp_numeric.main([
        '--rate', '--hostname', hostname, '--oid', oid, '--target-type',
        target_type
    ])

    run_check.assert_called_once_with(
        check_snmp_numeric.__file__,
        target_type,
        hostname,
        oid,
        logger,
    )

    get_perfdata.assert_called_once_with(run_check_result)

    get_single_float.assert_called_once_with(run_check_result)

    get_instance_rate_path.assert_called_once_with(hostname, oid)

    calculate_rate.assert_called_once_with(logger, float_value,
                                           instance_rate_storage_path)

    check_thresholds_and_exit.assert_called_once_with(
        rate_result,
        returned_thresholds,
        perfdata,
        True,
    )
def test_thresholds(mock_print, exit, thresholds, run_check, get_perfdata,
                    get_single_float, get_instance_rate_path, calculate_rate,
                    check_thresholds_and_exit, logging_utils):
    logger = FakeLogger()
    logging_utils.Logger.return_value = logger

    returned_thresholds = 'thresholds'
    thresholds.return_value = returned_thresholds

    perfdata = 'theperfdata'
    get_perfdata.return_value = perfdata

    float_value = 1.234
    get_single_float.return_value = float_value

    low_warn = 2
    low_crit = 1
    high_warn = 3
    high_crit = 4

    hostname = 'therealhost'
    oid = 'somefakeoid'
    target_type = 'thetypeoftarget'

    check_snmp_numeric.main([
        '--hostname', hostname, '--oid', oid, '--target-type', target_type,
        '--low-warning',
        text_type(low_warn), '--low-critical',
        text_type(low_crit), '--high-warning',
        text_type(high_warn), '--high-critical',
        text_type(high_crit)
    ])

    check_thresholds_and_exit.assert_called_once_with(
        float_value,
        returned_thresholds,
        perfdata,
        False,
    )

    thresholds.assert_called_once_with(
        low_warn,
        low_crit,
        high_warn,
        high_crit,
        logger,
    )
def test_multi_oid(mock_print, exit, thresholds, run_check, get_perfdata,
                   get_single_float, get_instance_rate_path, calculate_rate,
                   check_thresholds_and_exit, logging_utils):
    logger = FakeLogger()

    hostname = 'therealhost'
    oid = 'somefakeoid,otheroid'
    target_type = 'thetypeoftarget'

    check_snmp_numeric.main(
        ['--hostname', hostname, '--oid', oid, '--target-type', target_type])

    logger.string_appears_in('error', 'single oid')
    mock_print_arg = mock_print.call_args_list[0][0][0].lower()
    assert 'single oid' in mock_print_arg

    exit.assert_called_once_with(STATUS_UNKNOWN)