Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • digit-c4/netbox-plugins
  • abramda/netbox-plugins-for-git-lab-pilot
2 results
Show changes
Commits on Source (131)
Showing
with 19918 additions and 157 deletions
......@@ -196,3 +196,8 @@ override.tf.json
terraform.rc
docker-compose.override.yml
#Robot Framework reports
log.html
output.xml
report.html
......@@ -3,7 +3,9 @@ workflow:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH == 'develop'
- if: $CI_COMMIT_BRANCH =~ /^v3*/
- if: $CI_COMMIT_BRANCH =~ /^v4*/
default:
tags:
......@@ -26,10 +28,8 @@ lint-job:
before_script:
- python3 -m venv "$CI_PROJECT_DIR/plugins/venv"
- source "$CI_PROJECT_DIR/plugins/venv/bin/activate"
- pip install pylint
- pip install 'pylint==3.2'
script:
- pylint "$CI_PROJECT_DIR/plugins/netbox-rps-plugin/netbox_rps_plugin" "$CI_PROJECT_DIR/plugins/netbox-rps-plugin/tests"
- pylint "$CI_PROJECT_DIR/plugins/netbox-cert-plugin/netbox_cert_plugin" "$CI_PROJECT_DIR/plugins/netbox-cert-plugin/tests"
- pylint "$CI_PROJECT_DIR/tests"
after_script:
- deactivate
......@@ -40,44 +40,34 @@ build-job: # This job runs in the build stage, which runs first.
script:
- ansible-playbook ansible/build.yml
run-test-job:
run-test:
stage: test
before_script:
- chmod 600 $ANSIBLE_PRIVATE_KEY_FILE
- env ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_PRIVATE_KEY_FILE="$ANSIBLE_PRIVATE_KEY_FILE" ansible-playbook -i "$TESTING_HOSTS" -u debian ansible/deploy_on_test.yml
- python3 -m venv "$CI_PROJECT_DIR/plugins/venv"
- source "$CI_PROJECT_DIR/plugins/venv/bin/activate"
- pip install -r "$CI_PROJECT_DIR/plugins/netbox-rps-plugin/tests/requirements.e2e.txt"
- pip install -r "$CI_PROJECT_DIR/plugins/netbox-cert-plugin/tests/requirements.e2e.txt"
- pip install -r "$CI_PROJECT_DIR/tests/requirements.e2e.txt"
script:
- env HOST="$CI_COMMIT_SHORT_SHA.$HOSTNAME" PORT="$PORT" API_KEY="$API_KEY" pytest -s --junit-xml=tests-report-netbox-rps-plugin.xml "$CI_PROJECT_DIR/plugins/netbox-rps-plugin/tests/"
- env HOST="$CI_COMMIT_SHORT_SHA.$HOSTNAME" PORT="$PORT" API_KEY="$API_KEY" pytest -s --junit-xml=tests-report-netbox-cert-plugin.xml "$CI_PROJECT_DIR/plugins/netbox-cert-plugin/tests/"
- env HOST="$CI_COMMIT_SHORT_SHA.$HOSTNAME" PORT="$PORT" API_KEY="$API_KEY" pytest -s --junit-xml=tests-report-netbox-dist-plugin.xml "$CI_PROJECT_DIR/tests/e2e/"
after_script:
- env ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_PRIVATE_KEY_FILE="$ANSIBLE_PRIVATE_KEY_FILE" ansible-playbook -i "$TESTING_HOSTS" -u debian ansible/halt_test.yml
- deactivate
- rm -rf "$CI_PROJECT_DIR/plugins/venv"
artifacts:
when: always
reports:
junit: tests-report-netbox-*-plugin.xml
trigger:
include:
- local: '.gitlab/test.yml'
strategy: depend
# Create 'resource_group', to avoid collision when executing many pipelines at the same time.
resource_group: test-group
deliver-latest-job:
deliver-image-job:
stage: deliver
variables:
IMAGE_TAG: "latest"
IMAGE_TAG: "testing-${CI_COMMIT_BRANCH}"
IMAGE_TAG_POSTGRES: "15-alpine"
IMAGE_TAG_REDIS: "7-alpine"
script:
- ansible-playbook ansible/deliver.yml
only:
- main
- master
rules:
# deliver latest
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables: # Override IMAGE_TAG variable
IMAGE_TAG: "latest"
# deliver tagged image
- if: $CI_COMMIT_TAG
variables: # Override IMAGE_TAG variable
IMAGE_TAG: $CI_COMMIT_TAG
# For custom Testing images, keep standard, naming your branch as v4.1-someSquadNameRef
- if: $CI_COMMIT_BRANCH == 'develop'
- if: $CI_COMMIT_BRANCH =~ /^v3*/
- if: $CI_COMMIT_BRANCH =~ /^v4*/
deliver-tagged-job:
stage: deliver
variables:
IMAGE_TAG: $CI_COMMIT_TAG
script:
- ansible-playbook ansible/deliver.yml
only:
- tags
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline"
.test-core: &test-core
stage: test
tags:
- debian12_ovh
variables:
TEST_TAG: test
TEST_HOST: localhost
TEST_PORT: 8000
up-test-env-job:
<<: *test-core
before_script:
# check that no other unrelated Netbox is up on destination port.
- if [[ $(curl -f -s http://${TEST_HOST}:${TEST_PORT}/metrics |wc -l) != 0 ]];
then echo "WARNING!! An unrelated Netbox instace has not been shut down properly. Try again, or execute down-test-env-job manually."; exit 1;
fi
# check that runner can do `docker-in-docker`.
- docker info
# Build image to test
- docker build --no-cache -t code.europa.eu:4567/digit-c4/netbox-plugins:${TEST_TAG} .
- docker build --no-cache -t code.europa.eu:4567/digit-c4/netbox-plugins/postgres:${TEST_TAG} ./docker/postgres
- docker build --no-cache -t code.europa.eu:4567/digit-c4/netbox-plugins/redis:${TEST_TAG} ./docker/redis
script:
# Netbox up `http://localhost:8000`
- env TAG=${TEST_TAG} PORT=${TEST_PORT} docker compose -f docker-compose.yml -f docker-compose.test.yml up -d
# wait for netbox to be up and running
- for ((i=1; i<20; i++)); do
if [[ $(curl -f -s http://${TEST_HOST}:${TEST_PORT}/metrics |wc -l) < 250 ]];
then echo "not yet up, sleep for 20 seconds.."; sleep 20;
else echo "Netbox up, we are able to reach metrics page. http://${TEST_HOST}:${TEST_PORT}/metrics."; break;
fi;
if [[ $i == 19 ]];
then echo "Netbox seems not able to start on ${TEST_HOST}:${TEST_PORT}."; exit 1;
fi;
done
run-test-job:
<<: *test-core
before_script:
- python3 -m venv "$CI_PROJECT_DIR/plugins/venv"
- source "$CI_PROJECT_DIR/plugins/venv/bin/activate"
- pip install -r "$CI_PROJECT_DIR/tests/requirements.e2e.txt"
# Remove some tests if plugins are not installed, to keep CI compatibility with different testing branches.
- for str in {cert,mac,rps}; do
if [[ $(cat requirements.txt | grep -e ${str} | wc -l) == 0 ]]; then
rm -r $CI_PROJECT_DIR/tests/e2e/netbox/netbox_${str}*_plugin;
echo "Removed ${str}'s python tests.";
fi;
done
script:
- env HOST="${TEST_HOST}" PORT="${TEST_PORT}" API_KEY="$API_KEY" pytest -s --junit-xml=tests-report-netbox-dist-plugin.xml "$CI_PROJECT_DIR/tests/e2e/"
after_script:
- deactivate
- rm -rf "$CI_PROJECT_DIR/plugins/venv"
artifacts:
when: always
reports:
junit: tests-report-netbox-*-plugin.xml
needs:
- up-test-env-job
run-robot-test-job:
<<: *test-core
before_script:
- python3 -m venv "$CI_PROJECT_DIR/plugins/venv"
- source "$CI_PROJECT_DIR/plugins/venv/bin/activate"
- docker build -t robotframework:latest ./tests/docker/
# Remove some tests if plugins are not installed, to keep CI compatibility with different testing branches.
- for str in {mac,}; do
if [[ $(cat requirements.txt | grep -e ${str} | wc -l) == 0 ]]; then
rm -r $CI_PROJECT_DIR/tests/robot/netbox_${str}*_plugin;
echo "Removed ${str}'s robot tests.";
fi;
done
script:
- docker run --rm -v $CI_PROJECT_DIR:/project --network "host" robotframework:latest bash -c
"robot -v HOST:"${TEST_HOST}" -v PORT:"${TEST_PORT}" -v API_TOKEN:"$API_KEY" --outputdir /project/reports /project/tests/robot/"
after_script:
- sudo chmod -R 777 reports
- docker image rm robotframework:latest --force
- deactivate
- rm -rf "$CI_PROJECT_DIR/plugins/venv"
artifacts:
when: always
paths:
- reports/*
needs:
- up-test-env-job
- run-test-job
down-test-env-job:
<<: *test-core
script:
- echo "Test Env Down"
- env TAG=${TEST_TAG} PORT=${TEST_PORT} docker compose -f docker-compose.yml -f docker-compose.test.yml down -v
after_script:
- docker image rm code.europa.eu:4567/digit-c4/netbox-plugins:${TEST_TAG} --force
- docker image rm code.europa.eu:4567/digit-c4/netbox-plugins/postgres:${TEST_TAG} --force
- docker image rm code.europa.eu:4567/digit-c4/netbox-plugins/redis:${TEST_TAG} --force
- docker image ls
needs:
- up-test-env-job
- run-test-job
- run-robot-test-job
when: always
FROM netboxcommunity/netbox:v3.6.9-2.7.0
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
python3-dev \
python3-venv \
&& \
rm -rf /var/lib/apt/lists/*
COPY ./plugins /opt/netbox/plugins
RUN mkdir /opt/netbox/plugins
COPY requirements.txt /opt/netbox/plugins
COPY netbox_configuration/plugins.py /etc/netbox/config/plugins.py
COPY netbox_configuration/extra.py /etc/netbox/config/extra.py
COPY netbox_configuration/field_choices.py /etc/netbox/config/field_choices.py
COPY netbox_configuration/entrypoint.sh /usr/bin/netbox_plugin_entrypoint.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN pip install -r /opt/netbox/plugins/requirements.txt
RUN rm -rf /opt/netbox/plugins
CMD ["/usr/bin/netbox_plugin_entrypoint.sh"]
......@@ -9,13 +9,25 @@
password: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_PASSWORD') }}"
reauthorize: true
- name: Remove image
- name: Remove image Netbox
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Building image
- name: Remove image Postgres
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove image Redis
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Building image Netbox
community.docker.docker_image:
build:
pull: true
......@@ -23,6 +35,7 @@
args:
http_proxy: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}"
nocache: true
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
push: true
......@@ -30,28 +43,106 @@
force_tag: true
source: build
- name: Get source image
- name: Building image Postgres
community.docker.docker_image:
build:
pull: true
path: ../docker/postgres
args:
http_proxy: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}"
nocache: true
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
push: true
force_source: true
force_tag: true
source: build
- name: Building image Redis
community.docker.docker_image:
build:
pull: true
path: ../docker/redis
args:
http_proxy: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}"
nocache: true
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
push: true
force_source: true
force_tag: true
source: build
- name: Get source image Netbox
ansible.builtin.set_fact:
source_image: "{{ lookup('ansible.builtin.file', '../Dockerfile') | regex_search('FROM (.*):(.*)') | regex_replace('^FROM\\s(.*)$', '\\1') }}"
- name: Remove local image
- name: Get source image Postgres
ansible.builtin.set_fact:
source_image_postgres: >-
"{{ lookup('ansible.builtin.file', '../docker/postgres/Dockerfile') | regex_search('FROM (.*):(.*)') | regex_replace('^FROM\\s(.*)$', '\\1') }}"
- name: Get source image Redis
ansible.builtin.set_fact:
source_image_redis: >-
"{{ lookup('ansible.builtin.file', '../docker/redis/Dockerfile') | regex_search('FROM (.*):(.*)') | regex_replace('^FROM\\s(.*)$', '\\1') }}"
- name: Remove local image Netbox
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove local image
- name: Remove local image Netbox
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove source image
- name: Remove source image Netbox
community.docker.docker_image:
state: absent
name: "{{ source_image }}"
force_absent: true
- name: Remove local image Postgres
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove local image Netbox
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove source image Postgres
community.docker.docker_image:
state: absent
name: "{{ source_image_postgres }}"
force_absent: true
- name: Remove local image Redis
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove local image Redis
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove source image Redis
community.docker.docker_image:
state: absent
name: "{{ source_image_redis }}"
force_absent: true
- name: Log out of registry
community.docker.docker_login:
state: absent
......
......@@ -9,12 +9,12 @@
password: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_PASSWORD') }}"
reauthorize: true
- name: Get image to deliver
- name: Get image to deliver Netbox
community.docker.docker_image:
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
source: pull
- name: Push tag image
- name: Push tag image Netbox
community.docker.docker_image:
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'IMAGE_TAG') }}"
......@@ -22,18 +22,68 @@
force_tag: true
source: local
- name: Remove local image
- name: Remove local image Netbox
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove local image
- name: Remove local image Netbox
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'IMAGE_TAG') }}"
force_absent: true
- name: Get image to deliver Postgres
community.docker.docker_image:
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
source: pull
- name: Push tag image Postgres
community.docker.docker_image:
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'IMAGE_TAG_POSTGRES') }}"
push: true
force_tag: true
source: local
- name: Remove local image Postgres
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove local image Postgres
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/postgres:{{ lookup('ansible.builtin.env', 'IMAGE_TAG_POSTGRES') }}"
force_absent: true
- name: Get image to deliver Redis
community.docker.docker_image:
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
source: pull
- name: Push tag image Redis
community.docker.docker_image:
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'IMAGE_TAG_REDIS') }}"
push: true
force_tag: true
source: local
- name: Remove local image Redis
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"
force_absent: true
- name: Remove local image Redis
community.docker.docker_image:
state: absent
name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}/redis:{{ lookup('ansible.builtin.env', 'IMAGE_TAG_REDIS') }}"
force_absent: true
- name: Log out of registry
community.docker.docker_login:
state: absent
......@@ -26,6 +26,12 @@
dest: "/home/debian/netbox/{{ lookup('ansible.builtin.env', 'CI_PIPELINE_ID') }}/"
mode: "0755"
- name: Copy int SQL file
ansible.builtin.copy:
src: "../docker/postgres/docker-entrypoint-initdb.d"
dest: "/home/debian/netbox/{{ lookup('ansible.builtin.env', 'CI_PIPELINE_ID') }}/"
mode: "0755"
- name: Create .env file
ansible.builtin.copy:
dest: "/home/debian/netbox/{{ lookup('ansible.builtin.env', 'CI_PIPELINE_ID') }}/.env"
......@@ -35,10 +41,10 @@
mode: "0644"
- name: Run `docker-compose up`
community.docker.docker_compose:
community.docker.docker_compose_v2:
project_src: "/home/debian/netbox/{{ lookup('ansible.builtin.env', 'CI_PIPELINE_ID') }}/"
state: present
pull: true
pull: always
- name: Wait until the metrics are available
ansible.builtin.uri:
......
......@@ -3,7 +3,7 @@
tasks:
- name: Run `docker-compose down`
community.docker.docker_compose:
community.docker.docker_compose_v2:
project_src: "/home/debian/netbox/{{ lookup('ansible.builtin.env', 'CI_PIPELINE_ID') }}/"
state: absent
remove_volumes: true
......
version: '3.4'
services:
netbox:
image: "code.europa.eu:4567/digit-c4/netbox-plugins:${TAG}"
image: code.europa.eu:4567/digit-c4/netbox-plugins:${TAG}
container_name: netbox_${TAG}
ports:
- 8080
healthcheck:
start_period: 2s
retries: 30
env_file: env/netbox.env
- ${PORT}:8080
environment:
- DB_HOST=postgres_${TAG}
- REDIS_CACHE_HOST=redis_cache_${TAG}
- REDIS_HOST=redis_${TAG}
labels:
- "traefik.http.routers.netbox-${TAG}.rule=Host(`${TAG}.netbox.ntx.lu`)"
networks:
- traefik
logging:
driver: "syslog"
options:
syslog-address: "tcp://gra1-63cfda8371ef06f3c6bf175c.gra1.logs.ovh.com:6514"
syslog-format: "rfc5424"
tag: "netbox"
netbox-worker:
image: "code.europa.eu:4567/digit-c4/netbox-plugins:${TAG}"
env_file: env/netbox.env
networks:
- traefik
logging:
driver: "syslog"
options:
syslog-address: "tcp://gra1-63cfda8371ef06f3c6bf175c.gra1.logs.ovh.com:6514"
syslog-format: "rfc5424"
tag: "netbox-worker"
netbox-housekeeping:
image: "code.europa.eu:4567/digit-c4/netbox-plugins:${TAG}"
env_file: env/netbox.env
networks:
- traefik
logging:
driver: "syslog"
options:
syslog-address: "tcp://gra1-63cfda8371ef06f3c6bf175c.gra1.logs.ovh.com:6514"
syslog-format: "rfc5424"
tag: "netbox-housekeeping"
postgres:
image: code.europa.eu:4567/digit-c4/netbox-plugins/postgres:${TAG}
container_name: postgres_${TAG}
env_file: env/postgres.env
networks:
- traefik
logging:
driver: "syslog"
options:
......@@ -56,10 +24,8 @@ services:
syslog-format: "rfc5424"
tag: "netbox-postgres"
redis:
image: code.europa.eu:4567/digit-c4/netbox-plugins/redis:${TAG}
container_name: redis_${TAG}
env_file: env/redis.env
networks:
- traefik
logging:
driver: "syslog"
options:
......@@ -67,18 +33,11 @@ services:
syslog-format: "rfc5424"
tag: "netbox-redis"
redis-cache:
image: code.europa.eu:4567/digit-c4/netbox-plugins/redis:${TAG}
container_name: redis_cache_${TAG}
env_file: env/redis-cache.env
networks:
- traefik
logging:
driver: "syslog"
options:
syslog-address: "tcp://gra1-63cfda8371ef06f3c6bf175c.gra1.logs.ovh.com:6514"
syslog-format: "rfc5424"
tag: "netbox-cache"
networks:
traefik:
name: traefik_traefik
external: true
version: '3.4'
services:
netbox: &netbox
image: code.europa.eu:4567/digit-c4/netbox-plugins:latest
depends_on:
- postgres
- redis
- redis-cache
postgres:
condition: service_healthy
redis:
condition: service_started
redis-cache:
condition: service_started
user: 'unit:root'
healthcheck:
interval: 60s
start_period: 60s
timeout: 3s
interval: 15s
test: "curl -f http://localhost:8080/api/ || exit 1"
start_interval: 5s
retries: 5
test: "curl -f http://localhost:8080 || exit 1"
env_file: env/netbox.env
volumes:
- netbox-media-files:/opt/netbox/netbox/media:z,rw
- netbox-reports-files:/opt/netbox/netbox/reports:z,rw
- netbox-scripts-files:/opt/netbox/netbox/scripts:z,rw
netbox-worker:
<<: *netbox
depends_on:
netbox:
condition: service_healthy
command:
- /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py
- rqworker
healthcheck:
start_period: 20s
timeout: 3s
interval: 15s
test: "ps -aux | grep -v grep | grep -q rqworker || exit 1"
netbox-housekeeping:
<<: *netbox
depends_on:
netbox:
condition: service_healthy
command:
- /opt/netbox/housekeeping.sh
healthcheck:
start_period: 20s
timeout: 3s
interval: 15s
test: "ps -aux | grep -v grep | grep -q housekeeping || exit 1"
# postgres
- netbox-media-files:/opt/netbox/netbox/media
- netbox-reports-files:/opt/netbox/netbox/reports
- netbox-scripts-files:/opt/netbox/netbox/scripts
environment:
- ACTIVATE_WORKER_AND_HOUSEKEEPING=1
postgres:
image: docker.io/postgres:15-alpine
image: code.europa.eu:4567/digit-c4/netbox-plugins/postgres:15-alpine
env_file: env/postgres.env
healthcheck:
interval: 60s
start_period: 60s
start_interval: 10s
retries: 5
test: "pg_isready -h localhost -U $$POSTGRES_USER"
volumes:
- netbox-postgres-data:/var/lib/postgresql/data
# redis
- ./docker/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
redis:
image: docker.io/redis:7-alpine
image: code.europa.eu:4567/digit-c4/netbox-plugins/redis:7-alpine
env_file: env/redis.env
command:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
......@@ -59,14 +44,14 @@ services:
volumes:
- netbox-redis-data:/data
redis-cache:
image: docker.io/redis:7-alpine
image: code.europa.eu:4567/digit-c4/netbox-plugins/redis:7-alpine
env_file: env/redis-cache.env
command:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
volumes:
- netbox-redis-cache-data:/data
volumes:
netbox-media-files:
driver: local
......@@ -80,3 +65,5 @@ volumes:
driver: local
netbox-scripts-files:
driver: local
netbox-docker-agent:
driver: local
FROM docker.io/postgres:15-alpine
FROM docker.io/redis:7-alpine
# Creating a Webhook in NetBox Instance Documentation
Webhooks in NetBox provide a powerful mechanism to trigger custom actions or workflows when certain events occur within the system. This documentation outlines the process of creating a webhook in a NetBox instance to generate default entries, such as RPS HTTP Headers, when inserting data even in a different context, such as RPS Mappings.
## Prerequisites
Before creating a webhook in your NetBox instance, ensure you have the following:
1. Understanding of Webhooks: Familiarity with the concept of webhooks and how they work is recommended.
2. Understanding of NetBox Models: Knowledge of NetBox data models, especially the ones relevant to the context where you want to insert data, is necessary.
## Steps to Create a Webhook
Follow these steps to create a Webhook in your NetBox instance:
#### 1. Create the API token
Click on your username on the top right corner of the screen and select API Token.
#### 2. Create a new token
Fill the form in order to create a token and store it for later use.
#### 3. Navigate to Webhooks Section
Navigate to the “Operations” menu option and click on "Webhooks".
#### 4. Add a new Webhook
Click on the green button labelled "+Add" to add a new Webhook.
#### 5. Fill the form
Fill the details of your Webhook:
##### Webhook Section
Name: Name of your Webhook.
Content Types: Content that will be used as a primary trigger. For example: "Netbox RPS > Mapping".
Enable Flag: Click if you want to enable your Webhook.
Events: Which events will be used to trigger your Webhook.
##### HTTP Request Section
URL: This URL will be called using the HTTP method defined when the webhook is called.
HTTP Method: Which method will be used.
HTTP Content type: application/json.
Additional headers: Get the Authorization API Token that you created earlier in this tutorial.
Body template: Jason template for the object you want to create when the selected event is triggered.
For example, HTTP Headers:
```
{
"name": "X-Forwarded-Proto",
"value": "request.x_header.X-Forwarded-Proto $(CLIENT.PROTOCOL)",
"apply_to": "request",
"mapping": {"id": "{{ data['id'] }}"}
}
```
or multiple objects, multiple HTTP Headers:
```
[
{
"name": "X-Forwarded-Proto",
"value": "request.x_header.X-Forwarded-Proto $(CLIENT.PROTOCOL)",
"apply_to": "request",
"mapping": {"id": "{{ data['id'] }}"}
},
{
"name": "client-IP",
"value": "request.header.client-IP $(client.address)",
"apply_to": "request",
"mapping": {"id": "{{ data['id'] }}"}
},
{
"name": "Forwarded-For",
"value": "request.header.X-Forwarded-For $(client.effective_address)",
"apply_to": "request",
"mapping": {"id": "{{ data['id'] }}"}
},
{
"name": "Forwarded-Host",
"value": "request.x_header.X-Forwarded-Host $(url.host)",
"apply_to": "request",
"mapping": {"id": "{{ data['id'] }}"}
}
]
```
#### 6. Save the webhook
Then you can click the Save Button
......@@ -30,9 +30,9 @@ REDIS_DATABASE=0
REDIS_INSECURE_SKIP_TLS_VERIFY=false
REDIS_PASSWORD=H733Kdjndks81
REDIS_SSL=false
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
SECRET_KEY=r(m)9nLGnz$(_q3N4z1k(EFsMCjjjzx08x9VhNVcfd%6RF#r!6DE@+V5Zk2X
SKIP_SUPERUSER=false
SUPERUSER_PASSWORD=thisnetboxisnot4u
SUPERUSER_API_TOKEN=only4testingpurpose
WEBHOOKS_ENABLED=true
ACTIVATE_WORKER_AND_HOUSEKEEPING=1
#!/bin/bash
########################################################
# Select how to start Netbox Docker.
# set env variable `ACTIVATE_WORKER_AND_HOUSEKEEPING` if needed to:
# - 1
# - 0 (legacy)
########################################################
migrate_func () {
########################################################################################
# Piece of code borrowed from netbox official `/opt/netbox/docker-entrypoint.sh` script.
########################################################################################
# Load correct Python3 env
source /opt/netbox/venv/bin/activate
# Check if update is needed
if ! ./manage.py migrate --check >/dev/null 2>&1; then
echo "⚙️ Applying database migrations"
./manage.py migrate --no-input
echo "⚙️ Running trace_paths"
./manage.py trace_paths --no-input
echo "⚙️ Removing stale content types"
./manage.py remove_stale_contenttypes --no-input
echo "⚙️ Removing expired user sessions"
./manage.py clearsessions
echo "⚙️ Building search index (lazy)"
./manage.py reindex --lazy
fi
}
if [[ "${ACTIVATE_WORKER_AND_HOUSEKEEPING}" == 1 ]] ; then
echo "var ACTIVATE_WORKER_AND_HOUSEKEEPING=1"
echo "Netbox-worker and Netbox-housekeeping will not need extra containers to run."
# run function.
migrate_func && \
# Start netbox with `netbox-worker` and `netbox-housekeeping` running on same container
supervisord --configuration /etc/supervisor/conf.d/supervisord.conf
else
echo "var ACTIVATE_WORKER_AND_HOUSEKEEPING=0"
echo "Netbox-worker and Netbox-housekeeping might need separate containers to run."
## Launch regular netbox entrypoint
/opt/netbox/docker-entrypoint.sh /opt/netbox/launch-netbox.sh
fi
CENSUS_REPORTING_ENABLED = False
RELEASE_CHECK_URL = None
DEFAULT_DASHBOARD = [
{
"widget": "extras.BookmarksWidget",
"width": 4,
"height": 5,
"title": "Bookmarks",
"color": "orange",
},
{
"widget": "extras.ObjectCountsWidget",
"width": 4,
"height": 2,
"title": "Organization",
"config": {
"models": [
"dcim.site",
"tenancy.tenant",
"tenancy.contact",
]
},
},
{
"widget": "extras.NoteWidget",
"width": 4,
"height": 2,
"title": "Welcome!",
"color": "green",
"config": {
"content": (
"This is your personal dashboard. Feel free to customize it by rearranging, resizing, or removing "
'widgets. You can also add new widgets using the "add widget" button below. Any changes affect only '
"_your_ dashboard, so feel free to experiment!"
)
},
},
{
"widget": "extras.ObjectCountsWidget",
"width": 4,
"height": 3,
"title": "IPAM",
"config": {
"models": [
"ipam.vrf",
"ipam.aggregate",
"ipam.prefix",
"ipam.iprange",
"ipam.ipaddress",
"ipam.vlan",
]
},
},
{
"widget": "extras.ObjectCountsWidget",
"width": 4,
"height": 3,
"title": "Circuits",
"config": {
"models": [
"circuits.provider",
"circuits.circuit",
"circuits.providernetwork",
"circuits.provideraccount",
]
},
},
{
"widget": "extras.ObjectCountsWidget",
"width": 4,
"height": 3,
"title": "DCIM",
"config": {
"models": [
"dcim.site",
"dcim.rack",
"dcim.devicetype",
"dcim.device",
"dcim.cable",
],
},
},
{
"widget": "extras.ObjectCountsWidget",
"width": 4,
"height": 2,
"title": "Virtualization",
"config": {
"models": [
"virtualization.cluster",
"virtualization.virtualmachine",
]
},
},
{
"widget": "extras.ObjectListWidget",
"width": 12,
"height": 5,
"title": "Change Log",
"color": "blue",
"config": {
"model": "extras.objectchange",
"page_size": 25,
},
},
]
FIELD_CHOICES = {
'netbox_dns.Record.status+':(
('planned', 'Planned', 'grey'),
('failed', 'Failed', 'red'),
('deployed', 'Deployed', 'green')
)
}
\ No newline at end of file
PLUGINS = ['netbox_dns', 'netbox_rps_plugin', 'netbox_cert_plugin', 'netbox_prometheus_sd', 'netbox_docker_plugin']
PLUGINS = [
"netbox_dns",
"netbox_rps_plugin",
"netbox_cert_plugin",
"netbox_prometheus_sd",
"netbox_docker_plugin",
"netbox_mac_address_plugin",
]
global-include *.html