diff --git a/DOC/howto/event-trigger.md b/DOC/howto/event-trigger.md index 57c8821..de37716 100644 --- a/DOC/howto/event-trigger.md +++ b/DOC/howto/event-trigger.md @@ -43,6 +43,11 @@ Examples: "Load high" if uptime | sed 's/.*load average: //; s/,.*//' >= 4 ``` +A ready-made starter set (CPU, memory, disk space/health, NVMe, network, +processes) lives in `config/event-rules.template` — copy it to +`~/.config/linux_post_install/event.env` or add the lines you want via +`pos system event-trigger config`. + Behavior: - The check runs on every pass. Non-numeric/empty output, or an unparseable diff --git a/config/event-rules.template b/config/event-rules.template new file mode 100644 index 0000000..1c1aa0d --- /dev/null +++ b/config/event-rules.template @@ -0,0 +1,54 @@ +# eventer rules template — copy/paste into ~/.config/linux_post_install/event.env +# (or add each line via: pos system event-trigger config). +# +# One independent rule per line. Grammar: +# +# "" if +# (no message → auto-composed) +# +# optional quoted alert text (quote-stripped) +# any shell command; first numeric output is the value +# > < >= <= == != +# number with optional unit suffix: 60c, 80%, 10g +# +# Rules alert once on false→true (plus one recovery message on true→false) +# via lib/notify.sh — Telegram by default. State is tracked per rule in +# ~/.local/share/linux_post_install/eventer/state/ (keyed by rule-line hash). +# +# Verify each check on your machine first (adjust device names): +# sensors -u coretemp-isa-0000 | awk '/Package id 0:/{f=1} f && /temp1_input:/{print $2; exit}' +# smartctl -A /dev/sda | awk '/Temperature_Celsius/{print $10}' +# nvme smart-log /dev/nvme0 +# vnstat -d 1 +# +# ── CPU (lm-sensors) ────────────────────────────────────────────── +"CPU too hot" if sensors -u coretemp-isa-0000 | awk '/Package id 0:/{f=1} f && /temp1_input:/{print $2; exit}' > 60c +"CPU hot warning" if sensors -u coretemp-isa-0000 | awk '/Package id 0:/{f=1} f && /temp1_input:/{print $2; exit}' > 55c +"Load high" if uptime | sed 's/.*load average: //' | awk -F'[, ]+' '{print $1}' > 4 + +# ── Memory (procps, always present) ─────────────────────────────── +"RAM high" if free -m | awk '/^Mem:/{print int($3/$2*100)}' > 90% +"Swap in use" if free -m | awk '/^Swap:/{print $3+0}' > 1000 + +# ── Disk space ─────────────────────────────────────────────────── +"Disk / nearly full" if df -P / | awk 'NR==2{print $5+0}' > 80% +"Disk /srv full" if df -P /srv | awk 'NR==2{print $5+0}' > 85% + +# ── Disk health (smartmontools) ────────────────────────────────── +"Disk sda SMART fail" if smartctl -H /dev/sda | grep -q PASSED && echo 0 || echo 1 == 1 +"SDA hot" if smartctl -A /dev/sda | awk '/Temperature_Celsius/{print $10}' > 50c + +# ── NVMe (nvme-cli) ────────────────────────────────────────────── +"NVMe hot" if nvme smart-log /dev/nvme0 | awk '/^temperature/{print $3}' > 65c +"NVMe wear-out" if nvme smart-log /dev/nvme0 | awk '/percentage used/{print $NF+0}' > 80% + +# ── Network (vnstat needs ~1 day of collected data) ────────────── +"Big traffic day" if vnstat -d 1 | awk '/today/{print $10+0}' > 20000 +"Link eth0 down" if ethtool eth0 | grep -q 'Link detected: yes' && echo 0 || echo 1 == 1 + +# ── Processes ──────────────────────────────────────────────────── +"Top CPU 80%" if top -bn1 | awk 'NR==8{print $9+0}' > 80% +"Top MEM 90%" if top -bn1 | awk 'NR==8{print $10+0}' > 90% + +# Manage rules interactively: pos system event-trigger config +# Schedule the timer: pos system event-trigger enable 5m