Compare commits
57 Commits
b28feea59f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
868b78f476 | ||
| 066033a4d6 | |||
| e4726a478e | |||
| 3668563736 | |||
| d750ad84a5 | |||
|
|
ae4e83dafe | ||
| fcbd2c5452 | |||
| 039531ce7b | |||
| 91fe69a0a2 | |||
| 81af16cedf | |||
| 03be79d149 | |||
| 1112e15d80 | |||
| 0c86b453a6 | |||
| 882755ffc8 | |||
| 2854955c74 | |||
| fa06beefdd | |||
| d7f1052305 | |||
| 8ab7ff54b9 | |||
| 993104e122 | |||
| 44a3bc1cf4 | |||
| 44b4aa9e7a | |||
| 7986278926 | |||
| a1752e68c7 | |||
| f3ac36a139 | |||
| f95de88005 | |||
| 9f2e966662 | |||
| baf814e0e5 | |||
|
|
0722d1942f | ||
| 1119a38496 | |||
| 91afa98d6b | |||
| f3ce93f8b1 | |||
| 7bb7bfc3a5 | |||
| 5e70da801f | |||
| 7b0392a98c | |||
|
|
bb33667302 | ||
| ead031ac44 | |||
|
|
a41dbfeed3 | ||
| 8ccc13c7bb | |||
| 5e685381cb | |||
| 4b8c91d957 | |||
| 089935525b | |||
| 17fc3cdbb8 | |||
| a39a23597c | |||
| ebf3b5b9dd | |||
| d980f67ee4 | |||
| 8efb9ecb08 | |||
| 4aea91ce6e | |||
| 7e1b131dba | |||
| f8576b1b5f | |||
| c99b2b6c13 | |||
| e64bdef6d9 | |||
| f07025ba40 | |||
| 050c9ee235 | |||
| 91e0fe6180 | |||
| c731d61550 | |||
| cfb5f0b4e6 | |||
| cda7a45371 |
203
.gitea/workflows/build.yaml
Normal file
203
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
name: Zabbix APK Builder
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Trigger on pushes to main/test branch into the zabbix-apk-builder directory
|
||||||
|
push:
|
||||||
|
branches: [ main, test ]
|
||||||
|
paths: [ 'zabbix-apk-builder/**' ]
|
||||||
|
|
||||||
|
# Scheduled runs at 06:00 UTC daily
|
||||||
|
schedule:
|
||||||
|
- cron: '0 6 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# Skip the execution if the commit author is the bot itself to prevent loops
|
||||||
|
if: ${{ gitea.event.head_commit.author.name != 'Gitea Action' }}
|
||||||
|
outputs:
|
||||||
|
should_build: ${{ steps.version-check.outputs.should_build }}
|
||||||
|
latest_version: ${{ steps.version-check.outputs.latest_version }}
|
||||||
|
current_version: ${{ steps.version-check.outputs.current_version }}
|
||||||
|
is_push_trigger: ${{ steps.version-check.outputs.is_push_trigger }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check for new Zabbix version
|
||||||
|
id: version-check
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Remove jq installation
|
||||||
|
# apt-get update && apt-get install -y jq
|
||||||
|
|
||||||
|
# Detect trigger type
|
||||||
|
IS_PUSH="${{ gitea.event_name == 'push' }}"
|
||||||
|
echo "is_push_trigger=${IS_PUSH}" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
# Get versions
|
||||||
|
CURRENT_VERSION=$(grep '^pkgver=' zabbix-apk-builder/APKBUILD | cut -d'=' -f2)
|
||||||
|
LATEST_VERSION=$(curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
||||||
|
grep -o '"displayId":"[^"]*"' | cut -d'"' -f4 | \
|
||||||
|
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | grep -v 'rc\|beta\|alpha' | \
|
||||||
|
sort -V | tail -1)
|
||||||
|
|
||||||
|
echo "current_version=${CURRENT_VERSION}" >> "${GITHUB_OUTPUT}"
|
||||||
|
echo "latest_version=${LATEST_VERSION}" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
# Always build on push, build on schedule if versions differ
|
||||||
|
if [[ "${IS_PUSH}" == "true" || "${CURRENT_VERSION}" != "${LATEST_VERSION}" ]]; then
|
||||||
|
echo "should_build=true" >> "${GITHUB_OUTPUT}"
|
||||||
|
else
|
||||||
|
echo "should_build=false" >> "${GITHUB_OUTPUT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
update-version:
|
||||||
|
needs: check-version
|
||||||
|
# Only update version during scheduled runs when new version is available
|
||||||
|
if: ${{ needs.check-version.outputs.should_build == 'true' && needs.check-version.outputs.is_push_trigger == 'false' && needs.check-version.outputs.current_version != needs.check-version.outputs.latest_version }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Update APKBUILD version
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
LATEST_VERSION="${{ needs.check-version.outputs.latest_version }}"
|
||||||
|
CURRENT_VERSION="${{ needs.check-version.outputs.current_version }}"
|
||||||
|
|
||||||
|
echo "Updating APKBUILD from ${CURRENT_VERSION} to ${LATEST_VERSION}"
|
||||||
|
|
||||||
|
# Update pkgver
|
||||||
|
sed -i "s/^pkgver=.*/pkgver=${LATEST_VERSION}/" zabbix-apk-builder/APKBUILD
|
||||||
|
|
||||||
|
# Reset pkgrel to 0 for new version
|
||||||
|
sed -i "s/^pkgrel=.*/pkgrel=0/" zabbix-apk-builder/APKBUILD
|
||||||
|
|
||||||
|
# Clear checksums (will be regenerated during build)
|
||||||
|
sed -i 's/^sha512sums=.*/sha512sums="SKIP"/' zabbix-apk-builder/APKBUILD
|
||||||
|
|
||||||
|
# Commit changes with [ci skip] to prevent recursive triggers
|
||||||
|
git config --local user.email "action@gitea.com"
|
||||||
|
git config --local user.name "Gitea Action"
|
||||||
|
git add zabbix-apk-builder/APKBUILD
|
||||||
|
git commit -m "AUTO: Update Zabbix to version ${LATEST_VERSION} [ci skip]" || exit 0
|
||||||
|
git push
|
||||||
|
|
||||||
|
build-packages:
|
||||||
|
# Build packages after version update (for scheduled runs) or immediately (for push runs)
|
||||||
|
needs: [check-version, update-version]
|
||||||
|
# Run if should_build=true AND either update-version ran successfully OR it was skipped due to push trigger
|
||||||
|
if: ${{ needs.check-version.outputs.should_build == 'true' && (success() || needs.check-version.outputs.is_push_trigger == 'true') }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Use token to ensure we get the latest version if it was updated
|
||||||
|
token: ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
ref: ${{ gitea.ref }}
|
||||||
|
|
||||||
|
- name: Verify build environment
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "=== Build Environment ==="
|
||||||
|
echo "Trigger type: ${{ gitea.event_name }}"
|
||||||
|
echo "Current branch: $(git branch --show-current)"
|
||||||
|
echo "APKBUILD version: $(grep '^pkgver=' zabbix-apk-builder/APKBUILD | cut -d'=' -f2)"
|
||||||
|
echo "Target version: ${{ needs.check-version.outputs.latest_version }}"
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build Zabbix packages
|
||||||
|
env:
|
||||||
|
CI_RUN_ID: ${{ gitea.run_id }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd zabbix-apk-builder
|
||||||
|
chmod +x build.sh
|
||||||
|
./build.sh
|
||||||
|
|
||||||
|
- name: Verify and list built packages
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd zabbix-apk-builder
|
||||||
|
|
||||||
|
# Verify packages exist somewhere
|
||||||
|
PACKAGE_COUNT=$(find packages -name "*.apk" | wc -l)
|
||||||
|
|
||||||
|
if [[ $PACKAGE_COUNT -eq 0 ]]; then
|
||||||
|
echo "ERROR: No packages found"
|
||||||
|
find packages -type f 2>/dev/null || echo "packages directory is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Found $PACKAGE_COUNT packages:"
|
||||||
|
find packages -name "*.apk" -exec ls -lh {} \;
|
||||||
|
|
||||||
|
- name: Upload packages as artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: zabbix-apk-packages-${{ gitea.run_number }}
|
||||||
|
path: zabbix-apk-builder/packages/**/*.apk
|
||||||
|
retention-days: 30
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
deploy-test:
|
||||||
|
needs: [check-version, build-packages]
|
||||||
|
if: ${{ needs.check-version.outputs.should_build == 'true' && contains(gitea.ref, 'test') }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download packages
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: zabbix-apk-packages-${{ gitea.run_number }}
|
||||||
|
path: packages/
|
||||||
|
|
||||||
|
- name: Test deployment in Alpine container
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Find packages
|
||||||
|
AGENT_PKG=$(find packages -name "zabbix-agent-*.apk" | head -1)
|
||||||
|
PROXY_PKG=$(find packages -name "zabbix-proxy-*.apk" | head -1)
|
||||||
|
|
||||||
|
# Test function
|
||||||
|
test_package() {
|
||||||
|
local pkg="$1"
|
||||||
|
local binary="$2"
|
||||||
|
|
||||||
|
if [[ -f "$pkg" ]]; then
|
||||||
|
echo "Testing $(basename "$pkg")..."
|
||||||
|
CONTAINER_ID=$(docker run -d alpine:latest sleep 30)
|
||||||
|
docker cp "$pkg" "$CONTAINER_ID:/$(basename "$pkg")"
|
||||||
|
if docker exec "$CONTAINER_ID" sh -c "
|
||||||
|
apk add --allow-untrusted /$(basename "$pkg") >/dev/null 2>&1
|
||||||
|
which $binary >/dev/null 2>&1
|
||||||
|
$binary --version >/dev/null 2>&1
|
||||||
|
"; then
|
||||||
|
echo "SUCCESS: $(basename "$pkg") test passed"
|
||||||
|
else
|
||||||
|
echo "FAIL: $(basename "$pkg") test failed"
|
||||||
|
fi
|
||||||
|
docker rm -f "$CONTAINER_ID" >/dev/null
|
||||||
|
else
|
||||||
|
echo "ERROR: Package not found: $pkg"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_package "$AGENT_PKG" "zabbix_agentd"
|
||||||
|
test_package "$PROXY_PKG" "zabbix_proxy"
|
||||||
234
zabbix-apk-builder/.github/workflows/build.yml
vendored
234
zabbix-apk-builder/.github/workflows/build.yml
vendored
@@ -1,234 +0,0 @@
|
|||||||
name: Zabbix APK Builder
|
|
||||||
|
|
||||||
on:
|
|
||||||
# Manual trigger
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
force_build:
|
|
||||||
description: 'Force build even if version unchanged'
|
|
||||||
required: false
|
|
||||||
default: 'false'
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
# Scheduled check for new versions (daily at 6 AM UTC)
|
|
||||||
schedule:
|
|
||||||
- cron: '0 6 * * *'
|
|
||||||
|
|
||||||
# Trigger on pushes to main/test branch
|
|
||||||
push:
|
|
||||||
branches: [ main, test ]
|
|
||||||
paths: [ 'APKBUILD', 'Dockerfile', 'build.sh', '*.initd', '*.confd' ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check-version:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
should_build: ${{ steps.version-check.outputs.should_build }}
|
|
||||||
latest_version: ${{ steps.version-check.outputs.latest_version }}
|
|
||||||
current_version: ${{ steps.version-check.outputs.current_version }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Check for new Zabbix version
|
|
||||||
id: version-check
|
|
||||||
run: |
|
|
||||||
# Get current version from APKBUILD
|
|
||||||
CURRENT_VERSION=$(grep '^pkgver=' APKBUILD | cut -d'=' -f2)
|
|
||||||
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "Current version: $CURRENT_VERSION"
|
|
||||||
|
|
||||||
# Get latest version from Zabbix Bitbucket API (stable releases only)
|
|
||||||
LATEST_VERSION=$(curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
|
||||||
jq -r '.values[].displayId' | \
|
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
|
|
||||||
grep -v 'rc\|beta\|alpha' | \
|
|
||||||
sort -V | \
|
|
||||||
tail -1)
|
|
||||||
|
|
||||||
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "Latest version: $LATEST_VERSION"
|
|
||||||
|
|
||||||
# Determine if we should build
|
|
||||||
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ] || [ "${{ inputs.force_build }}" = "true" ]; then
|
|
||||||
echo "should_build=true" >> $GITHUB_OUTPUT
|
|
||||||
echo "Build required: Version changed or force build requested"
|
|
||||||
else
|
|
||||||
echo "should_build=false" >> $GITHUB_OUTPUT
|
|
||||||
echo "No build required: Version unchanged"
|
|
||||||
fi
|
|
||||||
|
|
||||||
update-version:
|
|
||||||
needs: check-version
|
|
||||||
if: needs.check-version.outputs.should_build == 'true'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Update APKBUILD version
|
|
||||||
run: |
|
|
||||||
LATEST_VERSION="${{ needs.check-version.outputs.latest_version }}"
|
|
||||||
CURRENT_VERSION="${{ needs.check-version.outputs.current_version }}"
|
|
||||||
|
|
||||||
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
|
|
||||||
echo "Updating APKBUILD from $CURRENT_VERSION to $LATEST_VERSION"
|
|
||||||
|
|
||||||
# Update pkgver
|
|
||||||
sed -i "s/^pkgver=.*/pkgver=$LATEST_VERSION/" APKBUILD
|
|
||||||
|
|
||||||
# Reset pkgrel to 0 for new version
|
|
||||||
sed -i "s/^pkgrel=.*/pkgrel=0/" APKBUILD
|
|
||||||
|
|
||||||
# Clear checksums (will be regenerated during build)
|
|
||||||
sed -i '/^sha512sums="/,/^"$/c\sha512sums="\nSKIP\nSKIP\nSKIP\nSKIP\nSKIP\n"' APKBUILD
|
|
||||||
|
|
||||||
# Commit changes
|
|
||||||
git config --local user.email "action@github.com"
|
|
||||||
git config --local user.name "GitHub Action"
|
|
||||||
git add APKBUILD
|
|
||||||
git commit -m "Update Zabbix to version $LATEST_VERSION" || exit 0
|
|
||||||
git push
|
|
||||||
fi
|
|
||||||
|
|
||||||
build-packages:
|
|
||||||
needs: [check-version, update-version]
|
|
||||||
if: needs.check-version.outputs.should_build == 'true'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ github.ref }}
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Build Zabbix packages
|
|
||||||
run: |
|
|
||||||
chmod +x build.sh
|
|
||||||
./build.sh
|
|
||||||
|
|
||||||
- name: List built packages
|
|
||||||
run: |
|
|
||||||
echo "Built packages:"
|
|
||||||
ls -la packages/
|
|
||||||
|
|
||||||
echo "Package sizes:"
|
|
||||||
du -h packages/*.apk
|
|
||||||
|
|
||||||
- name: Upload packages as artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: zabbix-apk-packages
|
|
||||||
path: packages/*.apk
|
|
||||||
retention-days: 30
|
|
||||||
|
|
||||||
- name: Create release
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
with:
|
|
||||||
tag_name: "v${{ needs.check-version.outputs.latest_version }}"
|
|
||||||
name: "Zabbix ${{ needs.check-version.outputs.latest_version }} APK Packages"
|
|
||||||
body: |
|
|
||||||
Automated build of Zabbix ${{ needs.check-version.outputs.latest_version }} packages for Alpine Linux.
|
|
||||||
|
|
||||||
## Packages
|
|
||||||
- `zabbix-agent-${{ needs.check-version.outputs.latest_version }}-r0.apk` - Monitoring agent
|
|
||||||
- `zabbix-proxy-${{ needs.check-version.outputs.latest_version }}-r0.apk` - Network proxy
|
|
||||||
- `zabbix-${{ needs.check-version.outputs.latest_version }}-r0.apk` - Meta package
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
```bash
|
|
||||||
apk add --allow-untrusted zabbix-agent-${{ needs.check-version.outputs.latest_version }}-r0.apk
|
|
||||||
rc-update add zabbix-agent default
|
|
||||||
rc-service zabbix-agent start
|
|
||||||
```
|
|
||||||
files: packages/*.apk
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
|
|
||||||
publish-to-gitea:
|
|
||||||
needs: [check-version, build-packages]
|
|
||||||
if: needs.check-version.outputs.should_build == 'true'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Download packages
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: zabbix-apk-packages
|
|
||||||
path: packages/
|
|
||||||
|
|
||||||
- name: Setup SSH for Gitea
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.GITEA_SSH_KEY }}" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan -H gitea-repo >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
||||||
|
|
||||||
- name: Publish to Gitea repository
|
|
||||||
run: |
|
|
||||||
# Clone or update the packages repository
|
|
||||||
git clone git@gitea-repo:mbuz/Zabbix.git gitea-repo || true
|
|
||||||
cd gitea-repo
|
|
||||||
|
|
||||||
# Create packages directory structure
|
|
||||||
mkdir -p alpine/v3.18/main/x86_64
|
|
||||||
|
|
||||||
# Copy new packages
|
|
||||||
cp ../packages/*.apk alpine/v3.18/main/x86_64/
|
|
||||||
|
|
||||||
# Update package index (simplified)
|
|
||||||
cd alpine/v3.18/main/x86_64
|
|
||||||
ls *.apk > PACKAGES.txt
|
|
||||||
|
|
||||||
# Commit and push
|
|
||||||
git config --local user.email "action@github.com"
|
|
||||||
git config --local user.name "GitHub Action"
|
|
||||||
git add .
|
|
||||||
git commit -m "Add Zabbix ${{ needs.check-version.outputs.latest_version }} packages" || exit 0
|
|
||||||
git push
|
|
||||||
|
|
||||||
deploy-test:
|
|
||||||
needs: [check-version, build-packages]
|
|
||||||
if: needs.check-version.outputs.should_build == 'true' && github.ref == 'refs/heads/test'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download packages
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: zabbix-apk-packages
|
|
||||||
path: packages/
|
|
||||||
|
|
||||||
- name: Test deployment in Alpine container
|
|
||||||
run: |
|
|
||||||
# Test agent package
|
|
||||||
docker run --rm -v $PWD/packages:/packages alpine:latest sh -c "
|
|
||||||
apk add --allow-untrusted /packages/zabbix-agent-*.apk
|
|
||||||
which zabbix_agentd
|
|
||||||
zabbix_agentd --version
|
|
||||||
"
|
|
||||||
|
|
||||||
# Test proxy package
|
|
||||||
docker run --rm -v $PWD/packages:/packages alpine:latest sh -c "
|
|
||||||
apk add --allow-untrusted /packages/zabbix-proxy-*.apk
|
|
||||||
which zabbix_proxy
|
|
||||||
zabbix_proxy --version
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "✅ Package deployment test passed"
|
|
||||||
1
zabbix-apk-builder/.gitignore
vendored
1
zabbix-apk-builder/.gitignore
vendored
@@ -9,6 +9,7 @@ src/
|
|||||||
|
|
||||||
# Backup files
|
# Backup files
|
||||||
*.backup
|
*.backup
|
||||||
|
*.bak
|
||||||
*~
|
*~
|
||||||
|
|
||||||
# OS files
|
# OS files
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Contributor: Maks <maks@onet.com>
|
# Contributor: Maksym Buz <maksym.buz@zabbix.com>
|
||||||
# Maintainer: Maks <maks@onet.com>
|
# Maintainer: Maksym Buz <maksym.buz@zabbix.com>
|
||||||
pkgname=zabbix
|
pkgname=zabbix
|
||||||
pkgver=7.4.2
|
pkgver=7.4.4
|
||||||
pkgrel=0
|
pkgrel=0
|
||||||
pkgdesc="Enterprise-class open source distributed monitoring solution"
|
pkgdesc="Enterprise-class open source distributed monitoring solution"
|
||||||
url="https://www.zabbix.com/"
|
url="https://www.zabbix.com/"
|
||||||
@@ -138,9 +138,9 @@ proxy() {
|
|||||||
install -dm755 "$subpkgdir"/var/log/zabbix
|
install -dm755 "$subpkgdir"/var/log/zabbix
|
||||||
install -dm755 "$subpkgdir"/var/run/zabbix
|
install -dm755 "$subpkgdir"/var/run/zabbix
|
||||||
}
|
}
|
||||||
|
# --- TEST ---
|
||||||
sha512sums="
|
sha512sums="SKIP"
|
||||||
3bf1f915c2cd5a59f1dd3afc10dd1a6e596840e576013839d6eae057cd327893f87cc5cec1d32b6a8ca8bd00735c0070327084aae01dc8d3399202f5a3e365c1 zabbix-7.4.2.tar.gz
|
SKIP
|
||||||
SKIP
|
SKIP
|
||||||
SKIP
|
SKIP
|
||||||
SKIP
|
SKIP
|
||||||
|
|||||||
@@ -1,258 +0,0 @@
|
|||||||
# CI/CD Pipeline Documentation
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
This CI/CD pipeline automates the entire Zabbix APK package lifecycle from version detection to deployment. It's designed to work with your Gitea repository and provides both automated and manual build capabilities.
|
|
||||||
|
|
||||||
## Pipeline Architecture
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
|
||||||
│ Version Check │ -> │ Update APKBUILD │ -> │ Build Packages │
|
|
||||||
│ (Zabbix Git) │ │ (Auto-commit) │ │ (Docker) │
|
|
||||||
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
|
||||||
│
|
|
||||||
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
|
||||||
│ Deploy Test │ <- │ Publish to Gitea │ <- │ Create Release │
|
|
||||||
│ (Alpine Test) │ │ (Package Repo) │ │ (GitHub) │
|
|
||||||
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
## Version Detection Strategy
|
|
||||||
|
|
||||||
### Primary Method: Zabbix Bitbucket API
|
|
||||||
- **Endpoint**: `https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags`
|
|
||||||
- **Process**:
|
|
||||||
1. Fetches all tags from Zabbix official repository
|
|
||||||
2. Filters for stable releases (excludes rc, beta, alpha)
|
|
||||||
3. Sorts versions and selects the latest
|
|
||||||
- **Advantages**:
|
|
||||||
- Official Zabbix repository
|
|
||||||
- Real-time release information
|
|
||||||
- Includes all release types for filtering
|
|
||||||
|
|
||||||
### Fallback Options
|
|
||||||
If the Bitbucket API fails:
|
|
||||||
1. **CDN Scraping**: Parse `https://cdn.zabbix.com/zabbix/sources/stable/`
|
|
||||||
2. **RSS Feed**: Monitor Zabbix blog/announcements
|
|
||||||
3. **Manual Trigger**: Force build via GitHub Actions
|
|
||||||
|
|
||||||
## Jobs Breakdown
|
|
||||||
|
|
||||||
### 1. **check-version**
|
|
||||||
- **Purpose**: Monitors Zabbix releases for new versions
|
|
||||||
- **Method**: Queries Zabbix Bitbucket API for latest stable release
|
|
||||||
- **Logic**:
|
|
||||||
```bash
|
|
||||||
# Filters tags to stable releases only
|
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' |
|
|
||||||
grep -v 'rc\|beta\|alpha' |
|
|
||||||
sort -V | tail -1
|
|
||||||
```
|
|
||||||
- **Output**: Determines if build is needed and provides version info
|
|
||||||
|
|
||||||
### 2. **update-version**
|
|
||||||
- **Purpose**: Automatically updates APKBUILD when new version found
|
|
||||||
- **Actions**:
|
|
||||||
- Updates `pkgver` to latest version
|
|
||||||
- Resets `pkgrel` to 0
|
|
||||||
- Clears checksums (regenerated during build)
|
|
||||||
- Commits and pushes changes
|
|
||||||
|
|
||||||
### 3. **build-packages**
|
|
||||||
- **Purpose**: Builds APK packages using Docker
|
|
||||||
- **Process**:
|
|
||||||
- Sets up Docker Buildx
|
|
||||||
- Runs `./build.sh`
|
|
||||||
- Uploads packages as artifacts
|
|
||||||
- Creates GitHub release (main branch only)
|
|
||||||
|
|
||||||
### 4. **publish-to-gitea**
|
|
||||||
- **Purpose**: Publishes packages to your Gitea repository
|
|
||||||
- **Process**:
|
|
||||||
- Downloads built packages
|
|
||||||
- Clones Gitea repo using SSH
|
|
||||||
- Organizes packages in Alpine repository structure
|
|
||||||
- Updates package index
|
|
||||||
- Commits and pushes to Gitea
|
|
||||||
|
|
||||||
### 5. **deploy-test**
|
|
||||||
- **Purpose**: Tests package installation (test branch only)
|
|
||||||
- **Process**:
|
|
||||||
- Downloads packages
|
|
||||||
- Tests installation in fresh Alpine containers
|
|
||||||
- Verifies binaries work correctly
|
|
||||||
|
|
||||||
## Trigger Conditions
|
|
||||||
|
|
||||||
### Automatic Triggers
|
|
||||||
- **Daily Check**: Runs at 6 AM UTC to check for new Zabbix versions
|
|
||||||
- **Code Changes**: Triggers on pushes to main/test branches when relevant files change
|
|
||||||
|
|
||||||
### Manual Triggers
|
|
||||||
- **Workflow Dispatch**: Manual trigger with optional force build
|
|
||||||
- **Use Case**: Emergency builds or testing
|
|
||||||
|
|
||||||
## Configuration Requirements
|
|
||||||
|
|
||||||
### GitHub Secrets
|
|
||||||
You need to configure these secrets in your GitHub repository:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# For Gitea repository access
|
|
||||||
GITEA_SSH_KEY # Private SSH key for gitea-repo access
|
|
||||||
```
|
|
||||||
|
|
||||||
### Repository Setup
|
|
||||||
1. **Branch Strategy**:
|
|
||||||
- `main`: Production releases
|
|
||||||
- `test`: Testing and validation
|
|
||||||
|
|
||||||
2. **File Structure**:
|
|
||||||
```
|
|
||||||
.github/workflows/build.yml # Main pipeline
|
|
||||||
APKBUILD # Package definition
|
|
||||||
build.sh # Build script
|
|
||||||
Dockerfile # Build environment
|
|
||||||
*.initd, *.confd # Service files
|
|
||||||
```
|
|
||||||
|
|
||||||
## API Endpoints Used
|
|
||||||
|
|
||||||
### Zabbix Version Detection
|
|
||||||
```bash
|
|
||||||
# Primary endpoint - Zabbix Bitbucket API
|
|
||||||
https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100
|
|
||||||
|
|
||||||
# Response format:
|
|
||||||
{
|
|
||||||
"values": [
|
|
||||||
{
|
|
||||||
"displayId": "7.4.2",
|
|
||||||
"type": "TAG"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Version Processing
|
|
||||||
```bash
|
|
||||||
# Extract stable versions only
|
|
||||||
curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
|
||||||
jq -r '.values[].displayId' | \
|
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
|
|
||||||
grep -v 'rc\|beta\|alpha' | \
|
|
||||||
sort -V | \
|
|
||||||
tail -1
|
|
||||||
```
|
|
||||||
|
|
||||||
## Package Repository Structure
|
|
||||||
|
|
||||||
Your Gitea repository will follow Alpine Linux repository format:
|
|
||||||
```
|
|
||||||
alpine/
|
|
||||||
v3.18/
|
|
||||||
main/
|
|
||||||
x86_64/
|
|
||||||
zabbix-agent-X.Y.Z-r0.apk
|
|
||||||
zabbix-proxy-X.Y.Z-r0.apk
|
|
||||||
zabbix-X.Y.Z-r0.apk
|
|
||||||
PACKAGES.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
## Deployment Flow
|
|
||||||
|
|
||||||
### Development Workflow
|
|
||||||
1. **Code Changes** → Push to `test` branch
|
|
||||||
2. **Pipeline Runs** → Builds and tests packages
|
|
||||||
3. **Testing** → Verify in Alpine containers
|
|
||||||
4. **Merge** → To `main` branch for release
|
|
||||||
|
|
||||||
### Production Workflow
|
|
||||||
1. **New Zabbix Release** → Detected by daily check
|
|
||||||
2. **Auto-Update** → APKBUILD updated and committed
|
|
||||||
3. **Build** → Packages built and tested
|
|
||||||
4. **Release** → GitHub release created
|
|
||||||
5. **Publish** → Packages pushed to Gitea repository
|
|
||||||
|
|
||||||
## Monitoring and Notifications
|
|
||||||
|
|
||||||
### Success Indicators
|
|
||||||
- ✅ Version check completes
|
|
||||||
- ✅ APKBUILD updated correctly
|
|
||||||
- ✅ Packages build successfully
|
|
||||||
- ✅ Tests pass in Alpine containers
|
|
||||||
- ✅ Packages published to Gitea
|
|
||||||
|
|
||||||
### Failure Handling
|
|
||||||
- 🚨 Build failures create GitHub issues
|
|
||||||
- 🚨 Failed deployments stop the pipeline
|
|
||||||
- 🚨 Version detection errors logged
|
|
||||||
|
|
||||||
## Usage Examples
|
|
||||||
|
|
||||||
### Manual Build
|
|
||||||
```bash
|
|
||||||
# Trigger manual build via GitHub Actions UI
|
|
||||||
# OR via GitHub CLI:
|
|
||||||
gh workflow run build.yml -f force_build=true
|
|
||||||
```
|
|
||||||
|
|
||||||
### Emergency Version Update
|
|
||||||
```bash
|
|
||||||
# Update version manually and push
|
|
||||||
sed -i 's/pkgver=.*/pkgver=7.4.3/' APKBUILD
|
|
||||||
git add APKBUILD
|
|
||||||
git commit -m "Emergency update to 7.4.3"
|
|
||||||
git push
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using Built Packages
|
|
||||||
```bash
|
|
||||||
# Add your Gitea repository
|
|
||||||
echo "http://gitea-repo/mbuz/Zabbix/raw/branch/main/alpine/v3.18/main" >> /etc/apk/repositories
|
|
||||||
|
|
||||||
# Install packages
|
|
||||||
apk update
|
|
||||||
apk add zabbix-agent zabbix-proxy
|
|
||||||
```
|
|
||||||
|
|
||||||
## Testing the Version Detection
|
|
||||||
|
|
||||||
You can test the version detection logic locally:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Get latest stable version
|
|
||||||
curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
|
||||||
jq -r '.values[].displayId' | \
|
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
|
|
||||||
grep -v 'rc\|beta\|alpha' | \
|
|
||||||
sort -V | \
|
|
||||||
tail -1
|
|
||||||
|
|
||||||
# Should output: 7.4.2 (or latest version)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Maintenance
|
|
||||||
|
|
||||||
### Regular Tasks
|
|
||||||
- Monitor pipeline runs
|
|
||||||
- Update Alpine Linux version in repository structure
|
|
||||||
- Rotate SSH keys periodically
|
|
||||||
- Review and update dependencies
|
|
||||||
|
|
||||||
### Troubleshooting
|
|
||||||
- Check GitHub Actions logs for failures
|
|
||||||
- Verify SSH key access to Gitea
|
|
||||||
- Ensure Docker builds work locally
|
|
||||||
- Test package installation manually
|
|
||||||
- Verify Zabbix API connectivity
|
|
||||||
|
|
||||||
## Security Considerations
|
|
||||||
|
|
||||||
1. **SSH Keys**: Use dedicated deploy keys with minimal permissions
|
|
||||||
2. **Secrets**: Store sensitive data in GitHub Secrets
|
|
||||||
3. **API Access**: Monitor for API rate limits or authentication changes
|
|
||||||
4. **Package Signing**: Consider implementing APK package signing
|
|
||||||
|
|
||||||
This pipeline provides a fully automated solution for maintaining up-to-date Zabbix packages while ensuring quality through testing and proper repository management.
|
|
||||||
@@ -36,5 +36,32 @@ COPY --chown=builder:builder . /home/builder/zabbix/
|
|||||||
|
|
||||||
WORKDIR /home/builder/zabbix
|
WORKDIR /home/builder/zabbix
|
||||||
|
|
||||||
|
# Create build script that just builds packages
|
||||||
|
USER root
|
||||||
|
RUN cat > /usr/local/bin/build-packages.sh << 'EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Building packages as builder user..."
|
||||||
|
sudo -u builder sh -c "
|
||||||
|
cd /home/builder/zabbix
|
||||||
|
echo 'Generating checksums...'
|
||||||
|
abuild checksum
|
||||||
|
echo 'Building packages...'
|
||||||
|
abuild -r
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "Build complete! Packages built in /home/builder/packages:"
|
||||||
|
find /home/builder/packages -name "*.apk" -exec ls -la {} \;
|
||||||
|
|
||||||
|
echo "Setting proper permissions on packages..."
|
||||||
|
chmod 644 /home/builder/packages/*.apk 2>/dev/null || true
|
||||||
|
|
||||||
|
echo "Final package list (excluding APKINDEX):"
|
||||||
|
find /home/builder/packages -name "*.apk" -exec ls -la {} \;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/build-packages.sh
|
||||||
|
|
||||||
# Set build command
|
# Set build command
|
||||||
CMD ["abuild", "-r"]
|
CMD ["/usr/local/bin/build-packages.sh"]
|
||||||
@@ -4,43 +4,32 @@ Automated Alpine Linux package builder for Zabbix Agent and Proxy with CI/CD pip
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- 🔄 **Automatic Version Detection**: Monitors Zabbix releases using official Bitbucket API
|
- 🔄 **Automatic Version Detection**: Monitors Zabbix releases using Bitbucket API
|
||||||
- 🏗️ **Docker-based Building**: Consistent, reproducible builds in isolated environment
|
|
||||||
- 🚀 **CI/CD Pipeline**: Full automation from version detection to package deployment
|
- 🚀 **CI/CD Pipeline**: Full automation from version detection to package deployment
|
||||||
- 📦 **Multi-package Support**: Builds agent, proxy, and main packages
|
- 📦 **Multi-package Support**: Builds agent and proxy packages
|
||||||
- 🧪 **Automated Testing**: Tests package installation in Alpine containers
|
- 🧪 **Automated Testing**: Tests package installation in Alpine containers
|
||||||
- 📊 **Gitea Integration**: Publishes packages to your private Gitea repository
|
- 📊 **Gitea Integration**: Publishes packages to Gitea repository
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
### 1. Repository Setup
|
### Prerequisites
|
||||||
|
|
||||||
|
- Docker installed
|
||||||
|
- Gitea repository with Actions enabled
|
||||||
|
|
||||||
|
### Manual Build
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Clone this repository
|
# Clone the repository
|
||||||
git clone <your-repo-url>
|
git clone <your-gitea-repo>
|
||||||
cd zabbix-apk-builder
|
cd zabbix-apk-builder
|
||||||
|
|
||||||
# Make build script executable
|
|
||||||
chmod +x build.sh setup-cicd.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Manual Build
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Build packages locally
|
# Build packages locally
|
||||||
|
chmod +x build.sh
|
||||||
./build.sh
|
./build.sh
|
||||||
|
|
||||||
# Packages will be in ./packages/
|
# Check built packages
|
||||||
ls -la packages/
|
ls -la packages/builder/x86_64/
|
||||||
```
|
|
||||||
|
|
||||||
### 3. CI/CD Setup
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Run the setup script
|
|
||||||
./setup-cicd.sh
|
|
||||||
|
|
||||||
# Follow the prompts to configure GitHub secrets
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Package Information
|
## Package Information
|
||||||
@@ -48,19 +37,8 @@ ls -la packages/
|
|||||||
### Built Packages
|
### Built Packages
|
||||||
|
|
||||||
1. **zabbix-agent** - Zabbix Agent only
|
1. **zabbix-agent** - Zabbix Agent only
|
||||||
2. **zabbix-proxy** - Zabbix Proxy (without LDAP)
|
2. **zabbix-proxy** - Zabbix Proxy
|
||||||
3. **zabbix** - Main package with libraries
|
3. **zabbix** - Meta package
|
||||||
|
|
||||||
### Current Version
|
|
||||||
|
|
||||||
- **Zabbix Version**: 7.4.2
|
|
||||||
- **Alpine Base**: 3.18
|
|
||||||
- **Architecture**: x86_64
|
|
||||||
|
|
||||||
### Dependencies Removed
|
|
||||||
|
|
||||||
- LDAP support removed from proxy build
|
|
||||||
- Simplified configuration for smaller footprint
|
|
||||||
|
|
||||||
## CI/CD Pipeline
|
## CI/CD Pipeline
|
||||||
|
|
||||||
@@ -68,7 +46,6 @@ ls -la packages/
|
|||||||
|
|
||||||
- **Daily**: Checks for new Zabbix versions at 6 AM UTC
|
- **Daily**: Checks for new Zabbix versions at 6 AM UTC
|
||||||
- **Push**: Builds when code changes in main/test branches
|
- **Push**: Builds when code changes in main/test branches
|
||||||
- **Manual**: Force builds via GitHub Actions
|
|
||||||
|
|
||||||
### Version Detection
|
### Version Detection
|
||||||
|
|
||||||
@@ -96,46 +73,22 @@ GITEA_SSH_KEY # SSH private key for Gitea access
|
|||||||
### File Structure
|
### File Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
.
|
zabbix-git/
|
||||||
├── APKBUILD # Alpine package definition
|
└── zabbix-apk-builder/
|
||||||
├── build.sh # Build automation script
|
├── .gitea/
|
||||||
├── Dockerfile # Build environment
|
│ └── workflows/
|
||||||
├── .github/workflows/ # CI/CD pipeline
|
│ └── build.yaml # Main CI/CD pipeline
|
||||||
├── packages/ # Built packages
|
├── APKBUILD # Alpine package definition
|
||||||
├── zabbix-agent.initd # Agent init script
|
├── Dockerfile # Build environment container
|
||||||
├── zabbix-agent.confd # Agent config
|
├── README.md # This file
|
||||||
├── zabbix-proxy.initd # Proxy init script
|
├── build.sh # Local build script
|
||||||
└── zabbix-proxy.confd # Proxy config
|
├── packages/ # Generated packages (gitignored)
|
||||||
```
|
├── zabbix-agent.confd # Agent configuration
|
||||||
|
├── zabbix-agent.initd # Agent init script
|
||||||
## Usage
|
├── zabbix-agent.pre-install # Agent pre-install script
|
||||||
|
├── zabbix-proxy.confd # Proxy configuration
|
||||||
### Install Packages
|
├── zabbix-proxy.initd # Proxy init script
|
||||||
|
└── zabbix-proxy.pre-install # Proxy pre-install script
|
||||||
```bash
|
|
||||||
# Add repository
|
|
||||||
echo "http://gitea-repo/mbuz/Zabbix/raw/branch/main/alpine/v3.18/main" >> /etc/apk/repositories
|
|
||||||
|
|
||||||
# Update and install
|
|
||||||
apk update
|
|
||||||
apk add zabbix-agent
|
|
||||||
|
|
||||||
# Enable and start
|
|
||||||
rc-update add zabbix-agent default
|
|
||||||
rc-service zabbix-agent start
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Configure agent
|
|
||||||
vim /etc/zabbix/zabbix_agentd.conf
|
|
||||||
|
|
||||||
# Set server IP
|
|
||||||
Server=your.zabbix.server
|
|
||||||
|
|
||||||
# Restart service
|
|
||||||
rc-service zabbix-agent restart
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
@@ -157,28 +110,16 @@ docker run --rm -it \
|
|||||||
|
|
||||||
### Branch Strategy
|
### Branch Strategy
|
||||||
|
|
||||||
- **main**: Production releases, auto-deployed
|
- **main**: Production releases, merge only
|
||||||
- **test**: Testing and validation, no auto-deploy
|
- **test**: Testing and validation
|
||||||
|
|
||||||
### Making Changes
|
### Making Changes
|
||||||
|
|
||||||
1. Create feature branch from `test`
|
1. Create feature branch from `main`
|
||||||
2. Test changes thoroughly
|
2. Test changes thoroughly
|
||||||
3. Merge to `test` for CI validation
|
3. Validate CI
|
||||||
4. Merge to `main` for production release
|
4. Merge to `main`
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Build Issues
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Check build logs
|
|
||||||
docker logs $(docker ps -l -q)
|
|
||||||
|
|
||||||
# Manual build debug
|
|
||||||
docker run -it --rm -v $(pwd):/build alpine:3.18 sh
|
|
||||||
cd /build && ./build.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
### Version Detection
|
### Version Detection
|
||||||
|
|
||||||
@@ -186,48 +127,13 @@ cd /build && ./build.sh
|
|||||||
# Test API manually
|
# Test API manually
|
||||||
curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
||||||
jq -r '.values[].displayId' | \
|
jq -r '.values[].displayId' | \
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
|
grep -E '^[0-9]+\.[0-9]+\.[0-9]+
|
||||||
|
| \
|
||||||
sort -V | tail -1
|
sort -V | tail -1
|
||||||
```
|
```
|
||||||
|
|
||||||
### CI/CD Issues
|
|
||||||
|
|
||||||
1. Check GitHub Actions logs
|
|
||||||
2. Verify SSH key permissions
|
|
||||||
3. Test Gitea connectivity
|
|
||||||
4. Validate APKBUILD syntax
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
- **[CI-CD-DOCS.md](CI-CD-DOCS.md)**: Comprehensive CI/CD documentation
|
|
||||||
- **[setup-cicd.sh](setup-cicd.sh)**: Setup script for CI/CD configuration
|
|
||||||
|
|
||||||
## Security
|
|
||||||
|
|
||||||
- Uses SSH keys for Gitea access
|
|
||||||
- Minimal package dependencies
|
|
||||||
- Regular security updates via automated builds
|
|
||||||
- No secrets stored in repository
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
1. Fork the repository
|
|
||||||
2. Create feature branch
|
|
||||||
3. Test changes in `test` branch
|
|
||||||
4. Submit pull request to `main`
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project follows the same license as Zabbix (GPL v2).
|
This project follows the same license as Zabbix (AGPLv3).
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
For issues:
|
|
||||||
1. Check troubleshooting section
|
|
||||||
2. Review CI/CD logs
|
|
||||||
3. Test manual build process
|
|
||||||
4. Check Zabbix API connectivity
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Built with ❤️ for Alpine Linux and Zabbix monitoring**
|
|
||||||
|
|||||||
@@ -3,52 +3,57 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
PROJECT_DIR="$(pwd)"
|
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
IMAGE_NAME="zabbix-apk-builder"
|
IMAGE_NAME="zabbix-apk-builder"
|
||||||
CONTAINER_NAME="zabbix-build-$$"
|
# Use a unique ID from the CI environment if available, otherwise fall back to PID
|
||||||
|
UNIQUE_ID="${CI_RUN_ID:-$$}"
|
||||||
|
CONTAINER_NAME="zabbix-build-${UNIQUE_ID}"
|
||||||
OUTPUT_DIR="$PROJECT_DIR/packages"
|
OUTPUT_DIR="$PROJECT_DIR/packages"
|
||||||
|
|
||||||
echo "=== Zabbix APK Builder ==="
|
echo "=== Zabbix APK Builder ==="
|
||||||
echo "Project directory: $PROJECT_DIR"
|
echo "Project directory: $PROJECT_DIR"
|
||||||
echo "Output directory: $OUTPUT_DIR"
|
echo "Output directory: $OUTPUT_DIR"
|
||||||
|
|
||||||
# Clean up any existing containers
|
# Clean up function
|
||||||
cleanup() {
|
cleanup() {
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up container..."
|
||||||
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
# Create output directory
|
# Clean and create output directory
|
||||||
|
rm -rf "$OUTPUT_DIR"
|
||||||
mkdir -p "$OUTPUT_DIR"
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
# Build Docker image
|
# Build Docker image
|
||||||
echo "Building Docker image..."
|
echo "Building Docker image..."
|
||||||
docker build -t "$IMAGE_NAME" "$PROJECT_DIR"
|
docker build -t "$IMAGE_NAME" "$PROJECT_DIR"
|
||||||
|
|
||||||
# Run the build in container
|
# Run the build in the container
|
||||||
echo "Running package build..."
|
echo "Running package build in container..."
|
||||||
docker run --rm \
|
docker run --name "$CONTAINER_NAME" "$IMAGE_NAME"
|
||||||
--name "$CONTAINER_NAME" \
|
|
||||||
-v "$OUTPUT_DIR:/output" \
|
|
||||||
"$IMAGE_NAME" \
|
|
||||||
sh -c "
|
|
||||||
set -e
|
|
||||||
echo 'Starting package build...'
|
|
||||||
|
|
||||||
# Generate checksums for APKBUILD
|
# Copy packages from container to host
|
||||||
echo 'Generating checksums for APKBUILD...'
|
echo "Copying packages from container..."
|
||||||
abuild checksum
|
if docker cp "$CONTAINER_NAME:/home/builder/packages/." "$OUTPUT_DIR/"; then
|
||||||
|
echo "✅ Packages copied successfully"
|
||||||
|
|
||||||
# Build packages
|
# Remove APKINDEX files (we only want the .apk packages)
|
||||||
abuild -r
|
echo "Removing repository index files..."
|
||||||
|
find "$OUTPUT_DIR" -name "APKINDEX.tar.gz" -delete 2>/dev/null || true
|
||||||
|
|
||||||
# Copy packages to output
|
# Fix permissions on copied files
|
||||||
echo 'Copying packages to output directory...'
|
echo "Fixing file permissions..."
|
||||||
find /home/builder/packages -name '*.apk' -exec cp {} /output/ \;
|
find "$OUTPUT_DIR" -name "*.apk" -exec chmod 644 {} \; 2>/dev/null || true
|
||||||
"
|
|
||||||
echo "Build completed successfully!"
|
echo "Build completed successfully!"
|
||||||
echo "To install packages:"
|
echo "Packages are in $OUTPUT_DIR:"
|
||||||
echo " apk add --allow-untrusted $OUTPUT_DIR/zabbix-agent-*.apk"
|
find "$OUTPUT_DIR" -name "*.apk" -exec ls -la {} \;
|
||||||
echo " apk add --allow-untrusted $OUTPUT_DIR/zabbix-proxy-*.apk"
|
else
|
||||||
|
echo "❌ Failed to copy packages"
|
||||||
|
echo "Checking what's in the container..."
|
||||||
|
docker exec "$CONTAINER_NAME" find /home/builder -name "*.apk" -exec ls -la {} \; 2>/dev/null || true
|
||||||
|
docker exec "$CONTAINER_NAME" ls -la /home/builder/packages/ 2>/dev/null || true
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Zabbix APK Builder CI/CD Setup Script
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "🚀 Zabbix APK Builder CI/CD Setup"
|
|
||||||
echo "=================================="
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Colors for output
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[0;32m'
|
|
||||||
YELLOW='\033[1;33m'
|
|
||||||
BLUE='\033[0;34m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
# Function to print colored output
|
|
||||||
print_step() {
|
|
||||||
echo -e "${BLUE}[STEP]${NC} $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success() {
|
|
||||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_warning() {
|
|
||||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_error() {
|
|
||||||
echo -e "${RED}[ERROR]${NC} $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if we're in a git repository
|
|
||||||
print_step "Checking Git repository status..."
|
|
||||||
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
|
||||||
print_error "Not in a Git repository. Please initialize git first:"
|
|
||||||
echo " git init"
|
|
||||||
echo " git add ."
|
|
||||||
echo " git commit -m 'Initial commit'"
|
|
||||||
echo " git remote add origin <your-github-repo>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if we have required files
|
|
||||||
print_step "Verifying required files..."
|
|
||||||
required_files=("APKBUILD" "build.sh" "Dockerfile" ".github/workflows/build.yml")
|
|
||||||
for file in "${required_files[@]}"; do
|
|
||||||
if [[ ! -f "$file" ]]; then
|
|
||||||
print_error "Required file missing: $file"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
print_success "All required files present"
|
|
||||||
|
|
||||||
# Test version detection API
|
|
||||||
print_step "Testing Zabbix version detection API..."
|
|
||||||
if ! curl -s --connect-timeout 10 "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=5" | grep -q "displayId"; then
|
|
||||||
print_warning "Could not reach Zabbix API. Pipeline will work but version detection may fail."
|
|
||||||
else
|
|
||||||
latest_version=$(curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
|
||||||
grep -o '"displayId":"[^"]*"' | cut -d'"' -f4 | \
|
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)
|
|
||||||
print_success "API working. Latest Zabbix version: $latest_version"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if GitHub CLI is available
|
|
||||||
print_step "Checking GitHub CLI availability..."
|
|
||||||
if command -v gh &> /dev/null; then
|
|
||||||
if gh auth status &> /dev/null; then
|
|
||||||
print_success "GitHub CLI authenticated"
|
|
||||||
GITHUB_CLI_AVAILABLE=true
|
|
||||||
else
|
|
||||||
print_warning "GitHub CLI not authenticated. Manual secret configuration needed."
|
|
||||||
GITHUB_CLI_AVAILABLE=false
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_warning "GitHub CLI not installed. Manual secret configuration needed."
|
|
||||||
GITHUB_CLI_AVAILABLE=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
# SSH Key Setup
|
|
||||||
print_step "Setting up SSH key for Gitea access..."
|
|
||||||
echo
|
|
||||||
echo "You need an SSH key for the CI/CD pipeline to push packages to your Gitea repository."
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Check if user has SSH keys
|
|
||||||
if [[ -f ~/.ssh/id_rsa ]] || [[ -f ~/.ssh/id_ed25519 ]]; then
|
|
||||||
echo "Existing SSH keys found:"
|
|
||||||
ls -la ~/.ssh/id_* 2>/dev/null | grep -v .pub || true
|
|
||||||
echo
|
|
||||||
read -p "Use existing SSH key? (y/N): " use_existing
|
|
||||||
|
|
||||||
if [[ $use_existing =~ ^[Yy]$ ]]; then
|
|
||||||
if [[ -f ~/.ssh/id_ed25519 ]]; then
|
|
||||||
SSH_KEY_PATH=~/.ssh/id_ed25519
|
|
||||||
elif [[ -f ~/.ssh/id_rsa ]]; then
|
|
||||||
SSH_KEY_PATH=~/.ssh/id_rsa
|
|
||||||
fi
|
|
||||||
print_success "Using existing SSH key: $SSH_KEY_PATH"
|
|
||||||
else
|
|
||||||
create_new_key=true
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
create_new_key=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $create_new_key == true ]]; then
|
|
||||||
print_step "Creating new SSH key for CI/CD..."
|
|
||||||
ssh-keygen -t ed25519 -f ~/.ssh/zabbix_cicd -N "" -C "zabbix-cicd@$(hostname)"
|
|
||||||
SSH_KEY_PATH=~/.ssh/zabbix_cicd
|
|
||||||
print_success "Created new SSH key: $SSH_KEY_PATH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Display public key
|
|
||||||
echo
|
|
||||||
echo "📋 Public key to add to your Gitea repository:"
|
|
||||||
echo "=============================================="
|
|
||||||
cat "$SSH_KEY_PATH.pub"
|
|
||||||
echo "=============================================="
|
|
||||||
echo
|
|
||||||
|
|
||||||
print_warning "IMPORTANT: Add this public key to your Gitea repository with write access!"
|
|
||||||
echo "1. Go to your Gitea repository settings"
|
|
||||||
echo "2. Navigate to Deploy Keys section"
|
|
||||||
echo "3. Add the public key above"
|
|
||||||
echo "4. Enable write access for the key"
|
|
||||||
echo
|
|
||||||
|
|
||||||
read -p "Press Enter after adding the public key to Gitea..."
|
|
||||||
|
|
||||||
# Configure GitHub Secrets
|
|
||||||
print_step "Configuring GitHub repository secrets..."
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [[ $GITHUB_CLI_AVAILABLE == true ]]; then
|
|
||||||
echo "Setting up GitHub secrets using GitHub CLI..."
|
|
||||||
|
|
||||||
# Set SSH key secret
|
|
||||||
if gh secret set GITEA_SSH_KEY < "$SSH_KEY_PATH"; then
|
|
||||||
print_success "SSH key secret configured"
|
|
||||||
else
|
|
||||||
print_error "Failed to set SSH key secret"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
echo "Manual secret configuration required:"
|
|
||||||
echo
|
|
||||||
echo "1. Go to your GitHub repository"
|
|
||||||
echo "2. Navigate to Settings → Secrets and variables → Actions"
|
|
||||||
echo "3. Add the following secret:"
|
|
||||||
echo
|
|
||||||
echo " Name: GITEA_SSH_KEY"
|
|
||||||
echo " Value: (paste the private key below)"
|
|
||||||
echo
|
|
||||||
echo "📋 Private key content:"
|
|
||||||
echo "======================"
|
|
||||||
cat "$SSH_KEY_PATH"
|
|
||||||
echo "======================"
|
|
||||||
echo
|
|
||||||
read -p "Press Enter after configuring the GitHub secret..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Test build locally
|
|
||||||
print_step "Testing local build..."
|
|
||||||
if [[ -x ./build.sh ]]; then
|
|
||||||
echo "Running test build (this may take a few minutes)..."
|
|
||||||
if ./build.sh; then
|
|
||||||
print_success "Local build test successful"
|
|
||||||
if [[ -d packages ]] && [[ $(ls packages/*.apk 2>/dev/null | wc -l) -gt 0 ]]; then
|
|
||||||
echo "Built packages:"
|
|
||||||
ls -la packages/*.apk
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_warning "Local build test failed, but CI/CD setup continues"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_error "build.sh is not executable"
|
|
||||||
chmod +x build.sh
|
|
||||||
print_success "Fixed build.sh permissions"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Repository setup verification
|
|
||||||
print_step "Verifying repository configuration..."
|
|
||||||
|
|
||||||
# Check remote URL
|
|
||||||
remote_url=$(git remote get-url origin 2>/dev/null || echo "")
|
|
||||||
if [[ -z "$remote_url" ]]; then
|
|
||||||
print_error "No Git remote 'origin' configured"
|
|
||||||
echo "Please add your GitHub repository as remote:"
|
|
||||||
echo " git remote add origin https://github.com/username/repo.git"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
print_success "Git remote configured: $remote_url"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if we're on main or test branch
|
|
||||||
current_branch=$(git branch --show-current)
|
|
||||||
if [[ "$current_branch" != "main" ]] && [[ "$current_branch" != "test" ]]; then
|
|
||||||
print_warning "Not on main or test branch (current: $current_branch)"
|
|
||||||
echo "CI/CD pipeline triggers on main/test branches"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Final steps
|
|
||||||
echo
|
|
||||||
print_step "Final setup steps..."
|
|
||||||
echo
|
|
||||||
echo "✅ CI/CD Setup Complete!"
|
|
||||||
echo
|
|
||||||
echo "📋 Next Steps:"
|
|
||||||
echo "1. Commit and push your changes:"
|
|
||||||
echo " git add ."
|
|
||||||
echo " git commit -m 'Add CI/CD pipeline'"
|
|
||||||
echo " git push origin main"
|
|
||||||
echo
|
|
||||||
echo "2. Check GitHub Actions tab in your repository"
|
|
||||||
echo "3. The pipeline will:"
|
|
||||||
echo " - Check for new Zabbix versions daily"
|
|
||||||
echo " - Build packages automatically"
|
|
||||||
echo " - Publish to your Gitea repository"
|
|
||||||
echo
|
|
||||||
echo "📖 Documentation:"
|
|
||||||
echo "- CI-CD-DOCS.md: Comprehensive pipeline documentation"
|
|
||||||
echo "- README.md: Usage and setup guide"
|
|
||||||
echo
|
|
||||||
echo "🔧 Manual Operations:"
|
|
||||||
echo "- Force build: Go to Actions tab → Zabbix APK Builder → Run workflow"
|
|
||||||
echo "- Test build: ./build.sh"
|
|
||||||
echo "- Check version: curl -s 'https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=5'"
|
|
||||||
echo
|
|
||||||
print_success "Setup completed successfully! 🎉"
|
|
||||||
68
zabbix-tests/host-cleanup.py
Executable file
68
zabbix-tests/host-cleanup.py
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
# === CONFIGURATION ===
|
||||||
|
ZABBIX_URL = "http://10.0.0.101:8887/api_jsonrpc.php"
|
||||||
|
ZABBIX_TOKEN = "c785634354e760a6843055ba4581bc7b6cd6eb2ec75f7c2a79f251c1719933f7"
|
||||||
|
GROUP_ID = "19"
|
||||||
|
BATCH_SIZE = 100
|
||||||
|
HOST_PATTERN = "dummy-host-"
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
"Content-Type": "application/json-rpc",
|
||||||
|
"Authorization": f"Bearer {ZABBIX_TOKEN}"
|
||||||
|
}
|
||||||
|
|
||||||
|
def zbx_request(method, params):
|
||||||
|
payload = {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": method,
|
||||||
|
"params": params,
|
||||||
|
"id": int(time.time())
|
||||||
|
}
|
||||||
|
r = requests.post(ZABBIX_URL, headers=HEADERS, data=json.dumps(payload))
|
||||||
|
r.raise_for_status()
|
||||||
|
resp = r.json()
|
||||||
|
if "error" in resp:
|
||||||
|
raise Exception(f"API error: {resp['error']}")
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def cleanup_hosts():
|
||||||
|
# Get all hosts in the group
|
||||||
|
resp = zbx_request("host.get", {
|
||||||
|
"groupids": [GROUP_ID],
|
||||||
|
"output": ["hostid", "host"]
|
||||||
|
})
|
||||||
|
|
||||||
|
# Filter hosts that contain the dummy pattern
|
||||||
|
hosts = [h for h in resp.get("result", []) if HOST_PATTERN in h["host"]]
|
||||||
|
|
||||||
|
if not hosts:
|
||||||
|
print("No dummy hosts found")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"Deleting {len(hosts)} hosts")
|
||||||
|
|
||||||
|
# Delete in batches
|
||||||
|
host_ids = [h["hostid"] for h in hosts]
|
||||||
|
total_deleted = 0
|
||||||
|
|
||||||
|
for i in range(0, len(host_ids), BATCH_SIZE):
|
||||||
|
batch = host_ids[i:i + BATCH_SIZE]
|
||||||
|
try:
|
||||||
|
resp = zbx_request("host.delete", batch)
|
||||||
|
deleted = len(resp.get("result", {}).get("hostids", []))
|
||||||
|
total_deleted += deleted
|
||||||
|
print(f"Deleted batch {i//BATCH_SIZE + 1}: {deleted} hosts")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in batch {i//BATCH_SIZE + 1}: {e}")
|
||||||
|
|
||||||
|
if i + BATCH_SIZE < len(host_ids):
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
print(f"Total deleted: {total_deleted}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cleanup_hosts()
|
||||||
62
zabbix-tests/host-creator.py
Executable file
62
zabbix-tests/host-creator.py
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
# === CONFIGURATION ===
|
||||||
|
ZABBIX_URL = "http://10.0.0.101:8887/api_jsonrpc.php"
|
||||||
|
ZABBIX_TOKEN = "c785634354e760a6843055ba4581bc7b6cd6eb2ec75f7c2a79f251c1719933f7"
|
||||||
|
PROXY_GROUP_ID = "1" # your proxy group ID
|
||||||
|
GROUP_ID = "19" # host group for these hosts
|
||||||
|
NUM_HOSTS = 1000 # number of hosts to create
|
||||||
|
BATCH_SIZE = 100 # how many to create per call
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
"Content-Type": "application/json-rpc",
|
||||||
|
"Authorization": f"Bearer {ZABBIX_TOKEN}"
|
||||||
|
}
|
||||||
|
|
||||||
|
def zbx_request(method, params):
|
||||||
|
"""Send Zabbix API request using Bearer token authentication."""
|
||||||
|
payload = {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": method,
|
||||||
|
"params": params,
|
||||||
|
"id": int(time.time())
|
||||||
|
}
|
||||||
|
r = requests.post(ZABBIX_URL, headers=HEADERS, data=json.dumps(payload))
|
||||||
|
r.raise_for_status()
|
||||||
|
resp = r.json()
|
||||||
|
if "error" in resp:
|
||||||
|
raise Exception(f"Zabbix API error: {resp['error']}")
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def create_hosts():
|
||||||
|
hosts = []
|
||||||
|
for i in range(1, NUM_HOSTS + 1):
|
||||||
|
host_name = f"dummy-host-{i:04d}"
|
||||||
|
host = {
|
||||||
|
"host": host_name,
|
||||||
|
"groups": [{"groupid": GROUP_ID}],
|
||||||
|
"templates": [{"templateid": "10048"}], # assign Proxy Health template
|
||||||
|
"monitored_by": 2, # 2 = proxy group
|
||||||
|
"proxy_groupid": PROXY_GROUP_ID # your proxy group ID
|
||||||
|
}
|
||||||
|
hosts.append(host)
|
||||||
|
|
||||||
|
for i in range(0, len(hosts), BATCH_SIZE):
|
||||||
|
batch = hosts[i:i + BATCH_SIZE]
|
||||||
|
print(f"Creating hosts {i+1}-{i+len(batch)}...")
|
||||||
|
try:
|
||||||
|
resp = zbx_request("host.create", batch)
|
||||||
|
created = len(resp.get("result", {}).get("hostids", []))
|
||||||
|
print(f"Created {created} hosts.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in batch {i+1}-{i+len(batch)}: {e}")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
create_hosts()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fatal error: {e}")
|
||||||
28
zabbix-tests/server-docker/.env
Normal file
28
zabbix-tests/server-docker/.env
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Database Configuration
|
||||||
|
MYSQL_DATABASE=zabbix
|
||||||
|
MYSQL_USER=zabbix
|
||||||
|
MYSQL_PASSWORD=strong-password
|
||||||
|
MYSQL_ROOT_PASSWORD=very-strong-password
|
||||||
|
|
||||||
|
# Image Versions (uncomment to override defaults)
|
||||||
|
ZABBIX_VERSION=latest
|
||||||
|
# MYSQL_VERSION=8.4.0-oraclelinux8 # Keep oraclelinux variant for architecture compatibility
|
||||||
|
|
||||||
|
# Port Configuration
|
||||||
|
ZABBIX_SERVER_PORT=10051
|
||||||
|
ZABBIX_WEB_PORT=8887
|
||||||
|
|
||||||
|
# Server Settings
|
||||||
|
PHP_TIMEZONE=Europe/Warsaw
|
||||||
|
ZBX_STARTSNMPTRAPPER=1
|
||||||
|
ZBX_SNMPTRAPPERFILE=/tmp/traps.log
|
||||||
|
ZBX_CACHESIZE=128M
|
||||||
|
ZBX_VALUECACHESIZE=64M
|
||||||
|
ZBX_TRENDCACHESIZE=32M
|
||||||
|
|
||||||
|
# Common Proxy Settings (applied to all proxies)
|
||||||
|
PROXY_CACHE_SIZE=128M
|
||||||
|
PROXY_HISTORY_CACHE_SIZE=32M
|
||||||
|
PROXY_HISTORY_INDEX_CACHE_SIZE=16M
|
||||||
|
PROXY_BUFFER_MODE=hybrid
|
||||||
|
PROXY_MEMORY_BUFFER_SIZE=64M
|
||||||
224
zabbix-tests/server-docker/docker-compose.yaml
Normal file
224
zabbix-tests/server-docker/docker-compose.yaml
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
### This will create a Zabbix server with six active proxies and a MySQL database.
|
||||||
|
### You need to configure proxies in Zabbix frontend after deployment.
|
||||||
|
### Adjust .env file for customization.
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql-server:
|
||||||
|
image: mysql:${MYSQL_VERSION:-8.4.0-oraclelinux8}
|
||||||
|
container_name: zabbix-mysql-server
|
||||||
|
command:
|
||||||
|
- 'mysqld'
|
||||||
|
- '--character-set-server=utf8mb4'
|
||||||
|
- '--collation-server=utf8mb4_bin'
|
||||||
|
- '--log-bin-trust-function-creators=1'
|
||||||
|
environment:
|
||||||
|
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
||||||
|
- MYSQL_USER=${MYSQL_USER}
|
||||||
|
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
||||||
|
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/mysql:/var/lib/mysql
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-server:
|
||||||
|
image: zabbix/zabbix-server-mysql:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-server
|
||||||
|
depends_on:
|
||||||
|
- mysql-server
|
||||||
|
ports:
|
||||||
|
- "${ZABBIX_SERVER_PORT}:10051"
|
||||||
|
environment:
|
||||||
|
- DB_SERVER_HOST=mysql-server
|
||||||
|
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
||||||
|
- MYSQL_USER=${MYSQL_USER}
|
||||||
|
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
||||||
|
- ZBX_STARTSNMPTRAPPER=${ZBX_STARTSNMPTRAPPER}
|
||||||
|
- ZBX_SNMPTRAPPERFILE=${ZBX_SNMPTRAPPERFILE}
|
||||||
|
- ZBX_CACHESIZE=${ZBX_CACHESIZE}
|
||||||
|
- ZBX_VALUECACHESIZE=${ZBX_VALUECACHESIZE}
|
||||||
|
- ZBX_TRENDCACHESIZE=${ZBX_TRENDCACHESIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/alertscripts:/usr/lib/zabbix/alertscripts
|
||||||
|
- ./zabbix/externalscripts:/usr/lib/zabbix/externalscripts
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-web:
|
||||||
|
image: zabbix/zabbix-web-nginx-mysql:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-web
|
||||||
|
depends_on:
|
||||||
|
- mysql-server
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "${ZABBIX_WEB_PORT}:8080"
|
||||||
|
environment:
|
||||||
|
- DB_SERVER_HOST=mysql-server
|
||||||
|
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
||||||
|
- MYSQL_USER=${MYSQL_USER}
|
||||||
|
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- PHP_TZ=${PHP_TIMEZONE}
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-proxy-active-01:
|
||||||
|
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-proxy-active-01
|
||||||
|
depends_on:
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "10101:10051"
|
||||||
|
environment:
|
||||||
|
- ZBX_HOSTNAME=zabbix-proxy-active-01
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- ZBX_PROXYMODE=0
|
||||||
|
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/proxy-01:/var/lib/zabbix/db_data:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-proxy-active-02:
|
||||||
|
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-proxy-active-02
|
||||||
|
depends_on:
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "10102:10051"
|
||||||
|
environment:
|
||||||
|
- ZBX_HOSTNAME=zabbix-proxy-active-02
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- ZBX_PROXYMODE=0
|
||||||
|
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/proxy-02:/var/lib/zabbix/db_data:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-proxy-active-03:
|
||||||
|
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-proxy-active-03
|
||||||
|
depends_on:
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "10103:10051"
|
||||||
|
environment:
|
||||||
|
- ZBX_HOSTNAME=zabbix-proxy-active-03
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- ZBX_PROXYMODE=0
|
||||||
|
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/proxy-03:/var/lib/zabbix/db_data:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-proxy-active-04:
|
||||||
|
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-proxy-active-04
|
||||||
|
depends_on:
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "10104:10051"
|
||||||
|
environment:
|
||||||
|
- ZBX_HOSTNAME=zabbix-proxy-active-04
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- ZBX_PROXYMODE=0
|
||||||
|
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/proxy-04:/var/lib/zabbix/db_data:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-proxy-active-05:
|
||||||
|
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-proxy-active-05
|
||||||
|
depends_on:
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "10105:10051"
|
||||||
|
environment:
|
||||||
|
- ZBX_HOSTNAME=zabbix-proxy-active-05
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- ZBX_PROXYMODE=0
|
||||||
|
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/proxy-05:/var/lib/zabbix/db_data:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
zabbix-proxy-active-06:
|
||||||
|
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
container_name: zabbix-proxy-active-06
|
||||||
|
depends_on:
|
||||||
|
- zabbix-server
|
||||||
|
ports:
|
||||||
|
- "10106:10051"
|
||||||
|
environment:
|
||||||
|
- ZBX_HOSTNAME=zabbix-proxy-active-06
|
||||||
|
- ZBX_SERVER_HOST=zabbix-server
|
||||||
|
- ZBX_PROXYMODE=0
|
||||||
|
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
volumes:
|
||||||
|
- ./zabbix/proxy-06:/var/lib/zabbix/db_data:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- zabbix-net
|
||||||
|
|
||||||
|
# zabbix-proxy-passive-03:
|
||||||
|
# image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
|
||||||
|
# container_name: zabbix-proxy-passive-03
|
||||||
|
# depends_on:
|
||||||
|
# - zabbix-server
|
||||||
|
# ports:
|
||||||
|
# - "10103:10051"
|
||||||
|
# environment:
|
||||||
|
# - ZBX_HOSTNAME=zabbix-proxy-passive-03
|
||||||
|
# - ZBX_SERVER_HOST=zabbix-server
|
||||||
|
# - ZBX_PROXYMODE=1
|
||||||
|
# - ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
|
||||||
|
# - ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
|
||||||
|
# - ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
|
||||||
|
# - ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
|
||||||
|
# - ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
|
||||||
|
# volumes:
|
||||||
|
# - ./zabbix/proxy-03:/var/lib/zabbix/db_data:rw
|
||||||
|
# restart: unless-stopped
|
||||||
|
# networks:
|
||||||
|
# - zabbix-net
|
||||||
|
|
||||||
|
networks:
|
||||||
|
zabbix-net:
|
||||||
|
driver: bridge
|
||||||
Reference in New Issue
Block a user