fix(alerts): correct telegram execution truth
Some checks failed
CD Pipeline / tests (push) Failing after 52s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
Code Review / ai-code-review (push) Successful in 11s

This commit is contained in:
Your Name
2026-05-31 13:58:21 +08:00
parent 943a6feacf
commit e2ab879636
15 changed files with 624 additions and 49 deletions

View File

@@ -18,7 +18,7 @@ Task 2.3: validate_kubectl_command() 白名單驗證
import pytest
from src.services.alert_rule_engine import validate_kubectl_command
from src.services.alert_rule_engine import match_rule, validate_kubectl_command
# =============================================================================
@@ -76,6 +76,49 @@ class TestValidKubectlCommands:
assert validate_kubectl_command(cmd) is False
class TestRuleMatchingSpecificity:
"""具名 alertname 規則不得被寬鬆 message keyword 誤命中。"""
def test_host_storage_alert_does_not_match_minio_disk_rule(self):
ctx = {
"alert_type": "host",
"severity": "critical",
"source": "prometheus",
"target_resource": "dirty-reboot-evidence",
"namespace": "awoooi-prod",
"message": "HostPreviousBootStorageErrorsDetected storage dirty reboot evidence",
"labels": {
"alertname": "HostPreviousBootStorageErrorsDetected",
"instance": "192.168.0.110:9100",
},
}
result = match_rule(ctx)
assert result is not None
assert result["rule_id"] != "minio_disk_high"
assert "/data/minio" not in result.get("kubectl_command", "")
def test_exact_minio_disk_alert_still_matches_minio_rule(self):
ctx = {
"alert_type": "storage",
"severity": "critical",
"source": "prometheus",
"target_resource": "minio",
"namespace": "awoooi-prod",
"message": "MinIO disk usage high",
"labels": {
"alertname": "MinioDiskUsageHigh",
"instance": "192.168.0.110:9000",
},
}
result = match_rule(ctx)
assert result is not None
assert result["rule_id"] == "minio_disk_high"
# =============================================================================
# 阻擋案例(應返回 False
# =============================================================================