Files
patrickandClaude Sonnet 5.5 9c4f7366eb
test / pytest (3.11) (push) Canceled after 0s
test / pytest (3.13) (push) Canceled after 0s
feat: Phase 6 prompt versioning with test area, retention
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 02:17:01 +01:00

43 lines
1.4 KiB
Python

from dataclasses import dataclass
from ..models import STATE_NAMES
from .validation import PromptError
LABEL_MAX = 200
OUTPUT_MAX = 2000
@dataclass(frozen=True)
class SampleAlert:
host: str
service: str
state: int
output: str
ZPOOL_SAMPLE = SampleAlert(
host="kosext100.krs.local",
service="zpool status",
state=1,
output=("RaidZ: One or more devices has experienced an unrecoverable error. An attempt was made to "
"correct the error. Applications are unaffected. Determine if the device needs to be replaced, "
"and clear the errors using 'zpool clear' or replace the device with 'zpool replace'."),
)
STATE_CHOICES = tuple(STATE_NAMES.items())
def sample_from_row(row: dict) -> SampleAlert:
return SampleAlert(str(row["host"]), str(row["service"]), int(row["state"]), str(row["output"]))
def parse_sample(host: str, service: str, state: str, output: str) -> SampleAlert:
host, service, output = host.strip(), service.strip(), output.strip()
if not host or not service:
raise PromptError("Host und Service sind Pflicht.")
if max(len(host), len(service)) > LABEL_MAX or len(output) > OUTPUT_MAX:
raise PromptError("Host, Service oder Plugin-Output ist zu lang.")
if not state.isdecimal() or int(state) not in STATE_NAMES:
raise PromptError("Ungültiger Status.")
return SampleAlert(host, service, int(state), output)