Accessing metric data in check routine

Hello!
Does anyone know of a way to access historic data from check metrics?
I’m currently working on a plugin for monitoring a Telephone-System, via the API I get data for failed and succeeded calls in total which I display as metrics. Now I want to check the percentage of failed calls in the last 12 hours, so it would be great if I had a way to access the metric data from the last 12h instead of storing it manually in a value store since this doesn’t seem efficient.
I have seen that you can extract the metric data via the REST-Api to display it in Grafana but haven’t found the exact request for that (yet) and I’m not really sure if a local REST-Api call is the most elegant solution to this.

have a look at the get_value_store() function. With this you can save values on one run of the check and access them on the next run to do your calculations. A second function that could help is get_rate. For both functions see the online Check plugin API reference inclued in your CMK site.

Have you already tried CheckMK LQL? You should get all metrics from the particular Host & service with the following command.

lq "GET log\nFilter: host_name = HOSTNAME\nFilter: service_description = SERVICE\nFilter: time >= $$(date +%s)-3600\nColumns: Columns: host_name service_description time current_service_perf_data"

Of course, replace “HOSTNAME” & “SERVICE” with your with your particular settings.

Note: The metrics are structured as follows:

metric_name=value;warn;crit;min;max