Example #1
0
def test_add_metric():
    check = Check()
    check.add_metric('Memory', 4500000, 'bytes', '4M:', '6M:')
    check.add_metric('CPU', 7, '%', '20:', '50:')
    assert len(check.metrics) == 2
    for metric in check.metrics:
        assert isinstance(metric, Metric)
Example #2
0
def test_final(capsys):
    check = Check()
    check.add_metric('Memory', 4500000, 'B', '4M:', '6M:', convert_metric=True)
    check.add_metric('CPU', 7, '%', '20:', '50:')
    with pytest.raises(SystemExit) as e:
        check.final()
    assert e.value.code == 2
    assert capsys.readouterr().out == (
        'METRIC CRITICAL - Memory is 4.29MB, CPU is 7% | Memory=4500000B;4M:;6M: CPU=7%;20:;50:{0}'
        .format(os.linesep))
Example #3
0
def test_final_per_second_UOM(capsys):
    check = Check()
    check.add_metric('Outbound Objects',
                     100,
                     'per_second',
                     '50',
                     '150',
                     summary_precision=0,
                     perf_data_precision=0)
    with pytest.raises(SystemExit) as e:
        check.final()
    assert e.value.code == 1
    assert capsys.readouterr().out == (
        "METRIC WARNING - Outbound Objects is 100/s | 'Outbound Objects'=100per_second;50;150{0}"
        .format(os.linesep))
Example #4
0
def test_add_metric_invalid_metric_name(metric_name, expected):
    check = Check()
    with pytest.raises(InvalidMetricName) as ex:
        check.add_metric(metric_name, 4500000, 'B', '4M:', '6M:')
    assert str(ex.value) == expected