Created
January 22, 2017 11:13
-
-
Save cpswan/25c9ff9081a8edc41742a54b717b41da to your computer and use it in GitHub Desktop.
Example Network UPS Tool (NUT) configs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
import smtplib | |
import mimetypes | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email.MIMEAudio import MIMEAudio | |
from email.MIMEImage import MIMEImage | |
from email.Encoders import encode_base64 | |
def sendMail(subject, text): | |
gmailUser = '[email protected]' | |
gmailPassword = 'pa55Word' | |
recipient = '[email protected]' | |
msg = MIMEMultipart() | |
msg['From'] = gmailUser | |
msg['To'] = recipient | |
msg['Subject'] = subject | |
msg.attach(MIMEText(text)) | |
mailServer = smtplib.SMTP('smtp.gmail.com', 587) | |
mailServer.ehlo() | |
mailServer.starttls() | |
mailServer.ehlo() | |
mailServer.login(gmailUser, gmailPassword) | |
mailServer.sendmail(gmailUser, recipient, msg.as_string()) | |
mailServer.close() | |
print'Sent email to %s' % recipient | |
sendMail(sys.argv[1], sys.argv[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MONITOR PowerWalker2200@localhost "Garage UPS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MODE=netserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PowerWalker2200] | |
driver = blazer_usb | |
port = auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LISTEN 0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ups_admin] | |
password = pa55Word | |
upsmon master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MONITOR PowerWalker2200@_server_IP_ 1 ups_admin pa55Word master | |
MINSUPPLIES 1 | |
SHUTDOWNCMD "/sbin/shutdown -h +0" | |
NOTIFYCMD /sbin/upssched | |
POLLFREQ 5 | |
POLLFREQALERT 5 | |
HOSTSYNC 15 | |
DEADTIME 15 | |
POWERDOWNFLAG /etc/killpower | |
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC | |
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC | |
RBWARNTIME 43200 | |
NOCOMMWARNTIME 300 | |
FINALDELAY 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case $1 in | |
ups-on-batt) | |
gmail.py "Garage has lost power" "Running on battery" | |
;; | |
onbattwarn) | |
gmail.py "Garage power still down after 30s" "Running on battery" | |
;; | |
ups-back-on-power) | |
gmail.py "Garage power restored" "Running on mains again" | |
;; | |
*) | |
logger -t upssched-cmd "Unrecognized command: $1" | |
;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMDSCRIPT /bin/upssched-cmd | |
PIPEFN /var/run/nut/upssched/upssched.pipe | |
LOCKFN /var/run/nut/upssched/upssched.lock | |
AT ONBATT * EXECUTE ups-on-batt | |
AT ONBATT * START-TIMER onbattwarn 30 | |
AT ONLINE * CANCEL-TIMER onbattwarn | |
AT ONLINE * EXECUTE ups-back-on-power |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use in anger:
Replace instances of
pa55Word
with a real password of your choosing.Put the actual IP of your server running NUT into
_server_IP_
in upsmon.confSubstitute these lines in gmail.py with real values for the account you're using to send and the address you want to get alerts from.
Also note that you'll have to jump through some hoops with the sending gmail account to allow it to be used this way (as gmail has tightened up security defaults).