Добавить docs/services/lxc208-manage/alert/formatters.py
This commit is contained in:
parent
1d8e9251b4
commit
888677a056
78
docs/services/lxc208-manage/alert/formatters.py
Normal file
78
docs/services/lxc208-manage/alert/formatters.py
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
from alerts.utils import plural_sectors
|
||||||
|
|
||||||
|
|
||||||
|
def temperature(device, value=None):
|
||||||
|
if value is not None:
|
||||||
|
return f"\u26c3 {device:<8} {value}\u00b0C"
|
||||||
|
return f"\u26c3 {device:<8}"
|
||||||
|
|
||||||
|
|
||||||
|
def bad_blocks(device, value=None):
|
||||||
|
if value is not None:
|
||||||
|
return f"\u26c3 {device:<8} {value} {plural_sectors(value)}"
|
||||||
|
return f"\u26c3 {device:<8}"
|
||||||
|
|
||||||
|
|
||||||
|
def smart(device, value=None):
|
||||||
|
return f"\u26c3 {device:<8}"
|
||||||
|
|
||||||
|
|
||||||
|
def read_errors(device, value=None):
|
||||||
|
if value is not None:
|
||||||
|
return f"\u26c3 {device:<8} {value}"
|
||||||
|
return f"\u26c3 {device:<8}"
|
||||||
|
|
||||||
|
|
||||||
|
def zfs_pool(device, value=None):
|
||||||
|
return f"\U0001F3DB \u041e\u043b\u0438\u043c\u043f ({device})"
|
||||||
|
|
||||||
|
|
||||||
|
def backup_outdated(device, value=None):
|
||||||
|
return f"\U0001F4E6 {device:<8}"
|
||||||
|
|
||||||
|
|
||||||
|
def backup_success(info):
|
||||||
|
lines = []
|
||||||
|
for b in info.get("backups", []):
|
||||||
|
lines.append(f"\U0001F4E6 {b['backup_id']}")
|
||||||
|
lines.append(f"\U0001F5C3 {b['size']}")
|
||||||
|
if b.get("duration"):
|
||||||
|
lines.append(f"\u23F1 {b['duration']}")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
lines.append(f"\u23F0 {info.get('time', 'unknown')}")
|
||||||
|
if info.get("total_size"):
|
||||||
|
lines.append(f"\U0001F5C3 \u041e\u0431\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440: {info['total_size']}")
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def backup_failed(info):
|
||||||
|
lines = []
|
||||||
|
for b in info.get("backups", []):
|
||||||
|
icon = "\u2705" if b["status"] == "ok" else "\u274C"
|
||||||
|
lines.append(f"{icon} {b['backup_id']}")
|
||||||
|
lines.append(f"\U0001F5C3 {b['size']}")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
lines.append(f"\u23F0 {info.get('time', 'unknown')}")
|
||||||
|
if info.get("total_size"):
|
||||||
|
lines.append(f"\U0001F5C3 \u041e\u0431\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440: {info['total_size']}")
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
FORMATTERS = {
|
||||||
|
"temperature": temperature,
|
||||||
|
"bad_blocks": bad_blocks,
|
||||||
|
"smart": smart,
|
||||||
|
"read_errors": read_errors,
|
||||||
|
"zfs_pool": zfs_pool,
|
||||||
|
"backup_outdated": backup_outdated,
|
||||||
|
"backup_success": backup_success,
|
||||||
|
"backup_failed": backup_failed,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_formatter(name):
|
||||||
|
return FORMATTERS.get(name)
|
||||||
Loading…
Reference in New Issue
Block a user