2025-07-23 11:51:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Zamba LXC Toolbox - Service Installer
|
|
|
|
# Service: icinga-stack
|
|
|
|
#
|
2025-07-23 17:00:18 +02:00
|
|
|
# Description: Führt die Installation und Konfiguration des Icinga2 Stacks mit MariaDB durch.
|
2025-07-23 12:43:19 +02:00
|
|
|
# Dieses Skript ist eigenständig und verwendet nur Standard-OS-Befehle.
|
2025-07-23 11:51:39 +02:00
|
|
|
#
|
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
# --- Internal Helper Functions ---
|
|
|
|
_generate_local_password() {
|
|
|
|
openssl rand -base64 "$1"
|
|
|
|
}
|
2025-07-23 11:51:39 +02:00
|
|
|
|
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
# --- Service Functions (_install, _configure, _setup, _info) ---
|
2025-07-23 11:51:39 +02:00
|
|
|
|
|
|
|
_install() {
|
2025-07-23 12:43:19 +02:00
|
|
|
echo ""
|
|
|
|
echo "================================================="
|
2025-07-23 17:00:18 +02:00
|
|
|
echo " Phase 1: Installation der Pakete (MariaDB Edition)"
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "================================================="
|
|
|
|
echo ""
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] System wird aktualisiert und Basispakete werden installiert."
|
2025-07-23 11:51:39 +02:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2025-07-23 12:43:19 +02:00
|
|
|
apt-get update
|
|
|
|
apt-get install -y wget gpg apt-transport-https curl sudo lsb-release
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Repositories für Icinga, InfluxDB und Grafana werden hinzugefügt."
|
2025-07-23 11:51:39 +02:00
|
|
|
# Icinga Repo
|
|
|
|
if [ ! -f /etc/apt/sources.list.d/icinga.list ]; then
|
2025-07-23 12:43:19 +02:00
|
|
|
curl -fsSL https://packages.icinga.com/icinga.key | gpg --dearmor -o /usr/share/keyrings/icinga-archive-keyring.gpg
|
2025-07-23 11:51:39 +02:00
|
|
|
echo "deb [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/debian icinga-${OS_CODENAME} main" > /etc/apt/sources.list.d/icinga.list
|
|
|
|
fi
|
|
|
|
|
|
|
|
# InfluxDB Repo
|
|
|
|
if [ ! -f /etc/apt/sources.list.d/influxdata.list ]; then
|
2025-07-23 12:43:19 +02:00
|
|
|
curl -fsSL https://repos.influxdata.com/influxdata-archive_compat.key | gpg --dearmor -o /usr/share/keyrings/influxdata-archive_compat-keyring.gpg
|
2025-07-23 11:51:39 +02:00
|
|
|
echo "deb [signed-by=/usr/share/keyrings/influxdata-archive_compat-keyring.gpg] https://repos.influxdata.com/debian ${OS_CODENAME} stable" > /etc/apt/sources.list.d/influxdata.list
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Grafana Repo
|
|
|
|
if [ ! -f /etc/apt/sources.list.d/grafana.list ]; then
|
2025-07-23 12:43:19 +02:00
|
|
|
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor -o /usr/share/keyrings/grafana-archive-keyring.gpg
|
2025-07-23 11:51:39 +02:00
|
|
|
echo "deb [signed-by=/usr/share/keyrings/grafana-archive-keyring.gpg] https://apt.grafana.com stable main" > /etc/apt/sources.list.d/grafana.list
|
|
|
|
fi
|
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Paketlisten werden erneut aktualisiert."
|
|
|
|
apt-get update
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Hauptkomponenten werden installiert (PHP Version: ${PHP_VERSION})."
|
|
|
|
apt-get install -y \
|
2025-07-23 17:00:18 +02:00
|
|
|
icinga2 icinga2-ido-mysql \
|
|
|
|
nginx php${PHP_VERSION}-fpm php${PHP_VERSION}-mysql php${PHP_VERSION}-intl php${PHP_VERSION}-imagick php${PHP_VERSION}-xml php${PHP_VERSION}-gd php${PHP_VERSION}-ldap \
|
|
|
|
mariadb-server mariadb-client \
|
2025-07-23 11:51:39 +02:00
|
|
|
influxdb2 \
|
|
|
|
grafana \
|
|
|
|
icingaweb2 icingacli
|
|
|
|
|
2025-07-23 13:15:39 +02:00
|
|
|
echo "[INFO] Icinga Web 2 Module (Abhängigkeiten für Director) werden installiert."
|
|
|
|
install_icinga_module() {
|
|
|
|
local module_name="$1"
|
|
|
|
local repo_name="$2"
|
|
|
|
if [ ! -d "/usr/share/icingaweb2/modules/${module_name}" ]; then
|
|
|
|
echo "[INFO] Installiere Modul: ${module_name}"
|
|
|
|
local version=$(curl -s "https://api.github.com/repos/Icinga/${repo_name}/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
|
|
|
|
wget -O "/tmp/${module_name}.tar.gz" "https://github.com/Icinga/${repo_name}/archive/refs/tags/v${version}.tar.gz"
|
|
|
|
tar -C /usr/share/icingaweb2/modules -xzf "/tmp/${module_name}.tar.gz"
|
|
|
|
mv "/usr/share/icingaweb2/modules/${repo_name}-"* "/usr/share/icingaweb2/modules/${module_name}"
|
|
|
|
rm "/tmp/${module_name}.tar.gz"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_icinga_module "ipl" "icingaweb2-module-ipl"
|
|
|
|
install_icinga_module "reactbundle" "icingaweb2-module-reactbundle"
|
2025-07-23 17:10:09 +02:00
|
|
|
install_icinga_module "incubator" "icingaweb2-module-incubator"
|
2025-07-23 13:15:39 +02:00
|
|
|
install_icinga_module "director" "icingaweb2-module-director"
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Systemd Services werden aktiviert."
|
2025-07-23 17:00:18 +02:00
|
|
|
systemctl enable --now icinga2 mariadb nginx php${PHP_VERSION}-fpm influxdb grafana-server
|
2025-07-23 11:51:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_configure() {
|
2025-07-23 12:43:19 +02:00
|
|
|
echo ""
|
|
|
|
echo "================================================="
|
2025-07-23 17:00:18 +02:00
|
|
|
echo " Phase 2: Konfiguration der Komponenten (MariaDB Edition)"
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "================================================="
|
|
|
|
echo ""
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 14:12:56 +02:00
|
|
|
# 1. Passwörter generieren
|
|
|
|
echo "[INFO] Passwörter und API-Keys werden generiert."
|
2025-07-23 12:43:19 +02:00
|
|
|
ICINGAWEB_DB_PASS=$(_generate_local_password 24)
|
|
|
|
DIRECTOR_DB_PASS=$(_generate_local_password 24)
|
|
|
|
ICINGA_IDO_DB_PASS=$(_generate_local_password 24)
|
|
|
|
ICINGA_API_USER_PASS=$(_generate_local_password 24)
|
|
|
|
ICINGAWEB_ADMIN_PASS=$(_generate_local_password 16)
|
|
|
|
GRAFANA_ADMIN_PASS=$(_generate_local_password 16)
|
|
|
|
INFLUX_ADMIN_TOKEN=$(_generate_local_password 40)
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 17:00:18 +02:00
|
|
|
# 2. MariaDB konfigurieren
|
|
|
|
echo "[INFO] MariaDB wird konfiguriert."
|
|
|
|
mysql -e "CREATE DATABASE IF NOT EXISTS icingaweb2 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
|
|
mysql -e "CREATE DATABASE IF NOT EXISTS director CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
|
|
mysql -e "CREATE DATABASE IF NOT EXISTS icinga_ido CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
|
|
|
|
|
|
mysql -e "CREATE USER IF NOT EXISTS 'icingaweb2'@'localhost' IDENTIFIED BY '${ICINGAWEB_DB_PASS}';"
|
|
|
|
mysql -e "CREATE USER IF NOT EXISTS 'director'@'localhost' IDENTIFIED BY '${DIRECTOR_DB_PASS}';"
|
|
|
|
mysql -e "CREATE USER IF NOT EXISTS 'icinga_ido'@'localhost' IDENTIFIED BY '${ICINGA_IDO_DB_PASS}';"
|
|
|
|
|
|
|
|
mysql -e "GRANT ALL PRIVILEGES ON icingaweb2.* TO 'icingaweb2'@'localhost';"
|
|
|
|
mysql -e "GRANT ALL PRIVILEGES ON director.* TO 'director'@'localhost';"
|
|
|
|
mysql -e "GRANT ALL PRIVILEGES ON icinga_ido.* TO 'icinga_ido'@'localhost';"
|
|
|
|
mysql -e "FLUSH PRIVILEGES;"
|
|
|
|
|
|
|
|
# 3. InfluxDB 2 konfigurieren
|
2025-07-23 14:12:56 +02:00
|
|
|
echo "[INFO] InfluxDB 2 wird konfiguriert."
|
|
|
|
influx setup --skip-verify --username admin --password "$GRAFANA_ADMIN_PASS" --org icinga --bucket icinga --token "$INFLUX_ADMIN_TOKEN" -f
|
|
|
|
INFLUX_ICINGA_TOKEN=$(influx auth create --org icinga --all-access --json | grep -oP '"token": "\K[^"]+')
|
2025-07-23 17:00:18 +02:00
|
|
|
if [ -z "$INFLUX_ICINGA_TOKEN" ]; then echo "[ERROR] Konnte InfluxDB Token nicht erstellen." >&2; exit 1; fi
|
2025-07-23 14:12:56 +02:00
|
|
|
|
2025-07-23 17:00:18 +02:00
|
|
|
# 4. Credentials-Datei schreiben
|
2025-07-23 14:12:56 +02:00
|
|
|
echo "[INFO] Zugangsdaten werden in ${CRED_FILE} gespeichert."
|
2025-07-23 17:00:18 +02:00
|
|
|
mkdir -p "$(dirname "$CRED_FILE")" && chmod 700 "$(dirname "$CRED_FILE")"
|
2025-07-23 11:51:39 +02:00
|
|
|
{
|
|
|
|
echo "# --- Icinga Monitoring Stack Credentials ---"
|
2025-07-23 17:00:18 +02:00
|
|
|
echo "URL: https://${ZAMBA_HOSTNAME:-$(hostname -f)}/icingaweb2; Benutzer: icingaadmin; Passwort: ${ICINGAWEB_ADMIN_PASS}"
|
|
|
|
echo "URL: https://${ZAMBA_HOSTNAME:-$(hostname -f)}/grafana; Benutzer: admin; Passwort: ${GRAFANA_ADMIN_PASS}"
|
|
|
|
echo "InfluxDB Admin Token: ${INFLUX_ADMIN_TOKEN}"
|
|
|
|
echo "Icinga Director API: Benutzer: director; Passwort: ${ICINGA_API_USER_PASS}"
|
|
|
|
} > "$CRED_FILE" && chmod 600 "$CRED_FILE"
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 14:12:56 +02:00
|
|
|
# 5. Icinga2 Konfigurationsdateien schreiben
|
2025-07-23 13:15:39 +02:00
|
|
|
echo "[INFO] Icinga2 Konfigurationsdateien werden geschrieben."
|
2025-07-23 17:00:18 +02:00
|
|
|
bash -c "cat > /etc/icinga2/features-available/ido-mysql.conf" <<EOF
|
|
|
|
object IdoMysqlConnection "ido-mysql" {
|
2025-07-23 11:51:39 +02:00
|
|
|
user = "icinga_ido",
|
|
|
|
password = "${ICINGA_IDO_DB_PASS}",
|
|
|
|
host = "localhost",
|
|
|
|
database = "icinga_ido"
|
|
|
|
}
|
|
|
|
EOF
|
2025-07-23 12:43:19 +02:00
|
|
|
bash -c "cat > /etc/icinga2/conf.d/api-users.conf" <<EOF
|
2025-07-23 11:51:39 +02:00
|
|
|
object ApiUser "director" {
|
|
|
|
password = "${ICINGA_API_USER_PASS}"
|
|
|
|
permissions = [ "object/modify/*", "object/query/*", "status/query", "actions/*", "events/*" ]
|
|
|
|
}
|
|
|
|
EOF
|
2025-07-23 12:43:19 +02:00
|
|
|
bash -c "cat > /etc/icinga2/features-available/influxdb2-writer.conf" <<EOF
|
2025-07-23 11:51:39 +02:00
|
|
|
object Influxdb2Writer "influxdb2-writer" {
|
|
|
|
host = "http://127.0.0.1:8086"
|
|
|
|
organization = "icinga"
|
|
|
|
bucket = "icinga"
|
2025-07-23 17:18:32 +02:00
|
|
|
auth_token = "${INFLUX_ICINGA_TOKEN}"
|
2025-07-23 11:51:39 +02:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2025-07-23 14:12:56 +02:00
|
|
|
# 6. Icinga Web 2 Konfigurationsdateien schreiben
|
2025-07-23 13:15:39 +02:00
|
|
|
echo "[INFO] Icinga Web 2 Konfigurationsdateien werden geschrieben."
|
2025-07-23 11:51:39 +02:00
|
|
|
mkdir -p /etc/icingaweb2
|
2025-07-23 12:43:19 +02:00
|
|
|
bash -c "cat > /etc/icingaweb2/resources.ini" <<EOF
|
2025-07-23 11:51:39 +02:00
|
|
|
[icingaweb_db]
|
|
|
|
type = "db"
|
2025-07-23 17:00:18 +02:00
|
|
|
db = "mysql"
|
2025-07-23 11:51:39 +02:00
|
|
|
host = "localhost"
|
|
|
|
dbname = "icingaweb2"
|
|
|
|
username = "icingaweb2"
|
|
|
|
password = "${ICINGAWEB_DB_PASS}"
|
|
|
|
|
|
|
|
[director_db]
|
|
|
|
type = "db"
|
2025-07-23 17:00:18 +02:00
|
|
|
db = "mysql"
|
2025-07-23 11:51:39 +02:00
|
|
|
host = "localhost"
|
|
|
|
dbname = "director"
|
|
|
|
username = "director"
|
|
|
|
password = "${DIRECTOR_DB_PASS}"
|
|
|
|
|
|
|
|
[icinga_ido]
|
|
|
|
type = "db"
|
2025-07-23 17:00:18 +02:00
|
|
|
db = "mysql"
|
2025-07-23 11:51:39 +02:00
|
|
|
host = "localhost"
|
|
|
|
dbname = "icinga_ido"
|
|
|
|
username = "icinga_ido"
|
|
|
|
password = "${ICINGA_IDO_DB_PASS}"
|
|
|
|
EOF
|
|
|
|
|
2025-07-23 14:12:56 +02:00
|
|
|
# 7. Grafana konfigurieren
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Grafana wird konfiguriert."
|
2025-07-23 14:39:28 +02:00
|
|
|
systemctl stop grafana-server
|
2025-07-23 12:43:19 +02:00
|
|
|
grafana-cli admin reset-admin-password "$GRAFANA_ADMIN_PASS"
|
2025-07-23 14:39:28 +02:00
|
|
|
systemctl start grafana-server
|
2025-07-23 11:51:39 +02:00
|
|
|
|
|
|
|
mkdir -p /etc/grafana/provisioning/datasources
|
2025-07-23 12:43:19 +02:00
|
|
|
bash -c "cat > /etc/grafana/provisioning/datasources/influxdb.yaml" <<EOF
|
2025-07-23 11:51:39 +02:00
|
|
|
apiVersion: 1
|
|
|
|
datasources:
|
|
|
|
- name: InfluxDB-Icinga
|
|
|
|
type: influxdb
|
|
|
|
access: proxy
|
|
|
|
url: http://localhost:8086
|
2025-07-23 17:00:18 +02:00
|
|
|
jsonData: { version: "Flux", organization: "icinga", defaultBucket: "icinga" }
|
|
|
|
secureJsonData: { token: "${INFLUX_ICINGA_TOKEN}" }
|
2025-07-23 11:51:39 +02:00
|
|
|
EOF
|
2025-07-23 12:43:19 +02:00
|
|
|
chown grafana:grafana /etc/grafana/provisioning/datasources/influxdb.yaml
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 17:10:09 +02:00
|
|
|
# 8. Nginx TLS Konfiguration
|
|
|
|
echo "[INFO] Nginx für TLS wird konfiguriert."
|
2025-07-23 11:51:39 +02:00
|
|
|
mkdir -p /etc/nginx/ssl
|
|
|
|
if [ ! -L /etc/nginx/ssl/fullchain.pem ]; then
|
2025-07-23 12:43:19 +02:00
|
|
|
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/nginx/ssl/fullchain.pem
|
|
|
|
ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/nginx/ssl/privkey.pem
|
2025-07-23 11:51:39 +02:00
|
|
|
fi
|
2025-07-23 13:15:39 +02:00
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
bash -c "cat > /etc/nginx/sites-available/icinga-stack" <<EOF
|
2025-07-23 11:51:39 +02:00
|
|
|
server {
|
|
|
|
listen 80;
|
2025-07-23 12:43:19 +02:00
|
|
|
server_name ${ZAMBA_HOSTNAME:-$(hostname -f)};
|
2025-07-23 11:51:39 +02:00
|
|
|
return 301 https://\$host\$request_uri;
|
|
|
|
}
|
|
|
|
server {
|
|
|
|
listen 443 ssl http2;
|
2025-07-23 12:43:19 +02:00
|
|
|
server_name ${ZAMBA_HOSTNAME:-$(hostname -f)};
|
2025-07-23 11:51:39 +02:00
|
|
|
ssl_certificate /etc/nginx/ssl/fullchain.pem;
|
|
|
|
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
|
|
|
|
root /usr/share/icingaweb2/public;
|
|
|
|
index index.php;
|
2025-07-23 17:00:18 +02:00
|
|
|
location / { try_files \$uri \$uri/ /index.php\$is_args\$args; }
|
2025-07-23 11:51:39 +02:00
|
|
|
location ~ \.php$ {
|
|
|
|
include fastcgi_params;
|
|
|
|
fastcgi_pass unix:/run/php/php${PHP_VERSION}-fpm.sock;
|
|
|
|
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
|
|
|
|
fastcgi_param ICINGAWEB_CONFIGDIR /etc/icingaweb2;
|
|
|
|
}
|
|
|
|
location /grafana {
|
|
|
|
proxy_pass http://localhost:3000;
|
|
|
|
proxy_set_header Host \$http_host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
2025-07-23 12:43:19 +02:00
|
|
|
ln -sf /etc/nginx/sites-available/icinga-stack /etc/nginx/sites-enabled/
|
2025-07-23 11:51:39 +02:00
|
|
|
rm -f /etc/nginx/sites-enabled/default
|
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' "/etc/php/${PHP_VERSION}/fpm/php.ini"
|
|
|
|
sed -i "s|;date.timezone =|date.timezone = $(cat /etc/timezone)|" "/etc/php/${PHP_VERSION}/fpm/php.ini"
|
2025-07-23 11:51:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_setup() {
|
2025-07-23 12:43:19 +02:00
|
|
|
echo ""
|
|
|
|
echo "================================================="
|
2025-07-23 17:00:18 +02:00
|
|
|
echo " Phase 3: Setup und finaler Neustart (MariaDB Edition)"
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "================================================="
|
|
|
|
echo ""
|
2025-07-23 11:51:39 +02:00
|
|
|
|
2025-07-23 17:10:09 +02:00
|
|
|
echo "[INFO] Icinga2 API wird initialisiert und Zertifikate werden erstellt."
|
|
|
|
icinga2 api setup
|
|
|
|
|
2025-07-23 17:00:18 +02:00
|
|
|
echo "[INFO] Warte auf MariaDB-Dienst..."
|
|
|
|
while ! mysqladmin ping -h localhost --silent; do
|
|
|
|
echo "[INFO] MariaDB ist noch nicht bereit, warte 2 Sekunden..."
|
2025-07-23 14:49:19 +02:00
|
|
|
sleep 2
|
|
|
|
done
|
2025-07-23 17:00:18 +02:00
|
|
|
echo "[INFO] MariaDB ist bereit."
|
2025-07-23 14:49:19 +02:00
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Datenbank-Schemas werden importiert."
|
2025-07-23 17:00:18 +02:00
|
|
|
local IDO_SCHEMA="/usr/share/icinga2-ido-mysql/schema/mysql.sql"
|
|
|
|
local IWEB_SCHEMA="/usr/share/icingaweb2/schema/mysql.schema.sql"
|
2025-07-23 21:22:24 +02:00
|
|
|
local DIRECTOR_SCHEMA="/usr/share/icingaweb2/modules/director/schema/mysql.sql"
|
2025-07-23 14:49:19 +02:00
|
|
|
|
2025-07-23 17:00:18 +02:00
|
|
|
if [ ! -f "$IDO_SCHEMA" ]; then echo "[ERROR] IDO-Schema nicht gefunden: $IDO_SCHEMA" >&2; exit 1; fi
|
|
|
|
if [ ! -f "$IWEB_SCHEMA" ]; then echo "[ERROR] IcingaWeb-Schema nicht gefunden: $IWEB_SCHEMA" >&2; exit 1; fi
|
2025-07-23 21:22:24 +02:00
|
|
|
if [ ! -f "$DIRECTOR_SCHEMA" ]; then echo "[ERROR] Director-Schema nicht gefunden: $DIRECTOR_SCHEMA" >&2; exit 1; fi
|
2025-07-23 14:49:19 +02:00
|
|
|
|
2025-07-23 17:49:48 +02:00
|
|
|
if ! mysql -e "use icinga_ido; show tables;" | grep -q "icinga_dbversion"; then
|
2025-07-23 14:49:19 +02:00
|
|
|
echo "[INFO] Importiere Icinga IDO-Schema..."
|
2025-07-23 17:00:18 +02:00
|
|
|
mysql icinga_ido < "$IDO_SCHEMA"
|
2025-07-23 14:49:19 +02:00
|
|
|
fi
|
|
|
|
|
2025-07-23 17:49:48 +02:00
|
|
|
if ! mysql -e "use icingaweb2; show tables;" | grep -q "icingaweb_user"; then
|
2025-07-23 14:49:19 +02:00
|
|
|
echo "[INFO] Importiere IcingaWeb2-Schema..."
|
2025-07-23 17:00:18 +02:00
|
|
|
mysql icingaweb2 < "$IWEB_SCHEMA"
|
2025-07-23 14:49:19 +02:00
|
|
|
fi
|
|
|
|
|
2025-07-23 21:22:24 +02:00
|
|
|
if ! mysql -e "use director; show tables;" | grep -q "director_datafield"; then
|
|
|
|
echo "[INFO] Importiere Icinga Director-Schema..."
|
|
|
|
mysql director < "$DIRECTOR_SCHEMA"
|
|
|
|
fi
|
|
|
|
|
2025-07-23 13:15:39 +02:00
|
|
|
echo "[INFO] Icinga2 Features werden aktiviert."
|
2025-07-23 17:00:18 +02:00
|
|
|
icinga2 feature enable ido-mysql api influxdb2-writer >/dev/null
|
2025-07-23 13:15:39 +02:00
|
|
|
|
2025-07-23 17:10:09 +02:00
|
|
|
echo "[INFO] Icinga Web 2 Module werden in korrekter Reihenfolge aktiviert."
|
2025-07-23 13:15:39 +02:00
|
|
|
icingacli module enable ipl
|
|
|
|
icingacli module enable reactbundle
|
2025-07-23 17:10:09 +02:00
|
|
|
icingacli module enable incubator
|
2025-07-23 13:15:39 +02:00
|
|
|
icingacli module enable director
|
|
|
|
|
2025-07-23 17:49:48 +02:00
|
|
|
echo "[INFO] Erstelle Icinga Web 2 Kernkonfiguration."
|
|
|
|
bash -c "cat > /etc/icingaweb2/config.ini" <<EOF
|
|
|
|
[global]
|
|
|
|
show_stacktraces = "0"
|
|
|
|
config_backend = "db"
|
|
|
|
config_resource = "icingaweb_db"
|
|
|
|
|
|
|
|
[logging]
|
|
|
|
log = "file"
|
|
|
|
log_file = "/var/log/icingaweb2/icingaweb2.log"
|
|
|
|
level = "ERROR"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
bash -c "cat > /etc/icingaweb2/authentication.ini" <<EOF
|
|
|
|
[icinga-web-admin]
|
|
|
|
backend = "db"
|
|
|
|
resource = "icingaweb_db"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
bash -c "cat > /etc/icingaweb2/roles.ini" <<EOF
|
|
|
|
[Administrators]
|
|
|
|
users = "icingaadmin"
|
|
|
|
permissions = "*"
|
|
|
|
groups = "Administrators"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
mkdir -p /etc/icingaweb2/modules/monitoring
|
|
|
|
bash -c "cat > /etc/icingaweb2/modules/monitoring/config.ini" <<EOF
|
|
|
|
[backend]
|
|
|
|
type = "ido"
|
|
|
|
resource = "icinga_ido"
|
2025-07-23 21:47:01 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# KORREKTUR: Director API-Verbindung wird direkt in die Konfigurationsdatei geschrieben.
|
|
|
|
mkdir -p /etc/icingaweb2/modules/director
|
|
|
|
bash -c "cat > /etc/icingaweb2/modules/director/config.ini" <<EOF
|
|
|
|
[db]
|
|
|
|
resource = "director_db"
|
|
|
|
|
|
|
|
[api]
|
|
|
|
endpoint = "localhost"
|
|
|
|
user = "director"
|
|
|
|
password = "${ICINGA_API_USER_PASS}"
|
2025-07-23 17:49:48 +02:00
|
|
|
EOF
|
|
|
|
|
2025-07-23 17:00:18 +02:00
|
|
|
echo "[INFO] Alle Services werden neu gestartet."
|
|
|
|
systemctl restart mariadb
|
2025-07-23 13:15:39 +02:00
|
|
|
systemctl restart icinga2
|
|
|
|
systemctl restart php${PHP_VERSION}-fpm
|
|
|
|
systemctl restart nginx
|
|
|
|
systemctl restart grafana-server
|
|
|
|
|
2025-07-23 19:21:18 +02:00
|
|
|
echo "[INFO] Füge Icinga Web 2 Admin-Benutzer direkt in die Datenbank ein."
|
2025-07-23 20:50:03 +02:00
|
|
|
local PASSWORD_HASH=$(php -r "echo password_hash('${ICINGAWEB_ADMIN_PASS}', PASSWORD_BCRYPT);")
|
2025-07-23 19:21:18 +02:00
|
|
|
mysql icingaweb2 -e "INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('icingaadmin', 1, '${PASSWORD_HASH}') ON DUPLICATE KEY UPDATE password_hash='${PASSWORD_HASH}';"
|
|
|
|
|
2025-07-23 13:15:39 +02:00
|
|
|
echo "[INFO] Warte auf Icinga2 API..."
|
2025-07-23 17:00:18 +02:00
|
|
|
sleep 15
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Icinga Director Setup wird ausgeführt."
|
2025-07-23 21:47:01 +02:00
|
|
|
# KORREKTUR: kickstart wird nicht mehr benötigt.
|
2025-07-23 21:00:52 +02:00
|
|
|
icingacli director migration run
|
2025-07-23 11:51:39 +02:00
|
|
|
icingacli director automation run
|
2025-07-23 12:43:19 +02:00
|
|
|
echo "[INFO] Director Konfiguration wird angewendet."
|
|
|
|
icingacli director config deploy
|
2025-07-23 11:51:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_info() {
|
2025-07-23 12:43:19 +02:00
|
|
|
echo ""
|
|
|
|
echo "================================================="
|
|
|
|
echo " Installation des Icinga Monitoring Stacks abgeschlossen"
|
|
|
|
echo "================================================="
|
2025-07-23 11:51:39 +02:00
|
|
|
echo ""
|
|
|
|
echo "Die Konfiguration wurde erfolgreich abgeschlossen."
|
|
|
|
echo "Alle notwendigen Passwörter, Logins und API-Keys wurden generiert."
|
|
|
|
echo ""
|
|
|
|
echo "Sie finden alle Zugangsdaten in der folgenden Datei:"
|
2025-07-23 12:43:19 +02:00
|
|
|
echo " ${CRED_FILE}"
|
2025-07-23 11:51:39 +02:00
|
|
|
echo ""
|
|
|
|
echo "Wichtige URLs:"
|
2025-07-23 12:43:19 +02:00
|
|
|
echo " Icinga Web 2: https://${ZAMBA_HOSTNAME:-$(hostname -f)}/icingaweb2"
|
|
|
|
echo " Grafana: https://${ZAMBA_HOSTNAME:-$(hostname -f)}/grafana"
|
2025-07-23 11:51:39 +02:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2025-07-23 12:43:19 +02:00
|
|
|
# --- Main Execution Logic ---
|
2025-07-23 13:38:16 +02:00
|
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "[ERROR] Dieses Skript muss als Root ausgeführt werden."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -f ./constants-service.conf ]; then
|
|
|
|
source ./constants-service.conf
|
|
|
|
else
|
|
|
|
echo "[ERROR] Die Datei 'constants-service.conf' wird für den Standalone-Betrieb benötigt."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ZAMBA_HOSTNAME=${ZAMBA_HOSTNAME:-$(hostname -f)}
|
|
|
|
set -euo pipefail
|
|
|
|
_install
|
|
|
|
_configure
|
|
|
|
_setup
|
|
|
|
_info
|
|
|
|
set +euo pipefail
|
|
|
|
exit 0
|
|
|
|
fi
|