Using get_value_store()

from the Plugin API coc

get_value_store()
Get the value store for the current service from Checkmk

The returned value store object can be used to persist values between different check executions. It is a MutableMapping, so it can be used just like a dictionary.

Return type
MutableMapping[str, Any]

so you can use it like this:

from cmk.base.plugins.agent_based.agent_based_api.v1 import (
    get_value_store,
)


def check_your_check_function(section):
    current_value = section.current_value  # or where ever your current value comes from

    persistent_values = get_value_store()  # load value store for this service
    
    if not persistent_values.get('previous_value'):   # check if this the first run
        persistent_values['previous_value'] = current_value  # save value for next run
        previous_value = None
    else:
        previous_value = persistent_values['previous_value']   # load previos value from store
        persistent_values['previous_value'] = current_value     # svae current value for next run

   # do your calucaltions ....

2 Likes