Skip to content

Commit 0a122e7

Browse files
committed
Merge branch 'checkmk_24_dnf5'
2 parents 6920bb6 + a578856 commit 0a122e7

21 files changed

Lines changed: 485 additions & 199 deletions

File tree

.github/workflows/build-release-latest.yml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,40 @@ on:
55
branches: '*'
66

77
jobs:
8-
build-package:
8+
build-image:
99
runs-on: ubuntu-latest
10+
outputs:
11+
image: ${{ steps.get_image.outputs.IMAGE }}
1012
steps:
1113
- uses: actions/checkout@v4
14+
# docker login is needed for pushing the test image
15+
- uses: docker/login-action@v3
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.actor }}
19+
password: ${{ secrets.GITHUB_TOKEN }}
20+
- id: get_hash
21+
run: echo "HASH=$(find mkp -type f -printf '%p:%s' | xargs | md5sum | cut -d\ -f1)" >> $GITHUB_OUTPUT
22+
- id: get_image
23+
run: echo "IMAGE=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]'):${{ steps.get_hash.outputs.HASH }}" >> $GITHUB_OUTPUT
24+
- run: echo "image ${{ steps.get_image.outputs.IMAGE }}"
1225
# build container image for package creation
13-
- run: /usr/bin/docker build -t ${{ github.job }} -f build/Dockerfile .
14-
# actually build .mkp file
15-
- run: /usr/bin/docker run --volume $PWD:/source ${{ github.job }}
26+
- run: docker pull ${{ steps.get_image.outputs.IMAGE }} || docker build -t ${{ steps.get_image.outputs.IMAGE }} -f dockerfiles/checkmk/Dockerfile .
27+
- run: docker push ${{ steps.get_image.outputs.IMAGE }}
28+
29+
build-package:
30+
runs-on: ubuntu-latest
31+
needs: build-image
32+
container:
33+
image: ${{ needs.build-image.outputs.image }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
# use script
37+
- run: build-mkp.sh
1638
# upload results
1739
- uses: actions/upload-artifact@v4
1840
with:
19-
path: ./*.mkp
41+
path: ./mkp/*.mkp
2042
retention-days: 1
2143

2244
github-release:
@@ -32,4 +54,13 @@ jobs:
3254
automatic_release_tag: "latest"
3355
prerelease: true
3456
files: |
35-
artifact/*
57+
artifact/*
58+
59+
# ghcr.io-cleanup:
60+
# - name: ghcr.io cleanup action
61+
# runs-on: ubuntu-latest
62+
# steps:
63+
# - uses: dataaxiom/ghcr-cleanup-action@v1
64+
# with:
65+
# older-than: 7 days
66+
# keep-n-tagged: 1

.github/workflows/build-release-stable.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,40 @@ on:
44
tags: 'v*'
55

66
jobs:
7-
build-package:
7+
build-image:
88
runs-on: ubuntu-latest
9+
outputs:
10+
image: ${{ steps.get_image.outputs.IMAGE }}
911
steps:
1012
- uses: actions/checkout@v4
13+
# docker login is needed for pushing the test image
14+
- uses: docker/login-action@v3
15+
with:
16+
registry: ghcr.io
17+
username: ${{ github.actor }}
18+
password: ${{ secrets.GITHUB_TOKEN }}
19+
- id: get_hash
20+
run: echo "HASH=$(find mkp -type f -printf '%p:%s' | xargs | md5sum | cut -d\ -f1)" >> $GITHUB_OUTPUT
21+
- id: get_image
22+
run: echo "IMAGE=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]'):${{ steps.get_hash.outputs.HASH }}" >> $GITHUB_OUTPUT
23+
- run: echo "image ${{ steps.get_image.outputs.IMAGE }}"
1124
# build container image for package creation
12-
- run: /usr/bin/docker build -t ${{ github.job }} -f build/Dockerfile .
13-
# actually build .mkp file
14-
- run: /usr/bin/docker run --volume $PWD:/source ${{ github.job }}
25+
- run: docker pull ${{ steps.get_image.outputs.IMAGE }} || docker build -t ${{ steps.get_image.outputs.IMAGE }} -f dockerfiles/checkmk/Dockerfile .
26+
- run: docker push ${{ steps.get_image.outputs.IMAGE }}
27+
28+
build-package:
29+
runs-on: ubuntu-latest
30+
needs: build-image
31+
container:
32+
image: ${{ needs.build-image.outputs.image }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
# use script
36+
- run: build-mkp.sh
1537
# upload results
1638
- uses: actions/upload-artifact@v4
1739
with:
18-
path: ./*.mkp
40+
path: ./mkp/*.mkp
1941
retention-days: 1
2042

2143
github-release:

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,25 @@ Inspired by https://github.com/lgbff/lgb_check_mk_plugins/tree/master/aptng.
66

77
See [https://docs.checkmk.com/latest/de/mkps.html#H1:Installation,%20Update%20and%20Removal](https://docs.checkmk.com/latest/de/mkps.html#H1:Installation,%20Update%20and%20Removal) for details on Check_MK package management.
88

9-
Now built by GitHub Actions.
9+
Now built by GitHub Actions.
10+
11+
12+
## 🛠️ Development
13+
14+
A local Checkmk with the check plugin integrated can be run via `docker-compose.yml`. Connect to it via browsing to
15+
URL [http://localhost:5000/cmk/check_mk/index.py](http://localhost:5000/cmk/check_mk/index.py)
16+
17+
This setup comes with a preconfigured site `cmk` and user `cmkadmin` with password `cmkadmin`. Aside the **checkmk**
18+
container a **client** container is running, which can be used for testing.
19+
20+
### 📃 Logging of bakery jobs
21+
22+
When debugging inside the container **checkmk**: `tail -f /omd/sites/cmk/var/log/ui-job-scheduler/*`
23+
24+
### 🏗️ Building
25+
26+
To build the package manually, run:
27+
28+
```bash
29+
docker run -it --rm --volume $PWD:/source --workdir /source checkmk-yum build-mkp.sh
30+
```

build/Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

build/build-entrypoint.sh

Lines changed: 0 additions & 45 deletions
This file was deleted.

docker-compose.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
services:
2+
checkmk:
3+
# feature equivalent to enterprise edition but just 30 days trial
4+
# nice to check extension GUI stuff
5+
image: checkmk-yum
6+
build:
7+
context: .
8+
dockerfile: dockerfiles/checkmk/Dockerfile
9+
args:
10+
CHECKMK_VERSION: 2.4.0p20
11+
CMK_PASSWORD: cmkadmin
12+
CMK_SITE_ID: cmk
13+
restart: unless-stopped
14+
ports:
15+
- 5000:5000
16+
environment:
17+
TZ: Europe/Berlin
18+
volumes:
19+
# meta-info about package for Checkmk extensions management
20+
- ${PWD}/mkp/var/check_mk/packages/yum:/omd/sites/cmk/var/check_mk/packages/yum
21+
# agent plugin to run on monitored hosts
22+
- ${PWD}/mkp/local/share/check_mk/agents/plugins/yum:/omd/sites/cmk/local/share/check_mk/agents/plugins/yum
23+
# bakery - not fully upgraded to the new layout in Checkmk 2.4 itself
24+
- ${PWD}/mkp/local/lib/python3/cmk/base/cee/plugins/bakery/yum.py:/omd/sites/cmk/local/lib/python3/cmk/base/cee/plugins/bakery/yum.py
25+
# already updated part of plugin
26+
- ${PWD}/mkp/local/lib/python3/cmk_addons/plugins/yum:/omd/sites/cmk/local/lib/python3/cmk_addons/plugins/yum
27+
28+
client-rocky-8:
29+
# client for testing, can be added in web GUI
30+
image: checkmk-client-rocky-8
31+
build:
32+
context: dockerfiles/client
33+
dockerfile: Dockerfile_rocky-8
34+
restart: unless-stopped
35+
environment:
36+
# check_mk_agent needs to know where to store its state
37+
MK_VARDIR: /var/lib/check_mk_agent
38+
post_start:
39+
# check_mk_agent requires executable plugins
40+
- command: /usr/bin/chmod -R +x /usr/lib/check_mk_agent/plugins
41+
volumes:
42+
- ${PWD}/mkp/local/share/check_mk/agents/plugins:/usr/lib/check_mk_agent/plugins
43+
44+
client-fedora-43:
45+
# client for testing, can be added in web GUI
46+
image: checkmk-client-fedora-43
47+
build:
48+
context: dockerfiles/client
49+
dockerfile: Dockerfile_fedora-43
50+
restart: unless-stopped
51+
environment:
52+
# check_mk_agent needs to know where to store its state
53+
MK_VARDIR: /var/lib/check_mk_agent
54+
post_start:
55+
# check_mk_agent requires executable plugins
56+
- command: /usr/bin/chmod -R +x /usr/lib/check_mk_agent/plugins
57+
volumes:
58+
- ${PWD}/mkp/local/share/check_mk/agents/plugins:/usr/lib/check_mk_agent/plugins

dockerfiles/checkmk/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARG CHECKMK_VERSION=2.4.0p19
2+
3+
FROM checkmk/check-mk-cloud:${CHECKMK_VERSION}
4+
LABEL maintainer=henri@nagstamon.de
5+
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
ARG CMK_PASSWORD=cmkadmin
8+
ARG CMK_SITE_ID=cmk
9+
10+
# python3 and git needed for modify-extension.py
11+
RUN apt -y update && \
12+
apt -y install less \
13+
python3 \
14+
python3-git \
15+
vim
16+
17+
# scripts used need to be executable
18+
COPY dockerfiles/checkmk/modify-extension.py /usr/local/bin
19+
RUN chmod +x /usr/local/bin/modify-extension.py
20+
COPY dockerfiles/checkmk/build-mkp.sh /usr/local/bin
21+
RUN chmod +x /usr/local/bin/build-mkp.sh
22+
23+
# Create site 'cmk'
24+
RUN omd create --admin-password "${CMK_PASSWORD}" "${CMK_SITE_ID}"
25+
# seems to avoid crying about tmpfs in container being not allowd
26+
RUN omd config cmk set TMPFS off
27+
# configure to be available for local debugging
28+
RUN omd config cmk set APACHE_TCP_ADDR 0.0.0.0

dockerfiles/checkmk/build-mkp.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CMK="/omd/sites/cmk"
5+
SU="su - cmk -c"
6+
WORKDIR="${PWD:-$(pwd)}"
7+
8+
# Copy local extension sources into the Check_MK local directory
9+
cp -r mkp/local/* "${CMK}/local"
10+
11+
# Create temporary directory as the cmk user
12+
$SU "mkdir -p ${CMK}/tmp/check_mk"
13+
14+
# Create mkp template (runs as cmk user)
15+
$SU "mkp template yum"
16+
17+
# Mark repo safe for git (needed when running as different user)
18+
git config --global --add safe.directory "${WORKDIR}"
19+
20+
# Run the extension modifier script to produce a manifest template
21+
modify-extension.py "${WORKDIR}" "${CMK}/tmp/check_mk/yum.manifest.temp"
22+
23+
# Fix permissions to avoid Permission denied during mkp package
24+
chmod go+rw "${CMK}/local/lib/python3/cmk/base/cee/plugins/bakery"
25+
chmod go+rw "${CMK}/local/lib/python3/cmk_addons/plugins/yum/agent_based"
26+
chmod go+rw "${CMK}/local/lib/python3/cmk_addons/plugins/yum/checkman"
27+
chmod go+rw "${CMK}/local/lib/python3/cmk_addons/plugins/yum/rulesets"
28+
29+
# Show generated manifest and build the mkp package (runs as cmk user)
30+
cat "${CMK}/tmp/check_mk/yum.manifest.temp"
31+
$SU "mkp package ${CMK}/tmp/check_mk/yum.manifest.temp"
32+
33+
# Copy created mkp back to the workspace
34+
mkdir -p "${WORKDIR}/mkp"
35+
cp "${CMK}/var/check_mk/packages_local/"*.mkp "${WORKDIR}/mkp/"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141

4242
# modify package config
4343
package_config['author'] = 'Henri Wahl'
44-
package_config['description'] = 'Checks for updates on RPM-based distributions via yum.'
44+
package_config['description'] = 'Checks for updates on RPM-based distributions via yum/dnf.'
4545
package_config['download_url'] = 'https://github.com/HenriWahl/checkmk-agent-plugin-yum/releases'
4646
package_config['title'] = 'YUM Update Check'
4747
package_config['version'] = version
48-
package_config['version.min_required'] = '2.0.0'
48+
package_config['version.min_required'] = '2.3.0'
4949

5050
# write package config file
5151
bla = pformat(package_config, indent=4)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM fedora:43
2+
3+
COPY check-mk-agent*.rpm /tmp/
4+
5+
RUN dnf -y install iproute \
6+
lsof \
7+
nmap-ncat \
8+
procps-ng
9+
10+
RUN dnf -y install /tmp/*.rpm && \
11+
rm -f /tmp/check-mk-agent*.rpm
12+
13+
EXPOSE 6556/tcp
14+
CMD ["nc", "-l", "6556", "-k", "-e", "/usr/bin/check_mk_agent"]

0 commit comments

Comments
 (0)