예제 #1
0
def test_get_rrd_data(cfg_setup, utcdate, timezone, period, result):

    with on_time(utcdate, timezone):
        timestamp = time.time()
        _, from_time, until_time, _ = prediction.get_prediction_timegroup(
            int(timestamp), prediction.prediction_periods[period])

    timeseries = cmk.utils.prediction.get_rrd_data('test-prediction', 'CPU load', 'load15', 'MAX',
                                                   from_time, until_time)

    assert timeseries.start <= from_time
    assert timeseries.end >= until_time
    assert (timeseries.step, len(timeseries.values)) == result
예제 #2
0
def test_get_rrd_data_fails(cfg_setup):
    timestamp = time.mktime(datetime.strptime("2018-11-28 12", "%Y-%m-%d %H").timetuple())
    _, from_time, until_time, _ = prediction.get_prediction_timegroup(
        timestamp, prediction.prediction_periods["hour"])

    # Fail to get data, because non-existent check
    with pytest.raises(MKGeneralException, match="Cannot get historic metrics via Livestatus:"):
        cmk.utils.prediction.get_rrd_data('test-prediction', 'Nonexistent check', 'util', 'MAX',
                                          from_time, until_time)

    # Empty response, because non-existent perf_data variable
    timeseries = cmk.utils.prediction.get_rrd_data(
        'test-prediction', 'CPU load', 'untracked_prefdata', 'MAX', from_time, until_time)

    assert timeseries == cmk.utils.prediction.TimeSeries([0, 0, 0])