Fix Build e domenticanza nel routermon

This commit is contained in:
2025-06-01 10:26:11 +02:00
parent 8aad6a6936
commit 0d34d7cb0d
3 changed files with 23 additions and 14 deletions

View File

@@ -2,6 +2,8 @@
GIT_HASH=$(git rev-parse --short HEAD)
docker-compose down
echo "Building UPSmon"
cp ../pyutils/utils.py ../upsmon/
docker build --build-arg BUILD_VER=${GIT_HASH} -f ../upsmon/upsmon.Dockerfile -t upsmon:influx3 ../upsmon

View File

@@ -15,18 +15,25 @@ LOGGER: logging.Logger
##################
###### MAIN ######
##################
def main():
def main() -> int:
INTERVAL = int(env['INTERVAL'])
# Init InfluxDB-v3 Client
write_client = InfluxDBClient3(host=env['INFLUXDB_URL'],
token=env['INFLUXDB_TOKEN'],
database=env['INFLUXDB_DATABASE'])
# Init routerOS API
connection = routeros_api.RouterOsApiPool(env['MIKROTIK_IP'],
username=env['MIKROTIK_USER'],
password=env['MIKROTIK_PASSWORD'],
plaintext_login=True)
api = connection.get_api()
try:
# Init InfluxDB-v3 Client
write_client = InfluxDBClient3(host=env['INFLUXDB_URL'],
token=env['INFLUXDB_TOKEN'],
database=env['INFLUXDB_DATABASE'])
# Init routerOS API
connection = routeros_api.RouterOsApiPool(env['MIKROTIK_IP'],
username=env['MIKROTIK_USER'],
password=env['MIKROTIK_PASSWORD'],
plaintext_login=True)
api = connection.get_api()
except Exception as e:
LOGGER.error(e)
return 1
finally:
LOGGER.info(f"InfluxDB Connected: [{env['INFLUXDB_URL']}/{env['INFLUXDB_DATABASE']}]")
LOGGER.info(f"Mikrotik Connected: [{env['MIKROTIK_IP']}]")
##############################
########## MAIN LOOP #########

View File

@@ -43,7 +43,7 @@ def bruteforceCommands(port: serial.Serial):
##################
###### MAIN ######
##################
def main():
def main() -> int:
INTERVAL = int(env['INTERVAL'])
UPS_COMMAND = "Q1"
try:
@@ -55,7 +55,7 @@ def main():
port = serial.Serial(port=env['PORT'], baudrate=int(env['BAUD']), bytesize=8, parity='N', stopbits=1)
except Exception as e:
LOGGER.error(e)
return 0
return 1
finally:
LOGGER.info(f"InfluxDB Connected: [{env['INFLUXDB_URL']}/{env['INFLUXDB_DATABASE']}]")
LOGGER.info(f"Serial Port Open: [{env['PORT']}]")
@@ -82,7 +82,7 @@ def main():
}
LOGGER.debug(f"UPS Status: \n{json.dumps(values, indent=2)}")
if values['onBatt']:
LOGGER.info(f"OnBattery\n{json.dumps(values,indent=2)}")
LOGGER.info(f"OnBattery: \n{json.dumps(values,indent=2)}")
write_client.write(record=dict2Point('ups', values))
time.sleep(INTERVAL)
except Exception as e: