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
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( int(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( HostName("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( HostName("test-prediction"), "CPU load", "untracked_prefdata", "MAX", from_time, until_time ) assert timeseries == cmk.utils.prediction.TimeSeries([0, 0, 0])