Werk #12149: Support for Python 2 based UNIX agent plugins
|Komponente||Checks und Agenten|
|Titel||Support for Python 2 based UNIX agent plugins|
|Checkmk-Editon||Checkmk Raw (CRE)|
|Kompatibilität||Inkompatibel - Manuelle Interaktion könnte erforderlich sein|
With Werk #11080, we made the huge step to port the entire Checkmk codebase from Python 2 to Python 3. This also affects all Python based agent plugins, that can be found under ~/share/check_mk/agents/plugins and that can be deployed via the agent bakery or manually.
However, there are still many UNIX systems out there that don't support Python 3 yet. In order to still ensure a functional monitoring on these hosts, all builtin Python based agent plugins now also support Python 2.
Automatic Python 3/Python 2 agent plugin mechanismThis is realized by the following mechanism:
- All python based agent plugins are written in Python 3 and end with .py
- For all builtin Python 3 agent plugins, an additional Python 2 plugin is available, that ends with _2.py. E.g., you will find a Python 2 agent plugin named apache_status_2.py right next to it's Python 3 counterpart apache_status.py.
- When deploying the agent plugin via agent bakery, both files will be deployed via the agent package. The UNIX agent will then automatically decide which file will be executed. If there is a Python installation >= 3.4 available on the system, the Python 3 variant will be executed. If there is instead a Python installation >= 2.6 available, the Python 2 variant will be executed. If none of the two variants are available, the plugin won't be executed.
- When deploying manually, the same mechanism holds true. You just have to include both files, if you want to make use of this feature. Please note that a python based plugin must end with _2.py to be executed via Python 2.
New agent rule "Python agent plugin execution (UNIX)"The agent will detect a Python 3 installation by the command python3 and a Python 2 installation by the commands python2 or python. If this mechanism is not suitable for you, or if you want to use Python 2, even if there is a Python 3 installation available, there exists a new agent ruleset called "Python agent plugin execution (UNIX)" for that purpose. Here, you can enforce either Python 2 or Python 3. Additionally, you can provide a custom Python command, if your host's Python installation differs from one of the above mentioned commands.
New error communicationIf the Python based plugins can't be executed on a host system, either because there is no suitable Python installation available, or the configured command doesn't exist, you will be noticed via the Check_MK service of the host, that will show a suitable error message and yield a WARN state. This also means that the Checkmk agent package installation will no longer fail if there is no suitable Python installation available.
IncompatibilitiesThis Werk is marked as incompatible due to some circumstances:
- Due to the fact that Python based plugins now require a .py ending, some builtin plugins had to be renamed. You'll have to consider this when deploying via a custom script that references the plugin's path on the Checkmk site. However, the agent bakery will still choose the right files.
- As Python 3 is the new default, and Python 2 was the old default, many Python based plugins will silently be executed with a different interpreter as before. If you still want Python 2, (and there is a Python 3 installation that would get chosen automatically,) you'll have to configure the above mentioned rule (if deploying via agent bakery), or explicitly deploy the _2.py version.
- When deploying your own Python based agent plugins, you have to keep in mind that a Python 3 plugin has to end with .py and a Python 2 plugin has to end with _2.py. In particular, the shebang (if any) will be ignored. If you explicitly wish to disable this mechanism, you can still write your Python based plugins as an executable script without a .py suffix (Of course, the shebang will be used, then).