From 88a9a813053cd6052b15257e155128348607a8ea Mon Sep 17 00:00:00 2001
From: TheMindDev <236810990+theMindDeveloper@users.noreply.github.com>
Date: Fri, 9 Oct 2026 09:36:37 +0000
Subject: [PATCH 1/2] Alerts: soft 'is off' message for pve2/pve3; Disk-full
text fixed (a '<' made Telegram drop it)
---
.../grafana/provisioning/alerting/rules.yml | 54 ++++++++++++++++++-
docs/24-alerting.md | 12 ++++-
runbooks/23-alerts-to-telegram.md | 6 ++-
scripts/grafana/gen_alerts.py | 12 ++++-
4 files changed, 78 insertions(+), 6 deletions(-)
diff --git a/compose/monitoring/grafana/provisioning/alerting/rules.yml b/compose/monitoring/grafana/provisioning/alerting/rules.yml
index 4237927..f277507 100644
--- a/compose/monitoring/grafana/provisioning/alerting/rules.yml
+++ b/compose/monitoring/grafana/provisioning/alerting/rules.yml
@@ -380,6 +380,58 @@
"folder": "Homelab",
"interval": "1m",
"rules": [
+ {
+ "uid": "host-off",
+ "title": "Power-saving node off",
+ "condition": "C",
+ "for": "2m",
+ "noDataState": "OK",
+ "execErrState": "Error",
+ "labels": {
+ "severity": "warning"
+ },
+ "annotations": {
+ "summary": "{{ .Labels.node }} is off",
+ "description": "Fine if you switched it off yourself. You get an OK message when it's back."
+ },
+ "isPaused": false,
+ "data": [
+ {
+ "refId": "A",
+ "relativeTimeRange": {
+ "from": 900,
+ "to": 0
+ },
+ "datasourceUid": "prometheus-homelab",
+ "model": {
+ "refId": "A",
+ "expr": "max by (node) (up{job=\"proxmox-host\", node=~\"pve2|pve3\"}) < bool 1",
+ "instant": true,
+ "intervalMs": 60000,
+ "maxDataPoints": 43200
+ }
+ },
+ {
+ "refId": "C",
+ "datasourceUid": "__expr__",
+ "model": {
+ "refId": "C",
+ "type": "threshold",
+ "expression": "A",
+ "conditions": [
+ {
+ "evaluator": {
+ "type": "gt",
+ "params": [
+ 0
+ ]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
{
"uid": "disk-80",
"title": "Disk over 80%",
@@ -495,7 +547,7 @@
"severity": "warning"
},
"annotations": {
- "summary": "{{ .Labels.node }} {{ .Labels.mountpoint }} will be full in < 7 days",
+ "summary": "{{ .Labels.node }} {{ .Labels.mountpoint }} will be full within 7 days",
"description": "Based on the last 6 hours of growth."
},
"isPaused": false,
diff --git a/docs/24-alerting.md b/docs/24-alerting.md
index 4c27a22..7b5c747 100644
--- a/docs/24-alerting.md
+++ b/docs/24-alerting.md
@@ -135,6 +135,7 @@ link. Everything else is one tap away in Grafana.
| ๐ด | Internet down | the FRITZ!Box reports the WAN link down | 3 min |
| ๐ | Disk / storage over 80 % | as above, earlier | 30 min |
| ๐ | Disk full within 7 days | `predict_linear` over 6 h says < 0 in 7 days | 2 h |
+| ๐ | Power-saving node off | pve2 or pve3 cannot be scraped ("pve3 is off", then an OK message when it's back) | 2 min |
| ๐ | RAM over 90 % | any monitored machine | 15 min |
| ๐ | CrowdSec detected an attack | a CrowdSec scenario matched in the last 10 min | 0 |
| ๐ | Many failed SSH logins | > 10 in 10 min on LXC 102 (Loki) | 0 |
@@ -202,7 +203,7 @@ into a night of messages:
| Naive rule | Problem | Fix |
|---|---|---|
-| Host down | fires for pve2/pve3 every evening | not alerted for pve2/pve3 (`node!~"pve2\|pve3"`) |
+| Host down | fires for pve2/pve3 every evening | no ๐ด for pve2/pve3 (`node!~"pve2\|pve3"`); instead a soft ๐ "Power-saving node off": a warning, so never at night, and "fine if you switched it off yourself" |
| Guest with autostart stopped | every guest on pve2 counts as "stopped" | `and on (node) (up{job="proxmox-host"} == 1)`: only while its node is up |
| OPNsense stopped logging | OPNsense lives on pve2 | a two-query rule: Loki count **and** "pve2 is up" |
@@ -215,6 +216,15 @@ B (Prometheus): max(up{job="proxmox-host", node="pve2"}) or vector(0)
C (math): $A < 1 && $B == 1
```
+### 4b ยท A "<" in a message text drops the whole message
+
+"Disk full within 7 days" fired, but nothing ever reached Telegram. Its text
+said "will be full in < 7 days". The contact point sends with `parse_mode`
+HTML, so Telegram read `< 7` as a broken HTML tag and rejected the whole
+message (400 "Unsupported start tag"). Grafana only logs that error, every
+5 minutes. The text now says "within 7 days", and `gen_alerts.py` refuses any
+`<` or `&` in alert texts, so this cannot come back.
+
### 5 ยท `$` means three different things
- In **docker compose** files, `$` starts a variable. A regex like `($|/)` in a
diff --git a/runbooks/23-alerts-to-telegram.md b/runbooks/23-alerts-to-telegram.md
index 5e34370..56e1543 100644
--- a/runbooks/23-alerts-to-telegram.md
+++ b/runbooks/23-alerts-to-telegram.md
@@ -79,8 +79,9 @@ Rules are written in [`scripts/grafana/gen_alerts.py`](../scripts/grafana/gen_al
Read it once; each rule is one call with its query, message and `for`. Things
that are specific to this lab and that you will want to change:
-- `node!~"pve2|pve3"` in "Host down": those two nodes are switched off on purpose.
- Use your own names, or remove it.
+- `node!~"pve2|pve3"` in "Host down" and `node=~"pve2|pve3"` in "Power-saving node off":
+ those two nodes are switched off on purpose, so they get a soft ๐ "is off" instead of ๐ด.
+ Use your own names, or remove both.
- `id!="lxc/101"` in "Guest with autostart stopped": one guest excluded on
purpose. Remove it or put your own (with a comment saying why).
- `node="pve2"` in "OPNsense stopped sending logs": the node the firewall runs on.
@@ -148,6 +149,7 @@ then "โ
OK again" for both once it is back.
| rule shows "Error", message about `$$A` | `$$` written in a rule file: alert-rule files take `$A` literally, only contact points expand variables |
| a rule never fires in a test | the query lacks `bool` (`< 1` instead of `< bool 1`), see docs/24 |
| "internet down" when only the exporter died | `or vector(0)` in that rule, see docs/24 |
+| a rule fires (Alerting shows it) but no Telegram message; Grafana log says 400 "Unsupported start tag" | a `<` or `&` in the alert text (Telegram HTML). The generator refuses them now |
| messages every evening for a switched-off node | exclude it from "Host down" and gate its guests on its `up`, see docs/24 |
---
diff --git a/scripts/grafana/gen_alerts.py b/scripts/grafana/gen_alerts.py
index 4826e3b..6372fda 100644
--- a/scripts/grafana/gen_alerts.py
+++ b/scripts/grafana/gen_alerts.py
@@ -26,7 +26,7 @@ def rule(uid, title, expr, summary, desc, sev, for_="5m", ds=PROM, nodata="OK",
"conditions": [{"evaluator": {"type": "gt", "params": [0]}}]})}]}
CRIT = [
- # pve2 + pve3 are switched off on purpose to save power -> no "down" alert for them.
+ # pve2 + pve3 are switched off on purpose to save power -> only a soft ๐ "is off" message (see WARN).
rule("host-down", "Host down", f'max by (node) (up{{{HOSTS}, node!~"pve2|pve3"}}) < bool 1',
"{{ .Labels.node }} is DOWN", "Prometheus can't reach {{ .Labels.node }} for 2 minutes.", "critical", "2m"),
rule("guest-stopped", "Guest with autostart stopped",
@@ -47,12 +47,15 @@ def rule(uid, title, expr, summary, desc, sev, for_="5m", ds=PROM, nodata="OK",
"Internet is DOWN (FRITZ!Box)", "The DSL/WAN link is down. You get this message once it's back.", "critical", "3m"),
]
WARN = [
+ # pve2 + pve3: switched off on purpose to save power, but the user still wants to know (no ๐ด, not at night).
+ rule("host-off", "Power-saving node off", 'max by (node) (up{job="proxmox-host", node=~"pve2|pve3"}) < bool 1',
+ "{{ .Labels.node }} is off", "Fine if you switched it off yourself. You get an OK message when it's back.", "warning", "2m"),
rule("disk-80", "Disk over 80%", f'max by (node, mountpoint) (1 - node_filesystem_avail_bytes{{{HOSTS},{FS}}} / node_filesystem_size_bytes{{{HOSTS},{FS}}}) > bool 0.8',
"{{ .Labels.node }} {{ .Labels.mountpoint }} is over 80% full", "Time to clean up.", "warning", "30m"),
rule("storage-80", "Proxmox storage over 80%", 'max by (id) (pve_disk_usage_bytes{id=~"storage/.*"} / pve_disk_size_bytes{id=~"storage/.*"}) > bool 0.8',
"Storage {{ .Labels.id }} is over 80% full", "Time to clean up.", "warning", "30m"),
rule("disk-full-7d", "Disk full within 7 days", f'max by (node, mountpoint) (predict_linear(node_filesystem_avail_bytes{{{HOSTS},{FS},node!=""}}[6h], 7*86400) < bool 0)',
- "{{ .Labels.node }} {{ .Labels.mountpoint }} will be full in < 7 days", "Based on the last 6 hours of growth.", "warning", "2h"),
+ "{{ .Labels.node }} {{ .Labels.mountpoint }} will be full within 7 days", "Based on the last 6 hours of growth.", "warning", "2h"),
rule("ram-90", "RAM over 90%", f'max by (node) (1 - node_memory_MemAvailable_bytes{{{HOSTS}}} / node_memory_MemTotal_bytes{{{HOSTS}}}) > bool 0.9',
"{{ .Labels.node }} RAM is over 90%", "For 15 minutes. Something uses too much memory.", "warning", "15m"),
rule("crowdsec", "CrowdSec detected an attack", '(sum by (name) (increase(cs_bucket_overflowed_total[10m])) or vector(0)) > bool 0',
@@ -86,6 +89,11 @@ def rule(uid, title, expr, summary, desc, sev, for_="5m", ds=PROM, nodata="OK",
"It was running and is not anymore. If you stopped it yourself, ignore this.", "game", "1m"),
]
+# Telegram uses parse_mode HTML: a "<" or "&" in a text makes Telegram reject the whole message (400 Bad Request).
+for r in CRIT + WARN + GAMES:
+ for t in r["annotations"].values():
+ assert "<" not in t and "&" not in t, f'{r["uid"]}: no "<" or "&" in alert texts (Telegram HTML)'
+
doc = {"apiVersion": 1, "groups": [
{"orgId": 1, "name": "critical", "folder": "Homelab", "interval": "1m", "rules": CRIT},
{"orgId": 1, "name": "warning", "folder": "Homelab", "interval": "1m", "rules": WARN},
From 4198d8d89e4c793f45a5841b56489b956ebe632e Mon Sep 17 00:00:00 2001
From: TheMindDev <236810990+theMindDeveloper@users.noreply.github.com>
Date: Fri, 9 Oct 2026 09:36:46 +0000
Subject: [PATCH 2/2] README, runbook 23: 20 alert rules
---
README.md | 4 ++--
runbooks/23-alerts-to-telegram.md | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index fdfc1a4..d9eaf35 100644
--- a/README.md
+++ b/README.md
@@ -348,7 +348,7 @@ flowchart LR
B["Proxmox API ยท FRITZ!Box
game panels ยท AdGuard"] -- "exporters" --> P
C["firewall log ยท SSH ยท
containers ยท website"] -- "Alloy + GeoIP" --> L[("Loki")]
L --> CS["CrowdSec
watch only"] --> P
- P --> G["Grafana
4 dashboards ยท 19 alert rules"]
+ P --> G["Grafana
4 dashboards ยท 20 alert rules"]
L --> G
G -- "alerts" --> T["Telegram"]
```
@@ -362,7 +362,7 @@ flowchart LR
| **Logs** | Loki + Alloy: SSH, every container, the OPNsense firewall log and the website (with the real visitor IP behind the tunnel), each with country and city |
| **Attacks** | CrowdSec reads those logs and recognises brute force, scans and web exploits, **watch only**: nothing is blocked |
| **Dashboards** | four, generated by a Python script: Overview, Hosts (a switch per machine), Games, Security (dark world map) |
-| **Alerts** | 19 rules to my own Telegram bot: ๐ด any time, ๐ not at night, ๐ฎ when a game server stops. Switched-off nodes are not an incident |
+| **Alerts** | 20 rules to my own Telegram bot: ๐ด any time, ๐ not at night, ๐ฎ when a game server stops. Switched-off nodes are not an incident, just a soft ๐ "is off" |
Prometheus **pulls**: it reaches out to each target on an interval, so adding a
host means editing `prometheus.yml` and installing an exporter, and never
diff --git a/runbooks/23-alerts-to-telegram.md b/runbooks/23-alerts-to-telegram.md
index 56e1543..f9d7acf 100644
--- a/runbooks/23-alerts-to-telegram.md
+++ b/runbooks/23-alerts-to-telegram.md
@@ -71,7 +71,7 @@ In `/opt/monitoring/grafana/provisioning/alerting/`
| `contact-points.yml` | two Telegram receivers on the same bot: `telegram` (with "OK again" messages) and `telegram-games` (without) | rarely |
| `policies.yml` | critical and ๐ฎ โ any time; warning โ muted 23:00-08:00 Europe/Berlin; group per alert and node; repeat every 4 h | quiet hours, timezone |
| `templates.yml` | the message: emoji, one bold line, one explanation, a link | to taste |
-| `rules.yml` | the 19 rules. **Generated**, don't edit by hand | via `gen_alerts.py` |
+| `rules.yml` | the 20 rules. **Generated**, don't edit by hand | via `gen_alerts.py` |
### Adapt the rules to your lab