These are the most important changes you have to be aware of when migrating your plug-in to this API version.
Note that changes are expressed in relation to the API version 1.
You can find a script in doc/treasures/migration_helpers/agent_based_v1_v2.py that will do most of the migration for you. Make sure to read the help texts by calling it with the argument --help
Architectural changes
These plug-ins previously were located at local/lib/check_mk/base/plugins/agent_based
To be discovered by Checkmk they now have to be in local/lib/python3/cmk_addons/plugins/<YOUR PLUGIN FAMILY NAME>/agent_based
Functional changes
type_defs module is dissolved
The type_defs module has been dissolved. All types are now directly imported from the v2 module.
check_levels signature changed
The new check_levels() function is designed to work well with the levels elements from the new rulesets API v1. These can be found in cmk.rulesets.v1.form_specs
The types of the arguments have been added to the API and can be found in cmk.agent_based.v2
Registration is replaced by a discovery approach
This is the main reason for the introduction of this new API version. Plug-ins are no longer registered during import, but only created and picked up later by the backend. To realize this, we introduced four new classes:
- AgentSection replacing register.agent_section()
- SimpleSNMPSection and SNMPSection replacing register.snmp_section()
- CheckPlugin replacing register.check_plugin()
- InventoryPlugin replacing register.inventory_plugin()
The arguments of these have barely changed (see next paragraph), resulting in easy to automate changes (see this commit for instance).
Changed arguments and validation for Agent and SNMP sections
We slightly adopted the arguments to the above-mentioned Section classes. We now favor type annotations over runtime validation. To get slightly easier type annotations, parse_function is no longer optional.
Removed wrapper for regex creation regex()
This has been removed. See its documentation for the reasoning. You can use pythons re.compile() as drop-in replacement.
Added rendering function time_offset()
On popular demand we add a function to render a number of seconds that might be negative.
Further references
You can find the entire documentation for both the agent-based Check API v1 and v2 in a Checkmk site from 2.3.0 on under Help > Plug-in API references > Agent based (“Check API”).
If you want to see how we 'bulk-migrated' plug-ins from v1 to v2: example 1, example 2, and example 3.