diff --git a/collector/Dockerfile b/collector/Dockerfile index 67bda78a..33ece497 100644 --- a/collector/Dockerfile +++ b/collector/Dockerfile @@ -10,4 +10,6 @@ COPY ./collector/server.py /app EXPOSE 5000 -ENTRYPOINT [ "python", "server.py" ] +ENTRYPOINT [ "python", "server.py"] + +CMD [ "--config-file-path", "/tmp/config.json"] diff --git a/collector/server.py b/collector/server.py index 17d64126..506843a6 100644 --- a/collector/server.py +++ b/collector/server.py @@ -3,6 +3,7 @@ from threading import Thread import enum import logging +import json from fastapi import FastAPI, Response from fastapi.middleware.cors import CORSMiddleware @@ -115,7 +116,12 @@ async def metrics(): if __name__ == "__main__": parser = argparse.ArgumentParser("snmp coolness") - + parser.add_argument( + "--config-file-path", + required=True, + help="Path to config file that stores IPs", + ) + parser.add_argument( "--ips", help="List of IP addresses of snmp agent (default: 192.168.69.208,192.168.69.149)", @@ -140,10 +146,20 @@ async def metrics(): ) args = parser.parse_args() - ip_list = args.ips.split(',') + try: + with open(args.config_file_path, "r") as f: + config = json.load(f) + left_ip = config["PRINTING"]["LEFT"]["IP"] + right_ip = config["PRINTING"]["RIGHT"]["IP"] + ip_list=[left_ip, right_ip] + + logging.info(f"connected to left printer ip: {left_ip}") + logging.info(f"connected to right printer ip: {right_ip}") + thread = Thread(target = scrape_snmp, args=(ip_list,), daemon=True) + thread.start() + except Exception as e: + logging.error(f"error opening config file: {e}") - thread = Thread(target = scrape_snmp, args=(ip_list,), daemon=True) - thread.start() uvicorn.run( app, host=args.host, diff --git a/docker-compose.yml b/docker-compose.yml index ef33ca44..85fdf370 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,9 @@ services: build: context: . dockerfile: ./collector/Dockerfile + + volumes: + - ./config/config.json:/tmp/config.json # we attach the print container to an external docker # network called "poweredge". we do this so a prometheus # container can pull metrics from the server over HTTP