NUT_to_Influx/main.py
Sean Corrigan bde886da72 Beaut
2021-09-14 15:17:48 -04:00

35 lines
860 B
Python

## Requires NUT2 from PIP
from nut2 import PyNUTClient
import os
# try:
# hostList = os.environ["hosts"]
# hostList = hostList.replace(" ","").split(",")
# except:
# print("error with hosts entry, please make sure in format -> 10.x.x.1, 10.x.x.2")
# host
hostList = ['10.0.5.2', '10.0.5.181']
upslist = {}
## pull all the UPSes froom each host into a nice dict
for host in hostList:
upslist[host] = []
client = PyNUTClient(host, '3493')
for UPS in client.list_ups():
upslist[host].append(UPS)
print(upslist)
for host in upslist:
client = PyNUTClient(host, '3493')
for UPS in upslist[host]:
print()
print("{} Battery Percent: {}%".format(UPS, client.list_vars(UPS)['battery.charge']))
# client = PyNUTClient('10.0.5.181', '3493')
# # print(client.list_ups())
# print(client.list_vars("Net-UPS1"))