feat: Initial v0.9 release with API Key authentication

## v0.9.20260325_144654

### Features
- API Key Authentication System
- Job Worker System
- V2 Backup Versioning

### Bug Fixes
- get_processor_results_by_job column mapping

Co-authored-by: OpenCode
This commit is contained in:
accusys
2026-03-25 14:52:51 +08:00
parent 47e86b696f
commit 383201cacd
193 changed files with 40268 additions and 422 deletions
+86 -6
View File
@@ -5,6 +5,12 @@
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MONITOR_DIR="$(dirname "$SCRIPT_DIR")"
# 載入密碼配置
if [ -f "$MONITOR_DIR/common/load_credentials.sh" ]; then
source "$MONITOR_DIR/common/load_credentials.sh"
fi
LOG_DIR="/Users/accusys/momentry/log/monitor"
mkdir -p "$LOG_DIR"
@@ -27,7 +33,7 @@ record_service() {
local response_time=$3
local error_msg=$4
psql -U accusys -h localhost -d momentry << EOF 2>/dev/null
PGPASSWORD="$PG_PASSWORD" psql -U "$PG_USER" -h localhost -d momentry << EOF 2>/dev/null
INSERT INTO monitor_services (service_name, service_type, status, response_time_ms, error_message, checked_at)
VALUES ('$service', 'service', '$status', $response_time, '$error_msg', NOW());
EOF
@@ -36,7 +42,7 @@ EOF
# 檢查 PostgreSQL
check_postgresql() {
local start=$(date +%s%N)
if pg_isready -h localhost -p 5432 -U accusys > /dev/null 2>&1; then
if PGPASSWORD="$PG_PASSWORD" pg_isready -h localhost -p 5432 -U "$PG_USER" > /dev/null 2>&1; then
local end=$(date +%s%N)
local ms=$(( (end - start) / 1000000 ))
echo -e "${GREEN}${NC} PostgreSQL (5432) - ${ms}ms"
@@ -52,7 +58,7 @@ check_postgresql() {
# 檢查 Redis
check_redis() {
local start=$(date +%s%N)
if redis-cli -a accusys ping 2>/dev/null | grep -q "PONG"; then
if redis-cli -a "$REDIS_PASSWORD" ping 2>/dev/null | grep -q "PONG"; then
local end=$(date +%s%N)
local ms=$(( (end - start) / 1000000 ))
echo -e "${GREEN}${NC} Redis (6379) - ${ms}ms"
@@ -68,7 +74,7 @@ check_redis() {
# 檢查 MariaDB
check_mariadb() {
local start=$(date +%s%N)
if mysql -u accusys -e "SELECT 1" > /dev/null 2>&1; then
if mysql -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" -e "SELECT 1" > /dev/null 2>&1; then
local end=$(date +%s%N)
local ms=$(( (end - start) / 1000000 ))
echo -e "${GREEN}${NC} MariaDB (3306) - ${ms}ms"
@@ -142,9 +148,16 @@ check_sftpgo() {
local end=$(date +%s%N)
local ms=$(( (end - start) / 1000000 ))
# 檢查 SFTP 端口
local sftp_port=$(lsof -i :2022 2>/dev/null | grep -c LISTEN || echo "0")
local webdav_port=$(lsof -i :8090 2>/dev/null | grep -c LISTEN || echo "0")
# 檢查 PostgreSQL 連接
local db_conn=$(PGPASSWORD="$PG_PASSWORD" psql -U "$PG_USER" -h localhost -d postgres -t -c "SELECT numbackends FROM pg_stat_database WHERE datname='sftpgo';" 2>/dev/null | xargs || echo "0")
if [ "$http_code" = "200" ] || [ "$http_code" = "301" ] || [ "$http_code" = "302" ]; then
echo -e "${GREEN}${NC} SFTPGo (8080) - ${ms}ms"
record_service "sftpgo" "up" "$ms" ""
echo -e "${GREEN}${NC} SFTPGo (8080) - ${ms}ms | SFTP:$sftp_port | WebDAV:$webdav_port | DB:$db_conn"
record_service "sftpgo" "up" "$ms" "SFTP:$sftp_port WebDAV:$webdav_port DB:$db_conn"
return 0
else
echo -e "${RED}${NC} SFTPGo (8080) - HTTP $http_code"
@@ -153,6 +166,73 @@ check_sftpgo() {
fi
}
# SFTPGo 詳細監控
check_sftpgo_detailed() {
echo ""
echo "=== SFTPGo 詳細監控 ==="
# 1. 服務狀態
echo "1. 服務狀態:"
ps aux | grep sftpgo | grep -v grep | awk '{print " PID: "$2" CMD: "$11" "$12}'
# 2. 端口監聽
echo "2. 端口監聽:"
echo " - HTTP (8080): $(lsof -i :8080 2>/dev/null | grep -c LISTEN || echo '0')"
echo " - SFTP (2022): $(lsof -i :2022 2>/dev/null | grep -c LISTEN || echo '0')"
echo " - WebDAV (8090): $(lsof -i :8090 2>/dev/null | grep -c LISTEN || echo '0')"
# 3. PostgreSQL 連接
echo "3. PostgreSQL 連接:"
PGPASSWORD="$PG_PASSWORD" psql -U "$PG_USER" -h localhost -d postgres -c "SELECT numbackends, xact_commit, xact_rollback FROM pg_stat_database WHERE datname='sftpgo';" 2>/dev/null | grep -v "numbackends\|^$\|row)" || echo " 無數據"
# 4. 用戶統計
echo "4. 用戶統計:"
PGPASSWORD="$SFTPGO_PASSWORD" psql -U "$SFTPGO_USER" -h localhost -d sftpgo -c "SELECT 'users' as type, COUNT(*) as count FROM users UNION ALL SELECT 'admins', COUNT(*) FROM admins UNION ALL SELECT 'api_keys', COUNT(*) FROM api_keys;" 2>/dev/null | grep -v "^$\|type\|^(\|row)" || echo " 無數據"
# 5. 數據庫大小
echo "5. 數據庫大小:"
PGPASSWORD="$PG_PASSWORD" psql -U "$PG_USER" -h localhost -d postgres -t -c "SELECT pg_size_pretty(pg_database_size('sftpgo'));" 2>/dev/null | xargs || echo " 無法獲取"
# 6. 磁盤使用
echo "6. 文件存儲使用:"
du -sh /Users/accusys/momentry/var/sftpgo/data/ 2>/dev/null | awk '{print " "$2": "$1}'
}
# SFTPGo 認證失敗監控
check_sftpgo_auth_failures() {
local log_file="/Users/accusys/momentry/log/sftpgo.log"
local threshold=${1:-5} # 默認 5 次失敗
if [ ! -f "$log_file" ]; then
return 0
fi
# 檢查過去 1 小時的認證失敗
local failures=$(grep -i "authentication error\|invalid credentials\|login failed\|auth error" "$log_file" 2>/dev/null | wc -l)
if [ "$failures" -gt "$threshold" ]; then
echo "⚠️ SFTPGo 認證失敗過多: $failures"
return 1
else
echo "✓ SFTPGo 認證失敗: $failures 次 (閾值: $threshold)"
return 0
fi
}
# SFTPGo 傳輸統計
check_sftpgo_transfers() {
echo ""
echo "=== SFTPGo 傳輸統計 ==="
# 檢查活動傳輸
local active_transfers=$(PGPASSWORD="$SFTPGO_PASSWORD" psql -U "$SFTPGO_USER" -h localhost -d sftpgo -t -c "SELECT COUNT(*) FROM active_transfers;" 2>/dev/null | xargs || echo "0")
echo "活動傳輸: $active_transfers"
# 檢查今日訪問IP
echo "今日訪問來源:"
tail -1000 /Users/accusys/momentry/log/sftpgo_access.log 2>/dev/null | grep -o '"remote_ip":"[^"]*"' | cut -d'"' -f4 | sort | uniq -c | sort -rn | head -5 | awk '{print " "$2": "$1" 次"}'
}
# 檢查 Ollama
check_ollama() {
local start=$(date +%s%N)