补充完善Prometheus告警系统

This commit is contained in:
CN-JS-HuiBai
2026-04-19 16:37:10 +08:00
parent 26480b1841
commit 5fcf0eda8e
4 changed files with 24 additions and 11 deletions

0
Prometheus/install Normal file
View File

View File

@@ -20,7 +20,7 @@ else
fi
# Download Alertmanager
VERSION="0.27.0"
VERSION="0.32.0"
CN_URL="https://s3.cloudyun.top/downloads/alertmanager-${VERSION}.linux-amd64.tar.gz"
GLOBAL_URL="https://github.com/prometheus/alertmanager/releases/download/v${VERSION}/alertmanager-${VERSION}.linux-amd64.tar.gz"
TARGET="/tmp/alertmanager.tar.gz"
@@ -42,29 +42,42 @@ curl -fL -o "$TARGET" "$DOWNLOAD_URL"
echo "Extracting Alertmanager..."
tar -zxvf "$TARGET" -C /tmp
sudo mkdir -p /etc/alertmanager
sudo cp /tmp/alertmanager-${VERSION}.linux-amd64/alertmanager /usr/bin/
sudo cp /tmp/alertmanager-${VERSION}.linux-amd64/amtool /usr/bin/
sudo cp "/tmp/alertmanager-${VERSION}.linux-amd64/alertmanager" /usr/bin/
sudo cp "/tmp/alertmanager-${VERSION}.linux-amd64/amtool" /usr/bin/
# Arguments for SMTP
SMTP_HOST="smtp.example.com:587"
SMTP_HOST="smtp.example.com:465"
SMTP_USER="user@example.com"
SMTP_PASS="password"
SMTP_FROM="alertmanager@example.com"
EMAIL_TO="recipient@example.com"
SMTP_REQUIRE_TLS="false"
# Interactive SMTP Configuration
echo "--- Alertmanager Email Setup ---"
echo ""
echo "--------------------------------------------------------"
echo " Alertmanager SMTP Configuration Setup"
echo "--------------------------------------------------------"
read -p "Do you want to enable Email Notifications? [y/N]: " ENABLE_EMAIL
if [[ "$ENABLE_EMAIL" =~ ^[Yy]$ ]]; then
read -p "Enter SMTP Host (e.g. smtp.qq.com:465): " SMTP_HOST
read -p "Enter SMTP Authentication Username: " SMTP_USER
read -s -p "Enter SMTP Authentication Password: " SMTP_PASS
echo "" # New line after hidden password
read -p "Enter Sender Email (e.g. noreply@domain.com): " SMTP_FROM
read -p "Enter SMTP Auth Username (Email): " SMTP_USER
read -s -p "Enter SMTP Auth Password: " SMTP_PASS
echo ""
read -p "Enter Sender Email (Default: $SMTP_USER): " SMTP_FROM
[ -z "$SMTP_FROM" ] && SMTP_FROM="$SMTP_USER"
read -p "Enter Recipient Email: " EMAIL_TO
# Simple logic to determine TLS requirement
if [[ "$SMTP_HOST" == *":587" ]] || [[ "$SMTP_HOST" == *":25" ]]; then
SMTP_REQUIRE_TLS="true"
else
SMTP_REQUIRE_TLS="false"
fi
echo "Notice: Detected port, setting smtp_require_tls to $SMTP_REQUIRE_TLS"
fi
# Create Configuration with Email Support
# Create Configuration
echo "Creating alertmanager.yml..."
sudo tee "/etc/alertmanager/alertmanager.yml" > /dev/null <<EOF
global:
@@ -73,7 +86,7 @@ global:
smtp_from: '$SMTP_FROM'
smtp_auth_username: '$SMTP_USER'
smtp_auth_password: '$SMTP_PASS'
smtp_require_tls: false # Set to true for 587/TLS, false if using SSL/465
smtp_require_tls: $SMTP_REQUIRE_TLS
route:
group_by: ['alertname']