From b9750d76cd2094e9f4efbde09dd9dedf02651299 Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Sun, 3 Nov 2024 20:35:07 -0700 Subject: [PATCH] added netbox healthcheck plugin (https://github.com/netbox-community/netbox-healthcheck-plugin/) --- Dockerfiles/netbox.Dockerfile | 2 ++ netbox/scripts/netbox_install_plugins.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/Dockerfiles/netbox.Dockerfile b/Dockerfiles/netbox.Dockerfile index 9bf794a4f..c422a0ce3 100644 --- a/Dockerfiles/netbox.Dockerfile +++ b/Dockerfiles/netbox.Dockerfile @@ -31,6 +31,7 @@ ENV SUPERCRONIC_CRONTAB "/etc/crontab" ENV NETBOX_INITIALIZERS_VERSION "50d077d" ENV NETBOX_TOPOLOGY_VERSION "4.0.1" +ENV NETBOX_HEALTHCHECK_VERSION "0.2.0" ENV YQ_VERSION "4.44.3" ENV YQ_URL "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_" @@ -86,6 +87,7 @@ RUN export BINARCH=$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/') "${NETBOX_PATH}/venv/bin/python" -m pip install --break-system-packages --no-compile --no-cache-dir \ "git+https://github.com/tobiasge/netbox-initializers@${NETBOX_INITIALIZERS_VERSION}" \ "git+https://github.com/netbox-community/netbox-topology-views@v${NETBOX_TOPOLOGY_VERSION}" \ + "git+https://github.com/netbox-community/netbox-healthcheck-plugin@v${NETBOX_HEALTHCHECK_VERSION}" \ psycopg2 \ pynetbox \ python-magic \ diff --git a/netbox/scripts/netbox_install_plugins.py b/netbox/scripts/netbox_install_plugins.py index 02524ad71..60960a77f 100755 --- a/netbox/scripts/netbox_install_plugins.py +++ b/netbox/scripts/netbox_install_plugins.py @@ -189,6 +189,17 @@ def main(): netboxVenvPy = os.path.join(os.path.join(os.path.join(args.netboxDir, 'venv'), 'bin'), 'python') manageScript = os.path.join(os.path.join(args.netboxDir, 'netbox'), 'manage.py') + # set a variable in local_settings.py for netbox-helathcheck-plugin + # see https://github.com/netbox-community/netbox-healthcheck-plugin/issues/12#issuecomment-2451665212 + netboxSettingsPyDir = os.path.join(args.netboxDir, os.path.join('netbox', 'netbox')) + if os.path.isdir(netboxSettingsPyDir): + try: + localSettingsPyContents = "import os\n\nREDIS_URL = f\"redis://{os.environ.get('REDIS_USERNAME', '')}:{os.environ.get('REDIS_PASSWORD', '')}@{os.environ.get('REDIS_HOST', 'netbox-redis')}:{os.environ.get('REDIS_PORT', '6379')}/{os.environ.get('REDIS_DATABASE', '0')}\"\n" + with open(f"{netboxSettingsPyDir}/local_settings.py", 'w') as f: + f.write(localSettingsPyContents) + except Exception as e: + logging.error(f"{type(e).__name__} writing local_settings.py: {e}") + if os.path.isdir(args.customPluginsDir) and os.path.isfile(os.path.join(args.netboxConfigDir, 'plugins.py')): # get a list of what packages/plugins already installed (package names and versions in a dict)