diff --git a/README.md b/README.md index ec3d9e7..2e439c1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a docker container that pulls data from a NUT server and pushed to InfluxDB. Based on work of mihai-cindea [https://github.com/mihai-cindea/nut-influxdb-exporter) ## Changes -Updated for InfluxDBv2. Changed outputted values. Poll multiple NUT servers. +Updated for InfluxDBv2. Changed outputted values. Poll multiple NUT servers. Poll internal batteries on MacOS using the NUT macosx-ups driver. ## Roadmap diff --git a/nut-influxdbv2-exporter.py b/nut-influxdbv2-exporter.py index 0dd4a1c..02a5738 100644 --- a/nut-influxdbv2-exporter.py +++ b/nut-influxdbv2-exporter.py @@ -22,7 +22,13 @@ # Other vars debug_str = os.getenv('DEBUG', 'false') -remove_keys = ['battery.type','device.serial','ups.realpower.nominal','ups.vendorid','ups.serial','ups.productid','ups.model','ups.mfr','driver.version.data','driver.version','device.type','device.mfr', 'driver.version.internal', 'driver.version.usb', 'ups.beeper.status', 'driver.name', 'battery.mfr.date','ups.firmware', 'ups.firmware.aux','ups.mfr.date', 'battery.date', 'battery.charge.low', 'battery.charge.warning', 'battery.runtime.low','driver.parameter.pollfreq','driver.parameter.pollinterval','driver.parameter.port','input.sensitivity','input.transfer.high','input.transfer.low','ups.delay.shutdown','ups.test.result','ups.timer.reboot','ups.timer.shutdown'] +remove_keys = ['battery.type','device.serial','ups.realpower.nominal','ups.vendorid','ups.serial','ups.productid', + 'ups.model','ups.mfr','driver.version.data','driver.version','device.type','device.mfr', + 'driver.version.internal', 'driver.version.usb', 'ups.beeper.status', 'driver.name', 'battery.mfr.date', + 'ups.firmware', 'ups.firmware.aux','ups.mfr.date', 'battery.date', 'battery.charge.low', + 'battery.charge.warning', 'battery.runtime.low','driver.parameter.pollfreq','driver.parameter.pollinterval', + 'driver.parameter.port','input.sensitivity','input.transfer.high','input.transfer.low','ups.delay.shutdown', + 'ups.test.result','ups.timer.reboot','ups.timer.shutdown','driver.parameter.synchronous'] # InfluxDBv2 variables influxdb2_host=os.getenv('INFLUXDB2_HOST', "localhost") @@ -93,9 +99,14 @@ def construct_object(data, remove_keys, host): for k, v in data.items(): if k == "ups.serial": - tags["hardware"]=':'.join(v[i:i+2] for i in range(0,12,2)) + if v: + tags["hardware"]=':'.join(v[i:i+2] for i in range(0,12,2)) elif k == "device.model": - tags["model"]=v.strip() + w = v.split("FW:", 2) + if v == "InternalBattery-0": + tags["model"]="InternalBattery" + else: + tags["model"]=w[0].strip() else: if k in remove_keys: continue