Files
orrisroot a033dfa970
Validate / lint (push) Successful in 11m0s
Validate / import-test (push) Canceled after 1m12s
feat: bootstrap Zabbix template repository
Set up a repository for custom Zabbix templates and add the first
template for Dell PowerVault ME storage systems.

- Add conventions, version policy, and release documentation.
- Add validation, index, packaging, export, and import-test scripts.
- Add a disposable Zabbix test stack with version-aware imports.
- Add PowerVault ME SNMP exports for Zabbix 7.0 and 8.0.
- Cover system information, unit health, sensors, ports, and
  firmware revisions.
2026-11-03 14:40:19 +09:00

150 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
usage() {
cat <<'EOF'
Usage:
scripts/new_template.sh <category> <product> <template-name> [method]
Examples:
scripts/new_template.sh app apache "Apache by HTTP" http
scripts/new_template.sh network cisco/ios "Cisco IOS by SNMP" snmp
Arguments:
category app / db / network / os / hardware / cloud / container / web /
virtualization / power / printer / custom
product Directory name in lowercase snake_case. Use vendor/product
when grouping by vendor.
template-name Zabbix template technical name.
method Collection method (default: agent).
EOF
}
if [[ $# -lt 3 || $# -gt 4 ]]; then
usage
exit 1
fi
category="$1"
product="$2"
name="$3"
method="${4:-agent}"
allowed_categories="app db network os hardware cloud container web virtualization power printer san custom"
if ! [[ " $allowed_categories " == *" $category "* ]]; then
echo "ERROR: Unknown category: $category" >&2
usage
exit 1
fi
if ! [[ "$product" =~ ^[a-z0-9][a-z0-9_]*(/[a-z0-9][a-z0-9_]*)?$ ]]; then
echo "ERROR: product must use lowercase letters, digits, and _: $product" >&2
exit 1
fi
allowed_methods="agent agent2 snmp http ipmi jmx ssh telnet odbc external script calculated dependent other"
if ! [[ " $allowed_methods " == *" $method "* ]]; then
echo "ERROR: Unknown method: $method" >&2
exit 1
fi
if [[ "$name" == *$'\n'* || "$name" == *$'\r'* ]]; then
echo "ERROR: template-name must not contain line breaks." >&2
exit 1
fi
if [[ "$name" != *" by "* ]]; then
echo "WARN: Template names should include 'by <Method>': $name" >&2
fi
package_dir="$ROOT/templates/$category/$product"
if [[ -e "$package_dir" ]]; then
echo "ERROR: Already exists: ${package_dir#"$ROOT/"}" >&2
exit 1
fi
maintainer="${MAINTAINER:-$(git -C "$ROOT" config user.name 2>/dev/null || true)}"
maintainer="${maintainer:-unknown}"
vendor="${VENDOR:-${product%%/*}}"
zabbix_min="${ZABBIX_MIN:-7.0}"
if ! [[ "$zabbix_min" =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: ZABBIX_MIN must use the 7.0 format: $zabbix_min" >&2
exit 1
fi
mkdir -p "$package_dir/$zabbix_min"
# Escape sed replacement characters.
escape_sed() {
printf '%s' "$1" | sed -e 's/[\\&|]/\\&/g'
}
sed \
-e "s|{{TEMPLATE_NAME}}|$(escape_sed "$name")|g" \
-e "s|{{ID}}|$(escape_sed "$category/$product")|g" \
-e "s|{{CATEGORY}}|$(escape_sed "$category")|g" \
-e "s|{{VENDOR}}|$(escape_sed "$vendor")|g" \
-e "s|{{METHOD}}|$(escape_sed "$method")|g" \
-e "s|{{ZABBIX_MIN}}|$(escape_sed "$zabbix_min")|g" \
"$ROOT/docs/template-README.md" > "$package_dir/README.md"
cat > "$package_dir/CHANGELOG.md" <<EOF
# Changelog
All notable changes to this template will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.1.0] - $(date +%F)
### Added
- Initial release.
EOF
# Escape YAML double-quoted string characters.
escape_yaml() {
printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'
}
cat > "$package_dir/manifest.yaml" <<EOF
id: "$(escape_yaml "$category/$product")"
name: "$(escape_yaml "$name")"
description: "TODO: Describe what this template monitors in one line."
version: "0.1.0"
category: "$(escape_yaml "$category")"
vendor: "$(escape_yaml "$vendor")"
method: "$(escape_yaml "$method")"
zabbix:
min: "$(escape_yaml "$zabbix_min")"
max: null
tested: ["$(escape_yaml "$zabbix_min")"]
depends_on: []
source: original
maintainer: "$(escape_yaml "$maintainer")"
EOF
touch "$package_dir/$zabbix_min/.gitkeep"
if command -v python3 >/dev/null 2>&1 && python3 -c 'import yaml' >/dev/null 2>&1; then
if ! python3 "$ROOT/scripts/gen_index.py" >/dev/null; then
echo "WARN: Could not update the template index in README.md. Run 'make index'." >&2
fi
fi
echo "Created: ${package_dir#"$ROOT/"}"
echo
echo "Next steps:"
echo " 1. Export the template as YAML from Zabbix $zabbix_min."
echo " 2. Place the export in ${package_dir#"$ROOT/"}/$zabbix_min/ and remove .gitkeep."
echo " 3. Replace the TODO entries in README.md and manifest.yaml."
echo " 4. Run 'make lint'."