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
2020-01-31 22:19:16 +01:00
src use mdns 1.1 2020-01-31 22:19:16 +01:00
.dockerignore add Dockerfile 2020-01-25 15:29:43 +01:00
.gitignore remove my config 2020-01-25 17:45:52 +01:00
Cargo.lock use mdns 1.1 2020-01-31 22:19:16 +01:00
Cargo.toml use mdns 1.1 2020-01-31 22:19:16 +01:00
Dockerfile add Dockerfile 2020-01-25 15:29:43 +01:00
README.md more readme 2020-01-25 17:52:16 +01: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.