├── .devcontainer ├── Dockerfile ├── build.sh ├── devcontainer.json ├── requirements.txt ├── symlink.sh ├── template-sync-includes.conf ├── template-sync.conf └── template-update.sh ├── .flake8 ├── .gitattributes ├── .github └── workflows │ ├── build-release.yml │ ├── build.yml │ ├── lint.yml │ └── pytest.yml ├── .gitignore ├── .vscode ├── settings.json └── tasks.json ├── README.md └── package /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/ubuntu/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] CheckMK version: 2.3.0-latest 4 | ARG VARIANT="2.3.0-latest" 5 | FROM checkmk/check-mk-raw:${VARIANT} 6 | 7 | RUN /docker-entrypoint.sh /bin/true 8 | 9 | # [Optional] Uncomment this section to install additional OS packages. 10 | RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 11 | && apt-get -y install --no-install-recommends nodejs gcc 12 | 13 | ADD requirements.txt /tmp/requirements.txt 14 | RUN PATH="/omd/sites/cmk/bin:${PATH}" \ 15 | OMD_ROOT="/omd/sites/cmk" \ 16 | /omd/sites/cmk/bin/pip3 install -r /tmp/requirements.txt 17 | 18 | ENTRYPOINT ["/bin/bash"] -------------------------------------------------------------------------------- /.devcontainer/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | NAME=$(python3 -c 'print(eval(open("package").read())["name"])') 4 | VERSION=$(python3 -c 'print(eval(open("package").read())["version"])') 5 | rm /omd/sites/cmk/var/check_mk/packages/${NAME} \ 6 | /omd/sites/cmk/var/check_mk/packages_local/${NAME}-*.mkp ||: 7 | 8 | mkp -v package package 2>&1 | sed '/Installing$/Q' ||: 9 | 10 | cp /omd/sites/cmk/var/check_mk/packages_local/$NAME-$VERSION.mkp . 11 | 12 | mkp inspect $NAME-$VERSION.mkp 13 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/ubuntu 3 | { 4 | "name": "Checkmk", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | // Update 'VARIANT' to pick an Ubuntu version: focal, bionic 8 | "args": { "VARIANT": "2.3.0-latest" } 9 | }, 10 | 11 | "customizations": { 12 | "vscode": { 13 | // Add the IDs of extensions you want installed when the container is created. 14 | "extensions": [ 15 | "ms-python.python", 16 | "ms-python.flake8", 17 | "littlefoxteam.vscode-python-test-adapter" 18 | ], 19 | 20 | // Set *default* container specific settings.json values on container create. 21 | "settings": { 22 | "terminal.integrated.defaultProfile.linux": "bash", 23 | "python.defaultInterpreterPath": "/omd/sites/cmk/bin/python3" 24 | } 25 | } 26 | }, 27 | 28 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 29 | // "forwardPorts": [], 30 | 31 | // Use 'postCreateCommand' to run commands after the container is created. 32 | "postCreateCommand": ".devcontainer/symlink.sh", 33 | 34 | // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 35 | "remoteUser": "cmk", 36 | 37 | // Uncomment to use with podman 38 | //"containerUser": "cmk", 39 | //"runArgs": ["--userns=keep-id"], 40 | 41 | "remoteEnv": { 42 | "PATH": "/omd/sites/cmk/bin:/omd/sites/cmk/local/lib/python3/bin/:${containerEnv:PATH}", 43 | "OMD_ROOT": "/omd/sites/cmk", 44 | "OMD_SITE": "cmk", 45 | "CMK_SITE_ID": "cmk", 46 | "WORKSPACE": "${containerWorkspaceFolder}" 47 | } 48 | } -------------------------------------------------------------------------------- /.devcontainer/requirements.txt: -------------------------------------------------------------------------------- 1 | flake8 2 | pytest 3 | pytest-md 4 | pytest-cov 5 | pytest-emoji 6 | requests-mock -------------------------------------------------------------------------------- /.devcontainer/symlink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PKGNAME=$(python3 -c 'print(eval(open("package").read())["name"])') 3 | ln -sv $WORKSPACE $OMD_ROOT/local/lib/python3/cmk_addons/plugins/$PKGNAME 4 | 5 | for DIR in 'agents' 'checkman' 'checks' 'doc' 'inventory' 'notifications' 'pnp-templates' 'web'; do 6 | rm -rfv $OMD_ROOT/local/share/check_mk/$DIR 7 | ln -sv $WORKSPACE/$DIR $OMD_ROOT/local/share/check_mk/$DIR 8 | done; 9 | 10 | rm -rfv $OMD_ROOT/local/lib/python3/cmk/base/plugins/agent_based 11 | ln -sv $WORKSPACE/agent_based $OMD_ROOT/local/lib/python3/cmk/base/plugins/agent_based 12 | 13 | mkdir -p $OMD_ROOT/local/lib/python3/cmk/base/cee/plugins 14 | ln -sv $WORKSPACE/bakery $OMD_ROOT/local/lib/python3/cmk/base/cee/plugins/bakery 15 | 16 | rm -rfv $OMD_ROOT/local/lib/nagios/plugins 17 | ln -sv $WORKSPACE/nagios_plugins $OMD_ROOT/local/lib/nagios/plugins -------------------------------------------------------------------------------- /.devcontainer/template-sync-includes.conf: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - Change template-sync.conf 2 | include .devcontainer/ 3 | include .devcontainer/** 4 | exclude .github/template-sync.conf 5 | include .github/ 6 | include .github/** 7 | include .vscode/ 8 | include .vscode/** 9 | include .flake8 10 | include .gitignore 11 | include .gitattributes -------------------------------------------------------------------------------- /.devcontainer/template-sync.conf: -------------------------------------------------------------------------------- 1 | # Add additional sync excludes for this repo 2 | #exclude .github/do-not-sync 3 | #exclude .flake8 4 | #exclude .gitignore -------------------------------------------------------------------------------- /.devcontainer/template-update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | TEMPDIR=$(mktemp -d) 4 | 5 | cleanup() { 6 | echo "Removing $TEMPDIR" 7 | rm -rf $TEMPDIR 8 | } 9 | trap cleanup EXIT 10 | 11 | git -C $TEMPDIR clone https://github.com/jiuka/checkmk_template.git 12 | 13 | CMD="rsync --archive --cvs-exclude --no-owner --no-group --no-times --verbose" 14 | if [ -e ".devcontainer/template-sync.conf" ]; then 15 | CMD="${CMD} --filter='merge .devcontainer/template-sync.conf'" 16 | fi 17 | if [ -e "${TEMPDIR}/checkmk_template/.devcontainer/template-sync-includes.conf" ]; then 18 | CMD="${CMD} --filter='merge ${TEMPDIR}/checkmk_template/.devcontainer/template-sync-includes.conf'" 19 | fi 20 | CMD="${CMD} --filter='exclude *' ${TEMPDIR}/checkmk_template/ $(pwd)/" 21 | bash -c "$CMD" 22 | 23 | echo $CMD -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | # In .style.yapf and .pylintrc we use 100, but in some cases this isn't enforced. 3 | max-line-length=550 4 | ignore= 5 | ################################################################################################ 6 | # Miscellaneous stuff 7 | ################################################################################################ 8 | ################################################################################################ 9 | # Incompatible with YAPF 10 | ################################################################################################ 11 | # unexpected spaces around keyword / parameter equals 12 | E251, -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior 2 | * text=auto eol=lf -------------------------------------------------------------------------------- /.github/workflows/build-release.yml: -------------------------------------------------------------------------------- 1 | name: build-release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | - '!v*[a-z]' 8 | 9 | jobs: 10 | build-release: 11 | name: Build Release Package 12 | runs-on: ubuntu-latest 13 | container: 14 | image: checkmk/check-mk-raw:2.3.0-latest 15 | permissions: 16 | contents: write 17 | 18 | env: 19 | OMD_ROOT: /omd/sites/cmk 20 | OMD_SITE: cmk 21 | CMK_SITE_ID: cmk 22 | WORKSPACE: ${{ github.workspace }} 23 | 24 | steps: 25 | - name: Initialize Checkmk Site 26 | run: /docker-entrypoint.sh /bin/true 27 | - uses: actions/checkout@v4 28 | - name: Parse Package File 29 | run: | 30 | NAME=$(python3 -c 'print(eval(open("package").read())["name"])') 31 | VERSION=$(python3 -c 'print(eval(open("package").read())["version"])') 32 | echo "CMKPKG_NAME=$NAME" >> "$GITHUB_ENV" 33 | echo "CMKPKG_VERSION=$VERSION" >> "$GITHUB_ENV" 34 | - name: Setup links 35 | run: .devcontainer/symlink.sh 36 | - name: Build Extension 37 | run: | 38 | chown -R cmk:cmk $GITHUB_WORKSPACE 39 | su -l -c "mkp -v package $GITHUB_WORKSPACE/package" cmk 40 | cp /omd/sites/cmk/var/check_mk/packages_local/${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp . 41 | echo "pkgfile=${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp" >> $GITHUB_OUTPUT 42 | id: cmkpkg 43 | - name: Create Release 44 | uses: softprops/action-gh-release@v2 45 | with: 46 | release_name: Release ${{ github.ref }} 47 | draft: false 48 | prerelease: false 49 | files: ${{ steps.cmkpkg.outputs.pkgfile }} 50 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - '**' 7 | tags-ignore: 8 | - 'v*' 9 | pull_request: 10 | 11 | jobs: 12 | build: 13 | name: Build Checkmk package 14 | runs-on: ubuntu-latest 15 | container: 16 | image: checkmk/check-mk-raw:2.3.0-latest 17 | 18 | env: 19 | OMD_ROOT: /omd/sites/cmk 20 | OMD_SITE: cmk 21 | CMK_SITE_ID: cmk 22 | WORKSPACE: ${{ github.workspace }} 23 | 24 | steps: 25 | - name: Initialize Checkmk Site 26 | run: /docker-entrypoint.sh /bin/true 27 | - uses: actions/checkout@v4 28 | - name: Parse Package File 29 | run: | 30 | NAME=$(python3 -c 'print(eval(open("package").read())["name"])') 31 | VERSION=$(python3 -c 'print(eval(open("package").read())["version"])') 32 | echo "CMKPKG_NAME=$NAME" >> "$GITHUB_ENV" 33 | echo "CMKPKG_VERSION=$VERSION" >> "$GITHUB_ENV" 34 | - name: Setup links 35 | run: .devcontainer/symlink.sh 36 | - name: Build Extension 37 | run: | 38 | chown -R cmk:cmk $GITHUB_WORKSPACE 39 | su -l -c "mkp -v package $GITHUB_WORKSPACE/package" cmk 40 | cp /omd/sites/cmk/var/check_mk/packages_local/${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp . 41 | echo "pkgfile=${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp" >> $GITHUB_OUTPUT 42 | id: cmkpkg 43 | - name: Upload artifact 44 | uses: actions/upload-artifact@v4 45 | with: 46 | name: ${{ steps.cmkpkg.outputs.pkgfile }} 47 | path: ${{ steps.cmkpkg.outputs.pkgfile }} 48 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**.py' 7 | - .github/workflows/lint.yml 8 | 9 | jobs: 10 | flake8_py3: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Python 3.12 17 | uses: actions/setup-python@v5 18 | with: 19 | python-version: '3.12' 20 | - name: Install flake8 21 | run: pip install flake8 22 | - name: Run flake8 23 | uses: py-actions/flake8@v2 24 | with: 25 | plugins: "flake8-github" 26 | args: "--format github" -------------------------------------------------------------------------------- /.github/workflows/pytest.yml: -------------------------------------------------------------------------------- 1 | name: pytest 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**.py' 7 | - .github/workflows/pytest.yml 8 | 9 | jobs: 10 | pytest: 11 | 12 | runs-on: ubuntu-latest 13 | container: 14 | image: checkmk/check-mk-raw:2.3.0-latest 15 | 16 | env: 17 | OMD_ROOT: /omd/sites/cmk 18 | OMD_SITE: cmk 19 | CMK_SITE_ID: cmk 20 | WORKSPACE: ${{ github.workspace }} 21 | 22 | steps: 23 | - name: Initialize Checkmk Site 24 | run: /docker-entrypoint.sh /bin/true 25 | - uses: actions/checkout@v4 26 | - name: Setup links 27 | run: .devcontainer/symlink.sh 28 | - name: Install pytest 29 | run: su -l -c "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt pip3 install -r $GITHUB_WORKSPACE/.devcontainer/requirements.txt" cmk 30 | - name: Run pytest 31 | run: | 32 | chown -R cmk:cmk $GITHUB_WORKSPACE $GITHUB_STEP_SUMMARY 33 | su -l -c "cd $GITHUB_WORKSPACE; python3 -m pytest -v --emoji -cov . --md $GITHUB_STEP_SUMMARY " cmk -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.mkp 2 | .coverage 3 | __pycache__ 4 | debug.log -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.linting.flake8Enabled": true, 3 | "python.linting.enabled": true, 4 | "python.testing.pytestArgs": [ 5 | "." 6 | ], 7 | "python.testing.unittestEnabled": false, 8 | "python.testing.pytestEnabled": true, 9 | "files.associations": { 10 | "package": "python" 11 | }, 12 | "python.defaultInterpreterPath": "/omd/sites/cmk/bin/python3" 13 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Install", 8 | "type": "shell", 9 | "command": ".devcontainer/build.sh", 10 | "problemMatcher": [], 11 | "group": { 12 | "kind": "build", 13 | "isDefault": true 14 | } 15 | }, 16 | { 17 | "label": "Start Site", 18 | "type": "shell", 19 | "command": "omd start", 20 | "problemMatcher": [] 21 | }, 22 | { 23 | "label": "Re-Start Site", 24 | "type": "shell", 25 | "command": "omd restart", 26 | "problemMatcher": [] 27 | }, 28 | { 29 | "label": "Stop Site", 30 | "type": "shell", 31 | "command": "omd stop", 32 | "problemMatcher": [] 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Checkmk extension for ... 2 | 3 | ![build](https://github.com/jiuka/checkmk_template/workflows/build/badge.svg) 4 | ![flake8](https://github.com/jiuka/checkmk_template/workflows/Lint/badge.svg) 5 | ![pytest](https://github.com/jiuka/checkmk_template/workflows/pytest/badge.svg) 6 | 7 | ## Description 8 | 9 | This is a template to develop Checkmk Extensions 10 | 11 | ## Development 12 | 13 | For the best development experience use [VSCode](https://code.visualstudio.com/) with the [Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension. This maps your workspace into a checkmk docker container giving you access to the python environment and libraries the installed extension has. 14 | 15 | ## Directories 16 | 17 | The following directories in this repo are getting mapped into the Checkmk site. 18 | 19 | * `agents`, `checkman`, `checks`, `doc`, `inventory`, `notifications`, `pnp-templates`, `web` are mapped into `local/share/check_mk/` 20 | * `agent_based` is mapped to `local/lib/check_mk/base/plugins/agent_based` 21 | * `nagios_plugins` is mapped to `local/lib/nagios/plugins` 22 | 23 | ## Continuous integration 24 | ### Local 25 | 26 | To build the package hit `Crtl`+`Shift`+`B` to execute the build task in VSCode. 27 | 28 | `pytest` can be executed from the terminal or the test ui. 29 | 30 | ### Github Workflow 31 | 32 | The provided Github Workflows run `pytest` and `flake8` in the same checkmk docker conatiner as vscode. 33 | -------------------------------------------------------------------------------- /package: -------------------------------------------------------------------------------- 1 | { 2 | 'author': u'', 3 | 'description': u'', 4 | 'download_url': '', 5 | 'files': { 6 | 'agent_based': [], 7 | 'agents': [], 8 | 'checkman': [], 9 | 'checks': [], 10 | 'doc': [], 11 | 'inventory': [], 12 | 'notifications': [], 13 | 'pnp-templates': [], 14 | 'web': [] 15 | }, 16 | 'name': '', 17 | 'title': u'', 18 | 'version': '0.0.1', 19 | 'version.min_required': '2.0.0', 20 | 'version.packaged': '2.2.0', 21 | 'version.usable_until': '2.3.0', 22 | } --------------------------------------------------------------------------------