Compare commits

...

15 Commits

Author SHA1 Message Date
54e56fade3 comment by lauren ramsey 2024-10-19 14:12:35 -05:00
17a35975b4 add .venv to .gitignore and .idea? 2024-10-18 20:19:16 -05:00
36a2bd8a9a add .venv to .gitignore 2024-10-18 20:17:22 -05:00
f2c1b5d33b add .venv to .gitignore 2024-10-18 20:16:54 -05:00
96bdfd93cd Add README.md 2024-10-18 01:51:01 -05:00
fde5d705cc chat gpt is retarded sometimes 2024-10-13 20:15:27 -05:00
595bea6539 import sys 2024-10-13 19:23:16 -05:00
ffeba267ec small edit 2024-10-13 18:49:01 -05:00
02a9624e31 write usb_acpi 2024-10-13 18:42:39 -05:00
e9c9555ba1 add usb acpi 2024-10-13 18:39:41 -05:00
3269abe626 add ssh client close 2024-10-12 03:24:28 -05:00
accb805db6 batt values tweaked based on testing 2024-10-12 03:10:09 -05:00
b691efb86b change battery values based on testing 2024-10-12 02:47:49 -05:00
e108e7fbcc add delay before nas shutdown 2024-10-12 02:39:58 -05:00
a8d95c9cd9 fix reqs 2024-10-12 02:35:39 -05:00
11 changed files with 68 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
# ignore please
.venv
__pycache__/
*.log*
config.py

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (power)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (power)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/power.iml" filepath="$PROJECT_DIR$/.idea/power.iml" />
</modules>
</component>
</project>

10
.idea/power.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

7
README.md Normal file
View File

@ -0,0 +1,7 @@
This script uses NUT and a few other libraries to communicate UPS status for servers.
If the power goes out, it will send an email and a discord message with status and battery charge.
If the power comes back, it will do the same.
Once battery reaches critical level, it will automate shutting servers down.
When the power comes back and the battery is charged, it will fire them up again.

View File

@ -123,6 +123,7 @@ def shutdown_nas():
stdin, stdout, stderr = client.exec_command('sudo shutdown')
for line in stdout:
print(line.strip())
client.close()
except Exception as e:
logger.error(e)
@ -148,7 +149,7 @@ def pwr_online(battery):
logger.info(message)
send_email(f"{ups_id}: Power On Line", message)
send_discord(message)
if ups_id == "Server" and battery > 90:
if ups_id == "Server" and battery > 75:
wake_up(battery)
def pwr_offline(battery):
@ -171,8 +172,8 @@ def batt_crit(battery):
if ups_id == "Server":
for node in servers:
shutdown_pve(node)
time.sleep(120)
shutdown_nas()
time.sleep(300)
# Main Loop
def main():
@ -191,8 +192,8 @@ def main():
else:
logger.info(f"UPS status changed to: {status}")
prev_status = status
elif status == "OB DISCHRG" and battery < 50:
if battery < 25:
elif status == "OB DISCHRG" and battery < 70:
if battery < 65:
batt_crit(battery)
if ups_id == "Server":
for node in servers:

View File

@ -3,5 +3,10 @@ ping3
config
discord
paramiko
requests
proxmoxer
wakeonlan
wakeonlan
# hi there :) ljr

9
usb_acpi.py Normal file
View File

@ -0,0 +1,9 @@
import sys
import time
with open('/dev/hidg0', 'wb') as f:
f.write(b'\x01')
time.sleep(0.3)
f.write(b'\x00')
sys.exit()