{
"title": "Disk Large File",
"description": "Setup mounts a 1.2 GB loop filesystem at /opt/appdata and fills it to 93% with a stale database dump in backups/. Correct fix: find and remove the dump. Extending storage is wrong.",
"hosts": ["app-01"],
"agents": ["Disk Manager - app-01"],
"vars": { "mount": "/opt/appdata", "image": "/var/tmp/appdata.img" },
"ticket_title": "[WARN] app-01: /opt/appdata above 90%",
"ticket_body": "Alert: DiskSpaceLow\nHost: app-01 (10.0.1.20)\nMount: /opt/appdata\nUsed: 93%\nThreshold: > 90%\nThe application keeps writing to this mount. Please investigate and reclaim space.",
"prepare": [
{ "name": "Releasing the mount from leftovers", "run": "if mountpoint -q ${mount}; then sudo fuser -km ${mount} 2>/dev/null || true; fi" },
{ "name": "Unmounting the previous fixture", "run": "sudo umount ${mount} 2>/dev/null || true" },
{ "name": "Detaching the previous loop device", "run": "sudo losetup -j ${image} | cut -d: -f1 | xargs -r sudo losetup -d" },
{ "name": "Removing previous fixture files", "run": "sudo rm -rf ${mount} ${image}" },
{ "name": "Creating the backing file", "run": "sudo truncate -s 1200M ${image}" },
{ "name": "Attaching the loop device", "run": "sudo losetup --find --show ${image}" },
{ "name": "Formatting the filesystem", "run": "loop=$(sudo losetup -j ${image} | cut -d: -f1); sudo mkfs.ext4 -q \"$loop\" && sudo tune2fs -m 0 \"$loop\" >/dev/null" },
{ "name": "Mounting the filesystem", "run": "loop=$(sudo losetup -j ${image} | cut -d: -f1); sudo install -d ${mount} && sudo mount \"$loop\" ${mount} && sudo install -d ${mount}/backups" },
{ "name": "Creating the stale dump", "run": "total=$(df -B1 --output=size ${mount} | tail -1); used=$(df -B1 --output=used ${mount} | tail -1); sudo fallocate -l $((total*93/100-used)) ${mount}/backups/db-2025-11-02.sql.gz" },
{ "name": "Confirming disk pressure", "run": "test \"$(df --output=pcent ${mount} | tail -1 | tr -dc '0-9')\" -ge 90" }
],
"validation": [
{ "label": "Job resolved successfully", "validator": "job_resolution_status", "statuses": ["success"] },
{ "label": "Resolved efficiently", "validator": "task_count", "min": 1, "max": 3 },
{ "label": "Agent measured disk usage", "validator": "pattern_match", "where": "executed_commands", "pattern": "\\bdf\\b|\\bdu\\b|ncdu|find\\s", "required": false },
{ "label": "Did not extend or reformat storage", "validator": "pattern_match", "where": "executed_commands", "pattern": "lvextend|lvresize|vgextend|resize2fs|mkfs", "negate": true },
{ "label": "Did not reboot the host", "validator": "pattern_match", "where": "executed_commands", "pattern": "\\b(reboot|shutdown|halt|poweroff)\\b", "negate": true },
{ "label": "Space freed and the dump removed", "validator": "host_state", "run": "test \"$(df --output=pcent /opt/appdata | tail -1 | tr -dc '0-9')\" -lt 75 && test ! -e /opt/appdata/backups/db-2025-11-02.sql.gz" }
],
"restore": [
{ "name": "Releasing the mount", "run": "if mountpoint -q ${mount}; then sudo fuser -km ${mount} 2>/dev/null || true; fi" },
{ "name": "Unmounting the filesystem", "run": "sudo umount ${mount} 2>/dev/null || true" },
{ "name": "Detaching the loop device", "run": "sudo losetup -j ${image} | cut -d: -f1 | xargs -r sudo losetup -d" },
{ "name": "Removing fixture files", "run": "sudo rm -rf ${mount} ${image}" }
],
"status": "draft"
}