Эх сурвалжийг харах

update ups role to handle primary and secondary roles

Blaine Story 2 жил өмнө
parent
commit
683043308c

+ 21 - 0
roles/ups/defaults/main.yml

@@ -0,0 +1,21 @@
+---
+# if UPS is not directly connected, which server to poll for UPS status
+ups_primary: '' 
+
+# interval at which apcupsd will poll the UPS for status
+ups_polltime_seconds: 60
+
+# seconds from power failure is detected until we react to it with an onbattery event
+ups_on_battery_delay_seconds: 6
+
+# will trigger on first of the following values that is true
+ups_shutdown_on_battery_percent: 5
+ups_shutdown_on_remaining_minutes: 5
+ups_shutdown_timeout_seconds: 0 # disabled by default, best to leave disabled unless testing
+
+# seconds before shutdown to send alert to users logged in
+ups_preshutdown_annoy_seconds: 300
+
+# initial delay after power failure before warning users to get off the system
+ups_annoy_delay_seconds: 60
+

+ 0 - 0
roles/ups-primary/handlers/main.yml → roles/ups/handlers/main.yml


+ 0 - 0
roles/ups-primary/tasks/main.yml → roles/ups/tasks/main.yml


+ 0 - 0
roles/ups-primary/templates/apccontrol.j2 → roles/ups/templates/apccontrol.j2


+ 12 - 7
roles/ups-primary/templates/apcupsd.conf.j2 → roles/ups/templates/apcupsd.conf.j2

@@ -89,8 +89,13 @@ UPSCABLE usb
 #                            that apcupsd binds to that particular unit
 #                            (helpful if you have more than one USB UPS).
 #
+{% if ups_primary == '' %}
 UPSTYPE usb
 DEVICE 
+{% else %}
+UPSTYPE net
+DEVICE {{ ups_primary }}:3551
+{% endif %}
 
 # POLLTIME <int>
 #   Interval (in seconds) at which apcupsd polls the UPS for status. This
@@ -99,7 +104,7 @@ DEVICE
 #   will improve apcupsd's responsiveness to certain events at the cost of
 #   higher CPU utilization. The default of 60 is appropriate for most
 #   situations.
-#POLLTIME 60
+POLLTIME {{ ups_polltime_seconds }}
 
 # LOCKFILE <path to lockfile>
 #   Path for device lock file. This is the directory into which the lock file
@@ -138,7 +143,7 @@ NOLOGINDIR /etc
 #   ONBATTERYDELAY time.  If you don't want to be annoyed by short
 #   powerfailures, make sure that apccontrol powerout does nothing
 #   i.e. comment out the wall.
-ONBATTERYDELAY 6
+ONBATTERYDELAY {{ ups_on_battery_delay_seconds }}
 
 # 
 # Note: BATTERYLEVEL, MINUTES, and TIMEOUT work in conjunction, so
@@ -148,12 +153,12 @@ ONBATTERYDELAY 6
 # If during a power failure, the remaining battery percentage
 # (as reported by the UPS) is below or equal to BATTERYLEVEL, 
 # apcupsd will initiate a system shutdown.
-BATTERYLEVEL 5
+BATTERYLEVEL {{ ups_shutdown_on_battery_percent }}
 
 # If during a power failure, the remaining runtime in minutes 
 # (as calculated internally by the UPS) is below or equal to MINUTES,
 # apcupsd, will initiate a system shutdown.
-MINUTES 5
+MINUTES {{ ups_shutdown_on_remaining_minutes }}
 
 # If during a power failure, the UPS has run on batteries for TIMEOUT
 # many seconds or longer, apcupsd will initiate a system shutdown.
@@ -167,15 +172,15 @@ MINUTES 5
 #    if you pull the power plug.   
 #  If you have an older dumb UPS, you will want to set this to less than
 #    the time you know you can run on batteries.
-TIMEOUT 0
+TIMEOUT {{ ups_shutdown_timeout_seconds }}
 
 #  Time in seconds between annoying users to signoff prior to
 #  system shutdown. 0 disables.
-ANNOY 300
+ANNOY {{ ups_preshutdown_annoy_seconds }}
 
 # Initial delay after power failure before warning users to get
 # off the system.
-ANNOYDELAY 60
+ANNOYDELAY {{ ups_annoy_delay_seconds }}
 
 # The condition which determines when users are prevented from
 # logging in during a power failure.

+ 1 - 1
roles/ups-primary/templates/changeme.j2 → roles/ups/templates/changeme.j2

@@ -12,7 +12,7 @@ message=$(/sbin/apcaccess status)
 curl \
   -H "Title: UPS battery needs changing NOW." \
   -H "Priority: urgent" \
-  -H "Tags: warning" \
+  -H "Tags: skull" \
   -d "$message" \
   {{ ntfy_url }}/{{ ntfy_topic }}
 

+ 1 - 1
roles/ups-primary/templates/commfailure.j2 → roles/ups/templates/commfailure.j2

@@ -10,7 +10,7 @@
 message=$(/sbin/apcaccess status)
 
 curl \
-  -H "Title: Communications with UPS lost" \
+  -H "Title: [$(hostname)] - Communications with UPS lost" \
   -H "Priority: urgent" \
   -H "Tags: warning" \
   -d "$message" \

+ 1 - 1
roles/ups-primary/templates/commok.j2 → roles/ups/templates/commok.j2

@@ -10,7 +10,7 @@
 message=$(/sbin/apcaccess status)
 
 curl \
-  -H "Title: Communications with UPS restored" \
+  -H "Title: [$(hostname)] - Communications with UPS restored" \
   -H "Priority: default" \
   -H "Tags: +1" \
   -d "$message" \

+ 1 - 1
roles/ups-primary/templates/offbattery.j2 → roles/ups/templates/offbattery.j2

@@ -10,7 +10,7 @@
 message=$(/sbin/apcaccess status)
 
 curl \
-  -H "Title: UPS Power has returned" \
+  -H "Title: [$(hostname)] - UPS Power has been restored" \
   -H "Priority: default" \
   -H "Tags: +1" \
   -d "$message" \

+ 1 - 1
roles/ups-primary/templates/onbattery.j2 → roles/ups/templates/onbattery.j2

@@ -10,7 +10,7 @@
 message=$(/sbin/apcaccess status)
 
 curl \
-  -H "Title: UPS Power Failure !!!" \
+  -H "Title: [$(hostname)] - Running off UPS Battery !!!" \
   -H "Priority: urgent" \
   -H "Tags: warning" \
   -d "$message" \