Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions config/alertmanager/alertmanager.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
global:
resolve_timeout: 5m
smtp_require_tls: false

route:
group_by: [alertname, cluster]
group_wait: 30s
group_interval: 5m
receiver: 'ntfy'
group_by: ['alertname', 'cluster', 'service']
group_wait: 10s
group_interval: 10s
repeat_interval: 12h
receiver: default
routes:
- match:
severity: critical
receiver: default
continue: true
alertname: Watchdog
receiver: 'null'

receivers:
- name: default
# Uncomment and configure one of the following:
# webhook_configs:
# - url: http://gotify:80/message?token=YOUR_TOKEN
# slack_configs:
# - api_url: YOUR_SLACK_WEBHOOK
# channel: #alerts
- name: 'null'
- name: 'ntfy'
webhook_configs:
- url: 'https://ntfy.${DOMAIN}/homelab-alerts'
send_resolved: true

inhibit_rules:
- source_match:
severity: critical
severity: 'critical'
target_match:
severity: warning
equal: [alertname, instance]
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
8 changes: 8 additions & 0 deletions config/ntfy/server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
base-url: https://ntfy.${DOMAIN}
auth-default-access: deny-all
behind-proxy: true
cache-file: /var/cache/ntfy/cache.db
auth-file: /var/lib/ntfy/user.db
database: /var/lib/ntfy/db.db
attachment-cache-dir: /var/cache/ntfy/attachments
log-level: info
23 changes: 23 additions & 0 deletions scripts/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# 统一通知脚本,调用此接口而不是直接调用 ntfy/Gotify API
# 用法: notify.sh <topic> <title> <message> [priority]

set -e

if [ $# -lt 3 ]; then
echo "用法: $0 <topic> <title> <message> [priority]"
exit 1
fi

TOPIC=$1
TITLE=$2
MESSAGE=$3
PRIORITY=${4:-default}

NTFY_URL=${NTFY_URL:-"http://ntfy:80"}

curl -X POST \
-H "Title: $TITLE" \
-H "Priority: $PRIORITY" \
-d "$MESSAGE" \
"${NTFY_URL}/${TOPIC}"
15 changes: 15 additions & 0 deletions stacks/notifications/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 通知服务栈

统一通知中心,让所有服务都能向用户推送通知。

## 服务清单

| 服务 | 镜像 | 用途 |
|------|------|------|
| ntfy | `binwiederhier/ntfy:v2.11.0` | 推送通知服务器 |
| Gotify | `gotify/server:2.5.0` | 备用推送服务 |

## 核心配置

### ntfy 配置