Skip to content

Commit

Permalink
Merge pull request #1 from jiuka/cmk23
Browse files Browse the repository at this point in the history
Checkmk 2.3.0 Support
  • Loading branch information
jiuka authored May 31, 2024
2 parents 0053dc8 + a3ddc7f commit b1e6e12
Show file tree
Hide file tree
Showing 24 changed files with 523 additions and 438 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/ubuntu/.devcontainer/base.Dockerfile

# [Choice] CheckMK version: 2.2.0-latest
ARG VARIANT="2.2.0-latest"
# [Choice] CheckMK version: 2.3.0-latest
ARG VARIANT="2.3.0-latest"
FROM checkmk/check-mk-raw:${VARIANT}

RUN /docker-entrypoint.sh /bin/true
Expand Down
14 changes: 2 additions & 12 deletions .devcontainer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

NAME=$(python3 -c 'print(eval(open("package").read())["name"])')
VERSION=$(python3 -c 'print(eval(open("package").read())["version"])')
rm -f $NAME-$VERSION.mkp \
/omd/sites/cmk/var/cat check_mk/packages/${NAME}-*.mkp \
rm /omd/sites/cmk/var/check_mk/packages/${NAME} \
/omd/sites/cmk/var/check_mk/packages_local/${NAME}-*.mkp ||:

mkp -v package package 2>&1 | sed '/Installing$/Q' ||:

cp /omd/sites/cmk/var/check_mk/packages_local/$NAME-$VERSION.mkp .

mkp inspect $NAME-$VERSION.mkp

# Set Outputs for GitHub Workflow steps
if [ -n "$GITHUB_WORKSPACE" ]; then
echo "pkgfile=${NAME}-${VERSION}.mkp" >> $GITHUB_OUTPUT
echo "pkgname=${NAME}" >> $GITHUB_OUTPUT
echo "pkgversion=$VERSION" >> $GITHUB_OUTPUT
fi
mkp inspect /omd/sites/cmk/var/check_mk/packages_local/$NAME-$VERSION.mkp
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Ubuntu version: focal, bionic
"args": { "VARIANT": "2.2.0-latest" }
"args": { "VARIANT": "2.3.0-latest" }
},

"customizations": {
Expand All @@ -29,7 +29,9 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/symlink.sh",
//"postCreateCommand": ".devcontainer/symlink.sh",
"workspaceMount": "source=${localWorkspaceFolder},target=/omd/sites/cmk/local/lib/python3/cmk_addons/plugins/jb_fls,type=bind,consistency=cached",
"workspaceFolder": "/omd/sites/cmk/local/lib/python3/cmk_addons/plugins/jb_fls",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "cmk",
Expand Down
12 changes: 0 additions & 12 deletions .devcontainer/symlink.sh

This file was deleted.

1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buy_me_a_coffee: jiuka
33 changes: 18 additions & 15 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,33 @@ jobs:
name: Build Release Package
runs-on: ubuntu-latest
container:
image: checkmk/check-mk-raw:2.2.0-latest
image: checkmk/check-mk-raw:2.3.0-latest
permissions:
contents: write

env:
OMD_ROOT: /omd/sites/cmk
OMD_SITE: cmk
CMK_SITE_ID: cmk
WORKSPACE: ${{ github.workspace }}

steps:
- name: Initialize Checkmk Site
run: /docker-entrypoint.sh /bin/true
- uses: actions/checkout@v3
- name: Setup links
run: .devcontainer/symlink.sh
- name: Update GITHUB_PATH
run: echo "/omd/sites/cmk/bin" >> $GITHUB_PATH
- uses: actions/checkout@v4
- name: Parse Package File
run: |
NAME=$(python3 -c 'print(eval(open("package").read())["name"])')
VERSION=$(python3 -c 'print(eval(open("package").read())["version"])')
echo "CMKPKG_NAME=$NAME" >> "$GITHUB_ENV"
echo "CMKPKG_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Install Plugin
run: |
rsync -aC --chown=cmk:cmk $GITHUB_WORKSPACE/ /omd/sites/cmk/local/lib/python3/cmk_addons/plugins/$CMKPKG_NAME/
- name: Build Extension
run: .devcontainer/build.sh
run: |
su -l -c "mkp -v package $GITHUB_WORKSPACE/package" cmk
cp /omd/sites/cmk/var/check_mk/packages_local/${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp .
echo "pkgfile=${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp" >> $GITHUB_OUTPUT
echo "pkgname=${CMKPKG_NAME}" >> $GITHUB_OUTPUT
echo "pkgversion=${CMKPKG_VERSION}" >> $GITHUB_OUTPUT
id: cmkpkg

- name: Create Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
release_name: Release ${{ github.ref }}
draft: false
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@ jobs:
name: Build Checkmk package
runs-on: ubuntu-latest
container:
image: checkmk/check-mk-raw:2.2.0-latest

env:
OMD_ROOT: /omd/sites/cmk
OMD_SITE: cmk
CMK_SITE_ID: cmk
WORKSPACE: ${{ github.workspace }}
image: checkmk/check-mk-raw:2.3.0-latest

steps:
- name: Initialize Checkmk Site
run: /docker-entrypoint.sh /bin/true
- uses: actions/checkout@v3
- name: Setup links
run: .devcontainer/symlink.sh
- name: Update GITHUB_PATH
run: echo "/omd/sites/cmk/bin" >> $GITHUB_PATH
- uses: actions/checkout@v4
- name: Parse Package File
run: |
NAME=$(python3 -c 'print(eval(open("package").read())["name"])')
VERSION=$(python3 -c 'print(eval(open("package").read())["version"])')
echo "CMKPKG_NAME=$NAME" >> "$GITHUB_ENV"
echo "CMKPKG_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Install Plugin
run: |
rsync -aC --chown=cmk:cmk $GITHUB_WORKSPACE/ /omd/sites/cmk/local/lib/python3/cmk_addons/plugins/$CMKPKG_NAME/
- name: Build Extension
run: .devcontainer/build.sh
run: |
su -l -c "mkp -v package $GITHUB_WORKSPACE/package" cmk
cp /omd/sites/cmk/var/check_mk/packages_local/${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp .
echo "pkgfile=${CMKPKG_NAME}-${CMKPKG_VERSION}.mkp" >> $GITHUB_OUTPUT
echo "pkgname=${CMKPKG_NAME}" >> $GITHUB_OUTPUT
echo "pkgversion=${CMKPKG_VERSION}" >> $GITHUB_OUTPUT
id: cmkpkg
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.cmkpkg.outputs.pkgfile }}
path: ${{ steps.cmkpkg.outputs.pkgfile }}
10 changes: 6 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ on:
push:
paths:
- '**.py'
- .github/workflows/lint.yml


jobs:
flake8_py3:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.12'
- name: Install flake8
run: pip install flake8
- name: Run flake8
Expand Down
40 changes: 21 additions & 19 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
name: pytest

on:
push: []
push:
paths:
- '**.py'
- .github/workflows/pytest.yml

jobs:
pytest:

runs-on: ubuntu-latest
container:
image: checkmk/check-mk-raw:2.2.0-latest

env:
OMD_ROOT: /omd/sites/cmk
OMD_SITE: cmk
CMK_SITE_ID: cmk
WORKSPACE: ${{ github.workspace }}
image: checkmk/check-mk-raw:2.3.0-latest

steps:
- name: Initialize Checkmk Site
run: /docker-entrypoint.sh /bin/true
- uses: actions/checkout@v3
- name: Setup links
run: ./.devcontainer/symlink.sh
- name: Install pytest
run: su -l -c "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt pip3 install -r $GITHUB_WORKSPACE/.devcontainer/requirements.txt" cmk
- name: Update GITHUB_PATH
run: echo "/omd/sites/cmk/bin" >> $GITHUB_PATH
- name: Run pytest
run: python3 -m pytest
- name: Initialize Checkmk Site
run: /docker-entrypoint.sh /bin/true
- uses: actions/checkout@v4
- name: Parse Package File
run: |
NAME=$(python3 -c 'print(eval(open("package").read())["name"])')
VERSION=$(python3 -c 'print(eval(open("package").read())["version"])')
echo "CMKPKG_NAME=$NAME" >> "$GITHUB_ENV"
echo "CMKPKG_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Install Plugin
run: |
rsync -aC --chown=cmk:cmk $GITHUB_WORKSPACE/ /omd/sites/cmk/local/lib/python3/cmk_addons/plugins/$CMKPKG_NAME/
- name: Install pytest
run: su -l -c "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt pip3 install -r $GITHUB_WORKSPACE/.devcontainer/requirements.txt" cmk
- name: Run pytest
run: su -l -c "python3 -m pytest /omd/sites/cmk/local/lib/python3/cmk_addons/plugins/$CMKPKG_NAME/" cmk
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ For the best development experience use [VSCode](https://code.visualstudio.com/)

## Directories

The following directories in this repo are getting mapped into the Checkmk site.

* `agents`, `checkman`, `checks`, `doc`, `inventory`, `notifications`, `pnp-templates`, `web` are mapped into `local/share/check_mk/`
* `agent_based` is mapped to `local/lib/check_mk/base/plugins/agent_based`
* `nagios_plugins` is mapped to `local/lib/nagios/plugins`
The repository is mounted into `/omd/sites/cmk/local/lib/python3/cmk_addons/plugins/jb_fls`

## Continuous integration
### Local
Expand Down
33 changes: 23 additions & 10 deletions agent_based/jb_fls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# jb_fls - JetBrains Floatingcheck
#
# Copyright (C) 2020 Marius Rieder <marius.rieder@durchmesser.ch>
# Copyright (C) 2020-2024 Marius Rieder <marius.rieder@durchmesser.ch>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -21,17 +21,26 @@


import datetime
from .agent_based_api.v1 import (
check_levels,
register,
from collections.abc import Mapping

from cmk.agent_based.v1 import check_levels
from cmk.agent_based.v2 import (
AgentSection,
CheckPlugin,
CheckResult,
DiscoveryResult,
render,
Result,
Service,
State,
StringTable,
)


def parse_jb_fls(string_table):
_Section = Mapping[str, str | tuple[str, str]]


def parse_jb_fls(string_table: StringTable) -> _Section:
parsed = {'connection': []}
for line in string_table:
if line[0] == 'connection':
Expand All @@ -41,18 +50,22 @@ def parse_jb_fls(string_table):
return parsed


register.agent_section(
name='jb_fls',
agent_section_jb_fls = AgentSection(
name="jb_fls",
parse_function=parse_jb_fls,
)


def discovery_jb_fls(section):
def discovery_jb_fls(section: _Section) -> DiscoveryResult:
if 'serverUID' in section:
yield Service()


def check_jb_fls(params, section):
def check_jb_fls(params, section: _Section) -> CheckResult:
if 'serverUID' not in section:
yield Result(state=State.UNKNOWN, summary='Server: %s not found' % (section.get('url')))
return

yield Result(state=State.OK, summary='Server: %s %s ' % (section.get('serverUID', 'Unknown'), section.get('url')))

if section.get('health', 500) != '200':
Expand Down Expand Up @@ -80,7 +93,7 @@ def check_jb_fls(params, section):
)


register.check_plugin(
check_plugin_jb_fls = CheckPlugin(
name='jb_fls',
service_name='JB FLS',
discovery_function=discovery_jb_fls,
Expand Down
Loading

0 comments on commit b1e6e12

Please sign in to comment.