Created
July 28, 2019 01:32
-
-
Save chaeplin/41ce5854f7ea64f485f4b8111e0eb891 to your computer and use it in GitHub Desktop.
apcups
This file contains hidden or 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
UPSNAME UNIFIUPS | |
UPSCABLE usb | |
UPSTYPE usb | |
DEVICE | |
LOCKFILE /tmp | |
SCRIPTDIR /etc/apcupsd | |
PWRFAILDIR /etc/apcupsd | |
NOLOGINDIR /etc | |
ONBATTERYDELAY 6 | |
BATTERYLEVEL 5 | |
MINUTES 3 | |
TIMEOUT 0 | |
ANNOY 300 | |
ANNOYDELAY 60 | |
NOLOGON disable | |
KILLDELAY 0 | |
NETSERVER on | |
NISIP 127.0.0.1 | |
NISPORT 3551 | |
EVENTSFILE /var/log/apcupsd.events | |
EVENTSFILEMAX 10 | |
UPSCLASS standalone | |
UPSMODE disable | |
STATTIME 0 | |
STATFILE /var/log/apcupsd.status | |
LOGSTATS off | |
DATATIME 0 |
This file contains hidden or 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/env python3 | |
# -*- coding: utf-8 -*- | |
import io, os, sys | |
import time | |
import json | |
import requests | |
from apcaccess import status as apc | |
def now(): | |
return int(time.time()) | |
webhook_url = 'https://hooks.slack.com/services/xxx/xxx/xxxx' | |
apctestresult = apc.parse(apc.get(host="127.0.0.1"), strip_units=True) | |
slack_msg = 'HOSTNAME : ' + apctestresult['HOSTNAME'] + '\r\n' + \ | |
'UPSNAME : ' + apctestresult['UPSNAME'] + '\r\n' + \ | |
'STATUS : ' + apctestresult['STATUS'] + '\r\n' + \ | |
'LINEV : ' + apctestresult['LINEV'] + ' Volts' + '\r\n' + \ | |
'LOADPCT : ' + apctestresult['LOADPCT'] + ' Percent' + '\r\n' + \ | |
'BCHARGE : ' + apctestresult['BCHARGE'] + ' Percent' + '\r\n' + \ | |
'TIMELEFT : ' + apctestresult['TIMELEFT'] + ' Minutes' + '\r\n' + \ | |
'BATTV : ' + apctestresult['BATTV'] + ' Volts' + '\r\n' + \ | |
'TONBATT : ' + apctestresult['TONBATT'] + ' Seconds' + '\r\n' + \ | |
'CUMONBATT : ' + apctestresult['CUMONBATT'] + ' Seconds' | |
slack_up_data = { | |
'attachments': [ | |
{ | |
'pretext': 'ups power event report', | |
'color': 'good', | |
'fields':[ | |
{ | |
'title': 'OK: UPS Power Recovered', | |
'value': slack_msg, | |
'short': False | |
}], | |
'ts': now() | |
} | |
] | |
} | |
try: | |
print(slack_up_data) | |
response = requests.post(webhook_url, data=json.dumps(slack_up_data), headers={'Content-Type': 'application/json'}) | |
if response.status_code != 200: | |
print('slack post failed') | |
except: | |
pass |
This file contains hidden or 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/env python3 | |
# -*- coding: utf-8 -*- | |
import io, os, sys | |
import time | |
import json | |
import requests | |
from apcaccess import status as apc | |
def now(): | |
return int(time.time()) | |
webhook_url = 'https://hooks.slack.com/services/xxx/xxx/xxxx' | |
apctestresult = apc.parse(apc.get(host="127.0.0.1"), strip_units=True) | |
slack_msg = 'HOSTNAME : ' + apctestresult['HOSTNAME'] + '\r\n' + \ | |
'UPSNAME : ' + apctestresult['UPSNAME'] + '\r\n' + \ | |
'STATUS : ' + apctestresult['STATUS'] + '\r\n' + \ | |
'LINEV : ' + apctestresult['LINEV'] + ' Volts' + '\r\n' + \ | |
'LOADPCT : ' + apctestresult['LOADPCT'] + ' Percent' + '\r\n' + \ | |
'BCHARGE : ' + apctestresult['BCHARGE'] + ' Percent' + '\r\n' + \ | |
'TIMELEFT : ' + apctestresult['TIMELEFT'] + ' Minutes' + '\r\n' + \ | |
'BATTV : ' + apctestresult['BATTV'] + ' Volts' + '\r\n' + \ | |
'TONBATT : ' + apctestresult['TONBATT'] + ' Seconds' + '\r\n' + \ | |
'CUMONBATT : ' + apctestresult['CUMONBATT'] + ' Seconds' | |
slack_up_data = { | |
'attachments': [ | |
{ | |
'pretext': 'ups power event report', | |
'color': 'danger', | |
'fields':[ | |
{ | |
'title': 'ALERT: UPS Power Failure', | |
'value': slack_msg, | |
'short': False | |
}], | |
'ts': now() | |
} | |
] | |
} | |
try: | |
print(slack_up_data) | |
response = requests.post(webhook_url, data=json.dumps(slack_up_data), headers={'Content-Type': 'application/json'}) | |
if response.status_code != 200: | |
print('slack post failed') | |
except: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.anites.com/2013/09/monitoring-ups.html?fbclid=IwAR1hb8OG8kRcbZY4-FbSXQ8IE0R3e1gUsKzVl9u6DNwhrwHrHeVtvK9XCnk