Compare commits
15 Commits
d0bb173518
...
main
Author | SHA1 | Date | |
---|---|---|---|
54e56fade3 | |||
17a35975b4 | |||
36a2bd8a9a | |||
f2c1b5d33b | |||
96bdfd93cd | |||
fde5d705cc | |||
595bea6539 | |||
ffeba267ec | |||
02a9624e31 | |||
e9c9555ba1 | |||
3269abe626 | |||
accb805db6 | |||
b691efb86b | |||
e108e7fbcc | |||
a8d95c9cd9 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
# ignore please
|
# ignore please
|
||||||
|
.venv
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.log*
|
*.log*
|
||||||
config.py
|
config.py
|
||||||
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal 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
7
.idea/misc.xml
generated
Normal 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
8
.idea/modules.xml
generated
Normal 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
10
.idea/power.iml
generated
Normal 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
6
.idea/vcs.xml
generated
Normal 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
7
README.md
Normal 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.
|
9
power.py
9
power.py
@ -123,6 +123,7 @@ def shutdown_nas():
|
|||||||
stdin, stdout, stderr = client.exec_command('sudo shutdown')
|
stdin, stdout, stderr = client.exec_command('sudo shutdown')
|
||||||
for line in stdout:
|
for line in stdout:
|
||||||
print(line.strip())
|
print(line.strip())
|
||||||
|
client.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
@ -148,7 +149,7 @@ def pwr_online(battery):
|
|||||||
logger.info(message)
|
logger.info(message)
|
||||||
send_email(f"{ups_id}: Power On Line", message)
|
send_email(f"{ups_id}: Power On Line", message)
|
||||||
send_discord(message)
|
send_discord(message)
|
||||||
if ups_id == "Server" and battery > 90:
|
if ups_id == "Server" and battery > 75:
|
||||||
wake_up(battery)
|
wake_up(battery)
|
||||||
|
|
||||||
def pwr_offline(battery):
|
def pwr_offline(battery):
|
||||||
@ -171,8 +172,8 @@ def batt_crit(battery):
|
|||||||
if ups_id == "Server":
|
if ups_id == "Server":
|
||||||
for node in servers:
|
for node in servers:
|
||||||
shutdown_pve(node)
|
shutdown_pve(node)
|
||||||
|
time.sleep(120)
|
||||||
shutdown_nas()
|
shutdown_nas()
|
||||||
time.sleep(300)
|
|
||||||
|
|
||||||
# Main Loop
|
# Main Loop
|
||||||
def main():
|
def main():
|
||||||
@ -191,8 +192,8 @@ def main():
|
|||||||
else:
|
else:
|
||||||
logger.info(f"UPS status changed to: {status}")
|
logger.info(f"UPS status changed to: {status}")
|
||||||
prev_status = status
|
prev_status = status
|
||||||
elif status == "OB DISCHRG" and battery < 50:
|
elif status == "OB DISCHRG" and battery < 70:
|
||||||
if battery < 25:
|
if battery < 65:
|
||||||
batt_crit(battery)
|
batt_crit(battery)
|
||||||
if ups_id == "Server":
|
if ups_id == "Server":
|
||||||
for node in servers:
|
for node in servers:
|
||||||
|
@ -3,5 +3,10 @@ ping3
|
|||||||
config
|
config
|
||||||
discord
|
discord
|
||||||
paramiko
|
paramiko
|
||||||
|
requests
|
||||||
proxmoxer
|
proxmoxer
|
||||||
wakeonlan
|
wakeonlan
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# hi there :) ljr
|
||||||
|
9
usb_acpi.py
Normal file
9
usb_acpi.py
Normal 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()
|
Reference in New Issue
Block a user