monitoring: alert on unknown servers in the Hetzner project
Some checks failed
deploy / ansible (push) Failing after 41s
Some checks failed
deploy / ansible (push) Failing after 41s
The VPC ping sweep misses a server that drops ICMP or is not attached to the private network. Prometheus now lists the project's servers from the Hetzner API with a read-only token and marks each one known or not against monitoring_hcloud_servers. Nothing is scraped from the servers: every discovered target is Prometheus itself with all samples dropped, which leaves one `up` series per server. A second alert fires when the list stops updating, so a revoked token does not silently disable the check. Assisted-by: Claude:fable-5-2
This commit is contained in:
parent
56dd0255dc
commit
ebd4f110f4
2 changed files with 381 additions and 190 deletions
|
|
@ -255,6 +255,38 @@ groups:
|
|||
for: 2m
|
||||
labels: { severity: critical }
|
||||
annotations: { summary: "{{ $labels.ip }} answers on the VPC (seen from {{ $labels.host }}) and is not in security_vpc_hosts" }
|
||||
- uid: sec-hcloud-server-unknown
|
||||
title: "Unknown server in the Hetzner project"
|
||||
condition: C
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: { from: 900, to: 0 }
|
||||
datasourceUid: prometheus
|
||||
model: { refId: A, expr: "up{job=\"hcloud\",known=\"false\"}", instant: true, intervalMs: 30000, maxDataPoints: 43200 }
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model: { refId: C, type: threshold, expression: A, conditions: [ { evaluator: { type: gt, params: [0] } } ] }
|
||||
noDataState: OK
|
||||
execErrState: Error
|
||||
for: 2m
|
||||
labels: { severity: critical }
|
||||
annotations: { summary: "Server {{ $labels.server }} ({{ $labels.type }}, {{ $labels.public_ip }}, private {{ $labels.private_ip }}) exists in the Hetzner project and is not in monitoring_hcloud_servers" }
|
||||
- uid: sec-hcloud-inventory-stale
|
||||
title: "Hetzner server list not updating"
|
||||
condition: C
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: { from: 900, to: 0 }
|
||||
datasourceUid: prometheus
|
||||
model: { refId: A, expr: "absent(up{job=\"hcloud\"}) or increase(prometheus_sd_refresh_failures_total{mechanism=\"hetzner\"}[30m]) > 3", instant: true, intervalMs: 30000, maxDataPoints: 43200 }
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model: { refId: C, type: threshold, expression: A, conditions: [ { evaluator: { type: gt, params: [0] } } ] }
|
||||
noDataState: OK
|
||||
execErrState: Error
|
||||
for: 10m
|
||||
labels: { severity: critical }
|
||||
annotations: { summary: "Prometheus cannot list the servers of the Hetzner project (token revoked or API unreachable): new servers go unnoticed" }
|
||||
- uid: sec-user-unknown
|
||||
title: "Unknown login account"
|
||||
condition: C
|
||||
|
|
|
|||
|
|
@ -54,6 +54,40 @@ scrape_configs:
|
|||
- targets: ["localhost:9090", "loki:3100", "grafana:3000", "blackbox:9115"]
|
||||
labels: { host: asxpio-ops }
|
||||
|
||||
# Servers in the Hetzner project, from the API (read-only token). Nothing
|
||||
# is scraped from them: every target is Prometheus itself with all
|
||||
# samples dropped, which leaves one `up` series per server.
|
||||
- job_name: hcloud
|
||||
scrape_interval: 60s
|
||||
hetzner_sd_configs:
|
||||
- role: hcloud
|
||||
authorization:
|
||||
credentials: "{{ monitoring_hcloud_token }}"
|
||||
relabel_configs:
|
||||
- source_labels: [__meta_hetzner_server_name]
|
||||
target_label: server
|
||||
- source_labels: [__meta_hetzner_server_name]
|
||||
target_label: instance
|
||||
- source_labels: [__meta_hetzner_public_ipv4]
|
||||
target_label: public_ip
|
||||
- regex: __meta_hetzner_hcloud_private_ipv4_.+
|
||||
action: labelmap
|
||||
replacement: private_ip
|
||||
- source_labels: [__meta_hetzner_hcloud_server_type]
|
||||
target_label: type
|
||||
- source_labels: [__meta_hetzner_server_status]
|
||||
target_label: status
|
||||
- target_label: known
|
||||
replacement: "false"
|
||||
- source_labels: [__meta_hetzner_server_name]
|
||||
regex: '{{ monitoring_hcloud_servers | map("regex_escape") | join("|") }}'
|
||||
target_label: known
|
||||
replacement: "true"
|
||||
- target_label: __address__
|
||||
replacement: localhost:9090
|
||||
metric_relabel_configs:
|
||||
- action: drop
|
||||
|
||||
{% for module in monitoring_probes | map(attribute='module') | unique %}
|
||||
- job_name: probe_{{ module }}
|
||||
metrics_path: /probe
|
||||
|
|
|
|||
Loading…
Reference in a new issue