From 792f8c7c0469b2840370cc61662dc644c0b33674 Mon Sep 17 00:00:00 2001 From: Emerson Felipe Date: Wed, 21 Aug 2024 21:19:04 +0000 Subject: [PATCH] Correctly adding interface with IP address to Devices (Nodes) --- netbox_proxbox/backend/diode/diode.py | 59 ++++++++++++ .../backend/diode/docker-compose.yaml | 92 +++++++++++++++++++ .../backend/routes/netbox/generic.py | 91 ++++++++++++++---- .../routes/proxbox/clusters/__init__.py | 2 +- 4 files changed, 226 insertions(+), 18 deletions(-) create mode 100644 netbox_proxbox/backend/diode/diode.py create mode 100644 netbox_proxbox/backend/diode/docker-compose.yaml diff --git a/netbox_proxbox/backend/diode/diode.py b/netbox_proxbox/backend/diode/diode.py new file mode 100644 index 0000000..a32580a --- /dev/null +++ b/netbox_proxbox/backend/diode/diode.py @@ -0,0 +1,59 @@ +from netboxlabs.diode.sdk import DiodeClient +from netboxlabs.diode.sdk.ingester import ( + Device, + Entity, + IPAddress, +) + + +def main(): + with DiodeClient( + target="grpc://localhost:8081", + app_name="my-test-app", + app_version="0.0.1", + api_key="5a52c45ee8231156cb620d193b0291912dd15433", + ) as client: + entities = [] + + """ + Ingest device with device type, platform, manufacturer, site, role, and tags. + """ + + + device = Device( + name="TESTE", + device_type="Device Type A", + platform="Platform A", + manufacturer="Manufacturer A", + site="Site ABC", + role="Role ABC", + serial="123456", + asset_tag="123456", + status="active", + tags=["tag 1", "tag 2"], + ) + + + #device = Device(name="Device A") + + ip_address = IPAddress( + address="172.16.0.1/24", + ) + + print(f"device: {device}") + + #print(f"client: {client}") + #print(f"client (dir): {dir(client)}") + #print(f"client (version): {client._target}") + #print(f"ip_address: {ip_address}") + entities.append(Entity(ip_address=ip_address)) + #entities.append(Entity(ip_address=ip_address)) + + response = client.ingest(entities=entities) + print(f"response: {response}") + if response.errors: + print(f"Errors: {response.errors}") + + +if __name__ == "__main__": + main() diff --git a/netbox_proxbox/backend/diode/docker-compose.yaml b/netbox_proxbox/backend/diode/docker-compose.yaml new file mode 100644 index 0000000..313264c --- /dev/null +++ b/netbox_proxbox/backend/diode/docker-compose.yaml @@ -0,0 +1,92 @@ +name: ${PROJECT_NAME:-diode} +services: + ingress-nginx: + image: nginx:latest + command: > + /bin/sh -c "echo 'upstream diode { + server diode-ingester:8081; + } + + server { + listen 80; + http2 on; + server_name localhost; + client_max_body_size 25m; + location /diode { + rewrite /diode/(.*) /$$1 break; + grpc_pass grpc://diode; + } + }' + > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" + restart: always + environment: + - DIODE_NGINX_PORT=${DIODE_NGINX_PORT} + ports: + - ${DIODE_NGINX_PORT}:80 + depends_on: + - diode-ingester + - diode-reconciler + + diode-ingester: + image: netboxlabs/diode-ingester:${DIODE_TAG:-latest} + environment: + - API_KEY=${RECONCILER_API_KEY} + - REDIS_PASSWORD=${REDIS_PASSWORD} + - REDIS_HOST=${REDIS_HOST} + - REDIS_PORT=${REDIS_PORT} + - RECONCILER_GRPC_HOST=${RECONCILER_GRPC_HOST} + - RECONCILER_GRPC_PORT=${RECONCILER_GRPC_PORT} + - SENTRY_DSN=${SENTRY_DSN} + restart: always + ports: + - "8081:8081" + depends_on: + - diode-redis + - diode-reconciler + + diode-reconciler: + image: netboxlabs/diode-reconciler:${DIODE_TAG:-latest} + environment: + - REDIS_PASSWORD=${REDIS_PASSWORD} + - REDIS_HOST=${REDIS_HOST} + - REDIS_PORT=${REDIS_PORT} + - NETBOX_DIODE_PLUGIN_API_BASE_URL=${NETBOX_DIODE_PLUGIN_API_BASE_URL} + - DIODE_TO_NETBOX_API_KEY=${DIODE_TO_NETBOX_API_KEY} + - NETBOX_TO_DIODE_API_KEY=${NETBOX_TO_DIODE_API_KEY} + - DIODE_API_KEY=${DIODE_API_KEY} + - LOGGING_LEVEL=${LOGGING_LEVEL} + - SENTRY_DSN=${SENTRY_DSN} + restart: always + ports: [ ] + depends_on: + - diode-redis + diode-redis: + image: redis/redis-stack-server:latest + command: + - sh + - -c + - redis-server --appendonly yes --dir /data --save 60 1 --requirepass $$REDIS_PASSWORD --loadmodule /opt/redis-stack/lib/rejson.so --loadmodule /opt/redis-stack/lib/redisearch.so --port $$REDIS_PORT + environment: + - REDIS_PASSWORD=${REDIS_PASSWORD} + - REDIS_PORT=${REDIS_PORT} + ports: [ ] + volumes: + - diode-redis-data:/data + diode-redis-cli: + image: redis/redis-stack-server:latest + links: + - diode-redis + entrypoint: + - sh + - -c + - | + redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" -a "$REDIS_PASSWORD" <