Trigger http requests a set delay after an edge in a prometheus query
  • Rust 65.3%
  • Nix 32.8%
  • Dockerfile 1.9%
Find a file
2025-06-02 22:33:05 +02:00
.forgejo/workflows workflow updates 2025-06-02 22:33:05 +02:00
src use secretfile 2024-03-02 21:22:42 +01:00
.dockerignore add Dockerfile 2020-01-25 15:29:43 +01:00
.envrc flake 2022-07-26 20:31:24 +02:00
.gitignore bumb dependencies 2022-07-26 19:54:10 +02:00
Cargo.lock use secretfile 2024-03-02 21:22:42 +01:00
Cargo.toml use secretfile 2024-03-02 21:22:42 +01:00
Dockerfile allow sending mqtt messages on action 2020-11-15 21:26:50 +01:00
flake.lock flake update 2025-06-02 22:32:48 +02:00
flake.nix flake update 2025-06-02 22:32:48 +02:00
module.nix nixos: load token from systemd credentials 2024-03-02 21:24:32 +01:00
overlay.nix updates 2024-02-12 20:54:36 +01:00
package.nix updates 2024-02-12 20:54:36 +01:00
README.md flake update 2025-06-02 22:32:48 +02:00

Prometheus edge trigger

Trigger http requests a set delay after an edge in a prometheus query.

Example

Given 2 wifi enabled switches that have their state logged into prometheus, automatically turn off switch2 5 minutes switch1 is turned off.

[prometheus]
url = "http://prometheus"

[[trigger]]
name = "Delay swtich"

[trigger.condition]
query = "switch_state{instance=\"$instance\"}"
from = 1
to = 0
params.instance = { type = "mdns", service = "_switch-http._tcp.local", host = "switch1" }

[trigger.action]
method = "PUT"
params.host = { type = "mdns", service = "_switch-http._tcp.local", host = "switch2" }
url = "http://$host/off"
delay = 300

Parameters

To remove the need to hard code ip addresses or host names, you can configure parameters to query for an ip address and use it in a query or url.

MDNS

params.host = { type = "mdns", service = "_switch-http._tcp.local", host = "switch2" }

Will attempt to lookup a host advertising itself under the _switch-http._tcp.local service with host name switch2 and return the ip address and port of the host.

Service

params.host = { type = "service", file = "services.json", key = "hostname", value = "switch2" }

Will look for a host in a json file in prometheus' file based service discovery format for an entry containing the label hostname with value switch2 and return the first target.