补充完善Prometheus告警系统
This commit is contained in:
0
Prometheus/install
Normal file
0
Prometheus/install
Normal file
@@ -20,7 +20,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Download Alertmanager
|
# Download Alertmanager
|
||||||
VERSION="0.27.0"
|
VERSION="0.32.0"
|
||||||
CN_URL="https://s3.cloudyun.top/downloads/alertmanager-${VERSION}.linux-amd64.tar.gz"
|
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"
|
GLOBAL_URL="https://github.com/prometheus/alertmanager/releases/download/v${VERSION}/alertmanager-${VERSION}.linux-amd64.tar.gz"
|
||||||
TARGET="/tmp/alertmanager.tar.gz"
|
TARGET="/tmp/alertmanager.tar.gz"
|
||||||
@@ -42,29 +42,42 @@ curl -fL -o "$TARGET" "$DOWNLOAD_URL"
|
|||||||
echo "Extracting Alertmanager..."
|
echo "Extracting Alertmanager..."
|
||||||
tar -zxvf "$TARGET" -C /tmp
|
tar -zxvf "$TARGET" -C /tmp
|
||||||
sudo mkdir -p /etc/alertmanager
|
sudo mkdir -p /etc/alertmanager
|
||||||
sudo cp /tmp/alertmanager-${VERSION}.linux-amd64/alertmanager /usr/bin/
|
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/amtool" /usr/bin/
|
||||||
|
|
||||||
# Arguments for SMTP
|
# Arguments for SMTP
|
||||||
SMTP_HOST="smtp.example.com:587"
|
SMTP_HOST="smtp.example.com:465"
|
||||||
SMTP_USER="user@example.com"
|
SMTP_USER="user@example.com"
|
||||||
SMTP_PASS="password"
|
SMTP_PASS="password"
|
||||||
SMTP_FROM="alertmanager@example.com"
|
SMTP_FROM="alertmanager@example.com"
|
||||||
EMAIL_TO="recipient@example.com"
|
EMAIL_TO="recipient@example.com"
|
||||||
|
SMTP_REQUIRE_TLS="false"
|
||||||
|
|
||||||
# Interactive SMTP Configuration
|
# 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
|
read -p "Do you want to enable Email Notifications? [y/N]: " ENABLE_EMAIL
|
||||||
if [[ "$ENABLE_EMAIL" =~ ^[Yy]$ ]]; then
|
if [[ "$ENABLE_EMAIL" =~ ^[Yy]$ ]]; then
|
||||||
read -p "Enter SMTP Host (e.g. smtp.qq.com:465): " SMTP_HOST
|
read -p "Enter SMTP Host (e.g. smtp.qq.com:465): " SMTP_HOST
|
||||||
read -p "Enter SMTP Authentication Username: " SMTP_USER
|
read -p "Enter SMTP Auth Username (Email): " SMTP_USER
|
||||||
read -s -p "Enter SMTP Authentication Password: " SMTP_PASS
|
read -s -p "Enter SMTP Auth Password: " SMTP_PASS
|
||||||
echo "" # New line after hidden password
|
echo ""
|
||||||
read -p "Enter Sender Email (e.g. noreply@domain.com): " SMTP_FROM
|
read -p "Enter Sender Email (Default: $SMTP_USER): " SMTP_FROM
|
||||||
|
[ -z "$SMTP_FROM" ] && SMTP_FROM="$SMTP_USER"
|
||||||
read -p "Enter Recipient Email: " EMAIL_TO
|
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
|
fi
|
||||||
|
|
||||||
# Create Configuration with Email Support
|
# Create Configuration
|
||||||
echo "Creating alertmanager.yml..."
|
echo "Creating alertmanager.yml..."
|
||||||
sudo tee "/etc/alertmanager/alertmanager.yml" > /dev/null <<EOF
|
sudo tee "/etc/alertmanager/alertmanager.yml" > /dev/null <<EOF
|
||||||
global:
|
global:
|
||||||
@@ -73,7 +86,7 @@ global:
|
|||||||
smtp_from: '$SMTP_FROM'
|
smtp_from: '$SMTP_FROM'
|
||||||
smtp_auth_username: '$SMTP_USER'
|
smtp_auth_username: '$SMTP_USER'
|
||||||
smtp_auth_password: '$SMTP_PASS'
|
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:
|
route:
|
||||||
group_by: ['alertname']
|
group_by: ['alertname']
|
||||||
|
|||||||
Reference in New Issue
Block a user