-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_slack_webhook.sh
More file actions
executable file
·96 lines (87 loc) · 3.21 KB
/
setup_slack_webhook.sh
File metadata and controls
executable file
·96 lines (87 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Interactive script to set up Slack webhook URL
ENV_FILE=".env"
EXAMPLE_FILE=".env.example"
echo "=========================================="
echo "🔧 Slack Webhook Setup"
echo "=========================================="
echo ""
# Check if .env exists, create from example if not
if [ ! -f "$ENV_FILE" ]; then
echo "📝 Creating .env file from .env.example..."
if [ -f "$EXAMPLE_FILE" ]; then
cp "$EXAMPLE_FILE" "$ENV_FILE"
echo "✅ Created .env file"
else
touch "$ENV_FILE"
echo "✅ Created empty .env file"
fi
echo ""
fi
# Check if already configured
if grep -q "^SENTINEL_SLACK_WEBHOOK_URL=" "$ENV_FILE" 2>/dev/null; then
CURRENT_URL=$(grep "^SENTINEL_SLACK_WEBHOOK_URL=" "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | tr -d "'")
if [ -n "$CURRENT_URL" ] && [ "$CURRENT_URL" != "" ]; then
echo "📋 Current Slack webhook URL:"
echo " ${CURRENT_URL:0:50}..."
echo ""
read -p "Do you want to update it? (y/N): " UPDATE
if [ "$UPDATE" != "y" ] && [ "$UPDATE" != "Y" ]; then
echo "✅ Keeping existing configuration"
exit 0
fi
fi
fi
echo "📖 How to get your Slack webhook URL:"
echo ""
echo " 1. Go to: https://api.slack.com/apps"
echo " 2. Click 'Create New App' → 'From scratch'"
echo " 3. Name your app (e.g., 'Sentinel AIOps')"
echo " 4. Select your workspace"
echo " 5. Go to 'Incoming Webhooks' in the left sidebar"
echo " 6. Toggle 'Activate Incoming Webhooks' to ON"
echo " 7. Click 'Add New Webhook to Workspace'"
echo " 8. Select channel: #all-aitubby"
echo " 9. Copy the webhook URL (starts with https://hooks.slack.com/services/...)"
echo ""
echo " OR use an existing webhook URL if you have one"
echo ""
read -p "Enter your Slack webhook URL: " WEBHOOK_URL
# Validate URL format
if [[ ! "$WEBHOOK_URL" =~ ^https://hooks\.slack\.com/services/ ]]; then
echo ""
echo "⚠️ Warning: URL doesn't match expected format (https://hooks.slack.com/services/...)"
read -p "Continue anyway? (y/N): " CONTINUE
if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then
echo "❌ Setup cancelled"
exit 1
fi
fi
# Update or add to .env
if grep -q "^SENTINEL_SLACK_WEBHOOK_URL=" "$ENV_FILE" 2>/dev/null; then
# Update existing
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s|^SENTINEL_SLACK_WEBHOOK_URL=.*|SENTINEL_SLACK_WEBHOOK_URL=$WEBHOOK_URL|" "$ENV_FILE"
else
# Linux
sed -i "s|^SENTINEL_SLACK_WEBHOOK_URL=.*|SENTINEL_SLACK_WEBHOOK_URL=$WEBHOOK_URL|" "$ENV_FILE"
fi
echo "✅ Updated SENTINEL_SLACK_WEBHOOK_URL in .env"
else
# Add new
echo "" >> "$ENV_FILE"
echo "# Slack Webhook Configuration" >> "$ENV_FILE"
echo "SENTINEL_SLACK_WEBHOOK_URL=$WEBHOOK_URL" >> "$ENV_FILE"
echo "✅ Added SENTINEL_SLACK_WEBHOOK_URL to .env"
fi
echo ""
echo "=========================================="
echo "✅ Slack webhook configured!"
echo "=========================================="
echo ""
echo "📋 Next steps:"
echo " 1. Test the webhook: python test_webhook_slack.py"
echo " 2. Start the server: python start_api_server.py"
echo " 3. Test via API: ./test_webhook_api.sh"
echo ""