Skip to content

Commit

Permalink
Update nut-influxdbv2-exporter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dbsqp authored Apr 9, 2021
1 parent 6a74342 commit e45fee8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions nut-influxdbv2-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
nut_debug="true"
else:
debug = False
nut_debug="false"
nut_debug=""


# report debug status
Expand All @@ -51,6 +51,13 @@
print ( " debug: FALSE" )


# get IP address
hostname = socket.gethostname()
host_ip = socket.gethostbyname(hostname)
if debug:
print ( " docker: "+host_ip )


# setup InfluxDB
influxdb2_url="http://" + influxdb2_host + ":" + str(influxdb2_port)
if debug:
Expand Down Expand Up @@ -112,23 +119,23 @@ def construct_object(data, remove_keys, host):

for ipaddress in nut_ip_list:
# setup NUT
position = nut_ip_list.index(ipaddress)
host=nut_host_list[position]
if debug:
print(" IP: ", ipaddress)
print(" IP: ", ipaddress)
print("host: ", host)

ups_client = PyNUTClient(host=ipaddress, port=nut_port, login=nut_username, password=nut_password, debug=nut_debug)
if ups_client and debug:
print("NUT: "+ipaddress+" OK")
print("NUT: OK")


position = nut_ip_list.index(ipaddress)
host=nut_host_list[position]


# push to Influx
while True:
try:
ups_data = ups_client.list_vars(nut_upsname)
if debug:
print ("UPS: "+host" : "+nut_upsname)
print ("UPS: "+nut_upsname"@"+host)
print (json.dumps(ups_data,indent=4))
except:
tb = traceback.format_exc()
Expand Down

0 comments on commit e45fee8

Please sign in to comment.