Skip to content

Commit 660b091

Browse files
committed
feat: clear unused env variables, update deployment scripts and add webhook auth
1 parent 3128295 commit 660b091

File tree

8 files changed

+28
-45
lines changed

8 files changed

+28
-45
lines changed

.env.example

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ ENVIRONMENT=production # production or local
88
TZ=Europe/Rome
99
PHP_VERSION=8.3 # PHP version to use in containers
1010

11-
# Podman socket path (running using user root or personal user)
12-
# Leave it blank, it will be generated automatically
13-
PODMAN_SOCKET=
14-
1511
# ============================================
1612
# DOMAIN CONFIGURATION
1713
# ============================================

README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,7 @@ The middleware handles alert lifecycle (firing/resolved) and intelligently updat
2222

2323
To deploy the infrastructure, ensure the following prerequisites are met:
2424

25-
1. **Configured SSH Key**:
26-
- The user must have an SSH key configured on their system.
27-
- The key must be authorized to access private repositories on GitHub.
28-
29-
2. **Add GitHub to known_hosts**:
30-
- Run the following command to add GitHub's fingerprint to the `known_hosts` file:
31-
```bash
32-
ssh-keyscan github.com >> ~/.ssh/known_hosts
33-
```
34-
- This command should be executed inside the user's `.ssh` directory.
35-
36-
3. **System Requirements**:
25+
1. **System Requirements**:
3726
- **Bash**: Ensure Bash is installed as the default shell.
3827
- **Podman**: Install Podman for container management.
3928
- **Podman-Compose**: Install Podman-Compose using the following commands to avoid issues with outdated versions:
@@ -143,7 +132,7 @@ nano middleware/config.json
143132
- `status_page_group`: Name of the group that will be created on the status page
144133
- `status_page_components`: Array of visible component names that belong to this group
145134

146-
Each visible component referenced in your Prometheus labels must be mapped to a group in this configuration. The `setup.py` script will use this mapping to automatically create groups and organize components during initialization.
135+
Each visible component referenced in your Prometheus labels must be mapped to a group in this configuration. The `setup-components.py` script will use this mapping to automatically create groups and organize components during initialization.
147136

148137
**Required Prometheus labels** for status page integration:
149138

@@ -196,7 +185,6 @@ For local development (without HTTPS), ensure your `.env` is properly configured
196185
ENVIRONMENT=local
197186
CACHET_DOMAIN=localhost
198187
WEBHOOK_DOMAIN=localhost
199-
TRAEFIK_DOMAIN=localhost
200188
APP_ENV=local
201189
APP_DEBUG=true
202190
APP_URL=http://localhost:8080

deploy.sh

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,22 @@ fi
114114
# Configure webhook authentication in Traefik middlewares
115115
echo ""
116116
echo "Configuring webhook authentication..."
117-
if [ -n "${WEBHOOK_USERNAME}" ] && [ -n "${WEBHOOK_PASSWORD}" ]; then
118-
# Check if htpasswd is available
117+
if [ -n "${WEBHOOK_BASIC_AUTH}" ]; then
118+
# Use the string specified in .env
119+
sed -i "s|WEBHOOK_CREDENTIALS_PLACEHOLDER|${WEBHOOK_BASIC_AUTH}|g" traefik/dynamic/middlewares.yml
120+
echo -e "${GREEN}${NC} Webhook authentication configured: ${WEBHOOK_BASIC_AUTH}"
121+
else
122+
# Generate default authentication admin:admin
119123
if ! command -v htpasswd &> /dev/null; then
120-
echo -e "${YELLOW}Warning: htpasswd not found. Installing apache2-utils...${NC}"
124+
echo -e "${YELLOW}htpasswd not found. Installing apache2-utils...${NC}"
121125
sudo apt-get install -y apache2-utils || {
122126
echo -e "${RED}Error: Failed to install apache2-utils. Please install it manually.${NC}"
123127
exit 1
124128
}
125129
fi
126-
127-
# Generate SHA hash for webhook credentials
128-
WEBHOOK_HASH=$(htpasswd -nbs "${WEBHOOK_USERNAME}" "${WEBHOOK_PASSWORD}")
129-
130-
# Update middlewares.yml with the generated hash
131-
sed -i 's|.*WEBHOOK_CREDENTIALS_PLACEHOLDER.*| - "'"${WEBHOOK_HASH}"'"|g' traefik/dynamic/middlewares.yml
132-
133-
echo -e "${GREEN}${NC} Webhook authentication configured for user: ${WEBHOOK_USERNAME}"
134-
else
135-
echo -e "${YELLOW}Warning: WEBHOOK_USERNAME or WEBHOOK_PASSWORD not set in .env${NC}"
130+
DEFAULT_AUTH=$(htpasswd -nb admin admin | cut -d':' -f2)
131+
sed -i "s|WEBHOOK_CREDENTIALS_PLACEHOLDER|admin:${DEFAULT_AUTH}|g" traefik/dynamic/middlewares.yml
132+
echo -e "${YELLOW}Warning: WEBHOOK_BASIC_AUTH not set in .env. Using default admin:admin.${NC}"
136133
fi
137134

138135
echo ""
@@ -214,8 +211,6 @@ echo "=========================================="
214211
echo "Starting Middleware, Initializing Components"
215212
echo "=========================================="
216213

217-
fi
218-
219214
# Start middleware container
220215
echo "Starting middleware container..."
221216
podman-compose up -d middleware
@@ -239,7 +234,7 @@ if [ $attempt -eq $max_attempts ]; then
239234
echo "If middleware keeps failing, check logs with: podman logs cachet-middleware"
240235
fi
241236

242-
# Setup components (run setup.py) with user prompt
237+
# Setup components (run setup-components.py) with user prompt
243238
echo ""
244239
echo "Initializing Cachet components from Prometheus configuration..."
245240
if [ ! -f middleware/prometheus.yml ]; then
@@ -256,16 +251,16 @@ echo " - Component groups: middleware/config.json"
256251
target_count=$(grep -c "status_page_alert: true" middleware/prometheus.yml || echo "0")
257252
echo "Found approximately ${target_count} targets with status_page_alert enabled"
258253
echo ""
259-
read -p "Do you want to run setup.py to create components? This will DELETE all existing components! (y/n) " -n 1 -r
254+
read -p "Do you want to run setup-components.py to create components? This will DELETE all existing components! (y/n) " -n 1 -r
260255
echo
261256
if [[ $REPLY =~ ^[Yy]$ ]]; then
262-
echo "Running setup.py inside middleware container..."
263-
if podman exec cachet-middleware python3 /app/setup.py --file /app/prometheus.yml; then
257+
echo "Running setup-components.py inside middleware container..."
258+
if podman exec cachet-middleware python3 /app/setup-components.py --file /app/prometheus.yml; then
264259
echo -e "${GREEN}${NC} Components created successfully!"
265260
else
266261
echo -e "${RED}${NC} Failed to create components"
267-
echo "You can run setup.py manually with:"
268-
echo " podman exec cachet-middleware python3 /app/setup.py --file /app/prometheus.yml"
262+
echo "You can run setup-components.py manually with:"
263+
echo " podman exec cachet-middleware python3 /app/setup-components.py --file /app/prometheus.yml"
269264
exit 1
270265
fi
271266
else

middleware/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ WORKDIR /app
3030
# Copy application files
3131
COPY alerts-middleware.py .
3232
COPY healthcheck.py .
33-
COPY setup.py .
33+
COPY setup-components.py .
3434

3535
# Make healthcheck script executable
3636
RUN chmod +x healthcheck.py

middleware/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Python Flask middleware that receives webhook notifications from Prometheus Aler
1010
- **Critical Targets**: Special logic for critical targets (force Major Outage on visible components)
1111
- **Smart Status Calculation**: Calculates visible component status by aggregating invisible component statuses
1212
- **Intelligent Incident Management**: Creates incidents only when visible component goes to Major Outage
13-
- **YAML Configuration**: Automatic component setup from Prometheus file with `setup.py`
13+
- **YAML Configuration**: Automatic component setup from Prometheus file with `setup-components.py`
1414

1515
## Architecture
1616

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
http:
2+
middlewares:
3+
webhook-auth:
4+
basicAuth:
5+
users:
6+
- "WEBHOOK_CREDENTIALS_PLACEHOLDER"

traefik/dynamic/routers.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ http:
88
- websecure
99
tls:
1010
certResolver: '{{ env "CERT_RESOLVER" | default "letsencrypt" }}'
11-
middlewares:
12-
- https-headers
13-
- redirect-to-https
1411
{{ else }}
1512
entryPoints:
1613
- web
@@ -26,8 +23,9 @@ http:
2623
certResolver: '{{ env "CERT_RESOLVER" | default "letsencrypt" }}'
2724
middlewares:
2825
- webhook-auth
29-
- redirect-to-https
3026
{{ else }}
3127
entryPoints:
3228
- web
29+
middlewares:
30+
- webhook-auth
3331
{{ end }}

0 commit comments

Comments
 (0)