fix(alerts): correct telegram execution truth
This commit is contained in:
@@ -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)
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user