From 36fd137897a12e60dce2470b762df16913f5d19e Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Fri, 19 Jan 2024 17:57:20 -0600 Subject: [PATCH] nut: Infer role from server name, set commands Since the "primary" `upsmon` is always (for our purposes) running on the same host as `upsd`, there's no reason to specify both values. All systems need a shutdown command; one is not set by default. The primary system is the only one that should send notifications. --- env/prod/nut.cue | 12 ++++++++++-- host/nut0.pyrocufflink.blue.cue | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/env/prod/nut.cue b/env/prod/nut.cue index 96f6076..7338b4e 100644 --- a/env/prod/nut.cue +++ b/env/prod/nut.cue @@ -73,7 +73,6 @@ nut: schema.#Nut & { #nut_monitor: { #server: string | *ups_server #username: string - #role: "primary" | *"secondary" monitor: [ for k, v in nut.ups { @@ -82,10 +81,19 @@ nut: schema.#Nut & { powervalue: 1 username: #username password: nut.users[#username].password - role: #role + if #server == "localhost" { + role: "primary" + } + if #server != "localhost" { + role: "secondary" + } } }, ] + shutdowncmd: "systemctl poweroff" + if #server == "localhost" { + notifycmd: "/usr/local/libexec/nut-notify" + } minsupplies: 1 } diff --git a/host/nut0.pyrocufflink.blue.cue b/host/nut0.pyrocufflink.blue.cue index abeeb04..9460779 100644 --- a/host/nut0.pyrocufflink.blue.cue +++ b/host/nut0.pyrocufflink.blue.cue @@ -9,7 +9,6 @@ nut: prod.nut nut: monitor: prod.#nut_monitor & { #server: "localhost" #username: "upsmon" - #role: "primary" } collectd: prod.collectd