You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: improve cmk-plugin-guide structure and fix critical errors
Major documentation improvements:
- Added comprehensive table of contents for better navigation
- Fixed critical typos (cmk.base.pyugins → cmk.base.plugins) that would cause import errors
- Clarified SimpleLevels parameter handling to prevent common TypeError issues
- Added "Common Pitfalls and Solutions" section for troubleshooting
- Fixed bakery plugin directory paths for consistency
- Corrected temperature monitor example to use proper HostAndItemCondition
- Added important note about check_mk → python3/cmk symlink relationship
- Removed redundant and contradictory SimpleLevels documentation
These changes make the guide more reliable and easier to follow for developers
creating CheckMK plugins.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: cmk-plugin-guide.md
+95-67Lines changed: 95 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,23 @@
5
5
6
6
This guide provides comprehensive instructions for developing agent-based check plugins for CheckMK 2.3.0, including Agent Bakery support, based on the official CheckMK Plugin APIs.
> **📝 Important Path Note**: In CheckMK, `~/local/lib/check_mk` is a symlink to `~/local/lib/python3/cmk`. You may encounter both paths in documentation, error messages, and examples - they refer to the same location. This can cause confusion when debugging path-related issues or following different documentation sources.
56
+
38
57
### Agent Plugin Location
39
58
```
40
59
/usr/lib/check_mk_agent/plugins/
@@ -814,60 +833,60 @@ check_levels(
814
833
815
834
##### SimpleLevels Format Handling
816
835
817
-
CheckMK 2.3 rulesets with SimpleLevels actually produce parameters directly in the `("fixed", (warn, crit))` format that `check_levels()` expects, NOT as a dictionary with 'levels_upper' key. This is a common source of confusion that can lead to TypeErrors.
836
+
CheckMK 2.3 rulesets with SimpleLevels produce parameters in a specific format that's ready for `check_levels()`:
837
+
838
+
**Key Points:**
839
+
- SimpleLevels configured in the GUI produces `("fixed", (warn, crit))` tuples directly
840
+
- When no levels are configured, SimpleLevels produces `None`
841
+
- The parameters are ready to use - no extraction or conversion needed
842
+
- Never wrap the values in additional tuples or try to extract from non-existent dicts
**⚠️ Common Pitfall - TypeError with SimpleLevels**
857
-
858
-
A frequent mistake is trying to extract levels from a dictionary structure that doesn't exist:
876
+
**⚠️ Common Mistake to Avoid**
859
877
860
878
```python
861
-
# ❌ WRONG - This causes TypeError: '>=' not supported between instances of 'float' and 'tuple'
879
+
# ❌ WRONG - Don't try to extract from non-existent dict structure
862
880
storage_levels = params.get('storage_levels')
863
-
if storage_levels andisinstance(storage_levels, dict)and'levels_upper'in storage_levels:
864
-
levels_upper=("fixed", storage_levels['levels_upper']) # storage_levels is already a tuple!
881
+
if storage_levels andisinstance(storage_levels, dict): # This check will fail!
882
+
levels= storage_levels.get('levels_upper') # storage_levels is a tuple, not a dict!
865
883
866
-
# ✅ CORRECT - SimpleLevels already produces the right format
867
-
levels_upper= params.get('storage_levels') #Just use it directly!
884
+
# ✅ CORRECT - Use the parameter directly
885
+
levels= params.get('storage_levels') #Already in correct format!
868
886
```
869
887
870
-
The TypeError occurs because the code tries to wrap `("fixed", (80.0, 90.0))` again, resulting in `("fixed", ("fixed", (80.0, 90.0)))`, which causes check_levels to fail when comparing the float value with the nested tuple.
888
+
**Why This Error Happens:**
889
+
The confusion often comes from older CheckMK versions or manual parameter handling patterns. In CheckMK 2.3 with SimpleLevels, the framework handles the complexity for you.
**Note**: When SimpleLevels in the ruleset has no levels configured, it produces `None`, not `("no_levels", None)`. The check_levels function handles `None` appropriately.
The Agent Bakery allows centralized configuration and deployment of agent plugins across multiple hosts using the `cmk.base.pyugins.bakery.bakery_api.v1` API.
1037
+
The Agent Bakery allows centralized configuration and deployment of agent plugins across multiple hosts using the `cmk.base.plugins.bakery.bakery_api.v1` API.
1042
1038
1043
1039
**Important**: CheckMK 2.3 bakery integration requires **two separate files**:
1044
1040
1.**Bakery Plugin** - Technical logic for plugin generation and deployment
@@ -1049,7 +1045,7 @@ The Agent Bakery allows centralized configuration and deployment of agent plugin
from cmk.base.pyugins.bakery.bakery_api.v1 import (
2596
+
from cmk.base.plugins.bakery.bakery_api.v1 import (
2601
2597
register,
2602
2598
Plugin,
2603
2599
OS,
@@ -2695,6 +2691,38 @@ For additional resources:
2695
2691
- Community forums for support and discussion
2696
2692
- Local API documentation in `check_mk/plugin-api/html/`
2697
2693
2694
+
## Common Pitfalls and Solutions
2695
+
2696
+
### Import and Path Errors
2697
+
2698
+
**Problem**: `ModuleNotFoundError` for bakery imports
2699
+
-**Cause**: Typo in import path (`cmk.base.pyugins` instead of `cmk.base.plugins`)
2700
+
-**Solution**: Use `from cmk.base.plugins.bakery.bakery_api.v1 import ...`
2701
+
2702
+
**Problem**: Bakery plugin not found
2703
+
-**Cause**: Wrong directory path for bakery plugins
2704
+
-**Solution**: Place in `~/local/lib/check_mk/base/cee/plugins/bakery/`
2705
+
2706
+
### SimpleLevels and check_levels Errors
2707
+
2708
+
**Problem**: `TypeError: '>=' not supported between instances of 'float' and 'tuple'`
2709
+
-**Cause**: Wrapping SimpleLevels parameters that are already in correct format
2710
+
-**Solution**: Pass SimpleLevels parameters directly to check_levels without modification
2711
+
2712
+
### Ruleset Configuration Errors
2713
+
2714
+
**Problem**: `TypeError: HostAndServiceCondition.__init__() got an unexpected keyword argument`
2715
+
-**Cause**: Using wrong condition type for check plugin
2716
+
-**Solution**:
2717
+
- Use `HostAndItemCondition` for checks with items (multiple services per host)
2718
+
- Use `HostAndServiceCondition` for checks without items (single service per host)
2719
+
2720
+
### Check Plugin Discovery Issues
2721
+
2722
+
**Problem**: Plugin not discovered by CheckMK
2723
+
-**Cause**: Missing or incorrect entry point prefixes
2724
+
-**Solution**: Name variables correctly: `agent_section_*`, `check_plugin_*`
2725
+
2698
2726
## CheckMK Color Class Constants
2699
2727
2700
2728
The `cmk.graphing.v1.Color` class provides predefined color constants for use in graphing definitions. These constants ensure consistent color usage across CheckMK visualizations.
0 commit comments