netbox
Method
Installation and Setup
git clone -b release https://github.com/netbox-community/netbox-docker.git
cd netbox-docker
The netbox-docker
directory contains
- files required for the container to spin up
- Configuration files
The directory already contains a docker-compose.yml
file. Custom docker compose
configurations can be entered in docker-compose.override.yml
, which will be read after docker-compose.yml
file, and overwrite any overlapping configurations.
The default cloned repository is not ready for production. Needs to change environment variables before exposing the service.
# docker-compose.override.yml
version: '3.4'
services:
netbox:
image: netbox:latest-plugins
ports:
- $NETBOX_PORT:8080
build:
context: .
dockerfile: Dockerfile-Plugins
env_file: .env
netbox-worker:
image: netbox:latest-plugins
env_file: .env
build:
context: .
dockerfile: Dockerfile-Plugins
netbox-housekeeping:
image: netbox:latest-plugins
env_file: .env
build:
context: .
dockerfile: Dockerfile-Plugins
postgres:
env_file: .env
volumes:
- ./db:/var/lib/postgresql/data
environment:
POSTGRES_DB: $DB_NAME
POSTGRES_PASSWORD: $DB_PASSWORD
POSTGRES_USER: $DB_USER
redis:
env_file: .env
volumes:
- ./redis:/data
redis-cache:
environment:
REDIS_PASSWORD: $REDIS_CACHE_PASSWORD
env_file: .env
#
volumes:
netbox-media-files:
driver: local
driver_opts:
o: bind
type: none
device: ./media
netbox-redis-cache-data:
driver: local
netbox-reports-files:
driver: local
driver_opts:
o: bind
type: none
device: ./reports
netbox-scripts-files:
driver: local
driver_opts:
o: bind
type: none
device: ./scripts
# .env
CORS_ORIGIN_ALLOW_ALL=True
DB_HOST=postgres
DB_NAME=netbox
DB_PASSWORD=<RANDOM_PASSWORD>
DB_USER=netbox
EMAIL_FROM=netbox@bar.com
EMAIL_PASSWORD=
EMAIL_PORT=25
EMAIL_SERVER=localhost
EMAIL_SSL_CERTFILE=
EMAIL_SSL_KEYFILE=
EMAIL_TIMEOUT=5
EMAIL_USERNAME=netbox
# EMAIL_USE_SSL and EMAIL_USE_TLS are mutually exclusive, i.e. they can't both be `true`!
EMAIL_USE_SSL=false
EMAIL_USE_TLS=false
GRAPHQL_ENABLED=true
HOUSEKEEPING_INTERVAL=86400
MEDIA_ROOT=/opt/netbox/netbox/media
METRICS_ENABLED=false
REDIS_CACHE_DATABASE=1
REDIS_CACHE_HOST=redis-cache
REDIS_CACHE_INSECURE_SKIP_TLS_VERIFY=false
REDIS_CACHE_PASSWORD=<RANDOM_PASSWORD>
REDIS_CACHE_SSL=false
REDIS_DATABASE=0
REDIS_HOST=redis
REDIS_INSECURE_SKIP_TLS_VERIFY=false
REDIS_PASSWORD=<RANDOM_PASSWORD>
REDIS_SSL=false
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
SECRET_KEY='<GENERATED_SECRET_KEY>'
SKIP_SUPERUSER=true
WEBHOOKS_ENABLED=true
- The local volumes are mapped to local directories for persistent data storage.
- Environment variables are moved to a centralized file for easy management
<GENERATED_SECRET_KEY>
is generated usingdocker compose run netbox python3 /opt/netbox/netbox/generate_secret_key.py
innetbox-docker
directory- Configuration · netbox-community/netbox-docker Wiki · GitHub
Go to IP:32773
to check
Create Superuser
After the container is up, need to create superuser
docker compose exec netbox /opt/netbox/netbox/manage.py createsuperuser
Then, use superuser credentials to login
Installing Plugins
Guide: Using Netbox Plugins · netbox-community/netbox-docker Wiki · GitHub Resources:
Setup Configuration
touch plugin_requirements.txt Dockerfile-Plugins
plugin_requirements.txt
netbox-secrets
Dockerfile-Plugins
FROM netboxcommunity/netbox:latest
COPY ./plugin_requirements.txt /opt/netbox/
RUN /opt/netbox/venv/bin/pip install --no-warn-script-location -r /opt/netbox/plugin_requirements.txt
# These lines are only required if your plugin has its own static files.
COPY configuration/configuration.py /etc/netbox/config/configuration.py
COPY configuration/plugins.py /etc/netbox/config/plugins.py
# NOTE: This SECRET_KEY is only used during the installation. There's no need to change it.
RUN SECRET_KEY="dummydummydummydummydummydummydummydummydummydummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input
Enable plugins in the configuration
configuration/plugins.py
PLUGINS = ["netbox_secrets"]
# PLUGINS_CONFIG = {
# "netbox_secretstore": {
# ADD YOUR SETTINGS HERE
# }
# }
Build plugins after updating configuration
docker compose build --no-cache
docker compose up -d
Process
- Check official netbox docker compose image
- GitHub - netbox-community/netbox-docker: 🐳 Docker Image of NetBox
- Quite complicated, looking to see if there is an easier way
- GitHub - linuxserver/docker-netbox
- hmmm....
- Decided to try official way
- ![[Pasted image 20231206131933.png]]
- Wait...
- Access on webpage
- Create admin user
docker compose exec netbox /opt/netbox/netbox/manage.py createsuperuser
- Setup
- HomeLab Stage LIV: Datacenter Documentation - VCDX #181 Marc Huppert
Random Information
The thing about Device Types
There is a library of device types on GitHub, go there and check if you can find the device model you want and import it into Netbox.
Automated Device Type Import
I added ghcr.io/minitriga/netbox-device-type-library-import in my docker-compose.override.yml
file, and it automatically imports the device types from the vendors I specified.
netbox-device-type-library-import:
image: ghcr.io/minitriga/netbox-device-type-library-import
environment:
NETBOX_URL: http://netbox:8080
NETBOX_TOKEN: <NETBOX_TOKEN>
# VENDORS:
Possibility of Snipe-it integration
netbox is great, but is there a better method to manage my inventory assets?
How to use netbox-ping-scan
Clone repo
cd netbox-docker
git clone https://github.com/henrionlo/netbox-ping-scan
Edit the script to match environment
Edit the netbox-ping-scan.py
file
NETBOX_URL = "http://localhost:<YOUR_NETBOX_PORT>"
NETBOX_TOKEN = "<NETBOX_API_TOKEN>"
Set IP Range to be scanned
Create two new tags in Netbox (Customization > Tags)
autoscan
- set
Allowed Object Types
toIPAM > IP address
toscan
- set
Allowed Object Types
toIPAM > prefix
Add and tag IPAM > Prefixes
- add new prefix
192.168.1.0/24
and addtoscan
tag
Add IP Address to be updated by the script
- add the IPs in
IPAM > IP Addresses
and add theautoscan
tag
Install dependencies and run script
python3 -m venv venv
. ./venv/bin/activate # . ./venv/bin/activate.fish
pip install pynetbox requests ipaddress urllib3
python ./netbox-ping-scan/netbox-ping-scan.py
netbox-agent
GitHub - Solvik/netbox-agent: Netbox agent to run on your infrastructure's servers
Clone Repository
git clone https://github.com/Solvik/netbox-agent.git
cd netbox-agent
Edit code to match latest pynetbox API
- In
./netbox_agent/server.py
change alldevice_role=
torole=
Error during script execution
DEBUG:urllib3.connectionpool:http://localhost:32773 "POST /api/dcim/devices/ HTTP/1.1" 400 36
Traceback (most recent call last):
File "/usr/local/bin/netbox_agent", line 8, in \<module>
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/netbox_agent/cli.py", line 50, in main
return run(config)
File "/usr/local/lib/python3.10/dist-packages/netbox_agent/cli.py", line 43, in run
server.netbox_create_or_update(config)
File "/usr/local/lib/python3.10/dist-packages/netbox_agent/server.py", line 407, in netbox_create_or_update
server = self._netbox_create_server(datacenter, tenant, rack)
File "/usr/local/lib/python3.10/dist-packages/netbox_agent/server.py", line 272, in _netbox_create_server
new_server = nb.dcim.devices.create(
File "/usr/local/lib/python3.10/dist-packages/pynetbox/core/endpoint.py", line 309, in create
).post(args[0] if args else kwargs)
File "/usr/local/lib/python3.10/dist-packages/pynetbox/core/query.py", line 387, in post
return self._make_call(verb="post", data=data)
File "/usr/local/lib/python3.10/dist-packages/pynetbox/core/query.py", line 282, in _make_call
raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'role': ['This field is required.']}
Checked recent changes in pynetbox and found that all device_role=
params are changed to role=
Install requirements
python3 -m venv venv
. ./venv/bin/activate
pip3 install -r requirements.txt
Edit Config File
sudo vim /etc/qualification
/etc/qualification
:
datacenter: <DATACENTER_LOCATION>
sudo vim /etc/netbox_agent.yaml
# /etc/netbox_agent.yaml
# Netbox configuration
netbox:
url: 'http://<NETBOX_IP>:<NETBOX_PORT>'
token: '<NETBOX_API_TOKEN>'
# uncomment to disable ssl verification
# ssl_verify: false
# uncomment to use the system's CA certificates
# ssl_ca_certs_file: /etc/ssl/certs/ca-certificates.crt
# Network configuration
network:
# Regex to ignore interfaces
ignore_interfaces: "(dummy.*|docker.*)"
# Regex to ignore IP addresses
ignore_ips: (127\.0\.0\..*)
# enable auto-cabling by parsing LLDP answers
lldp: false
#
# You can use these to change the Netbox roles.
# These are the defaults.
#
device:
#chassis_role: "Server Chassis"
#blade_role: "Blade"
server_role: "<SERVER_ROLE>"
# tags: server, blade, ,just a comma,delimited,list
# custom_fields: field1=value1,field2=value2#
#
# Can use this to set the tenant
#
#tenant:
# driver: "file:/tmp/tenant"
# regex: "(.*)"
## Enable virtual machine support
# virtual:
# # not mandatory, can be guessed
# enabled: True
# # see https://netbox.company.com/virtualization/clusters/
# cluster_name: my_vm_cluster
# Enable datacenter location feature in Netbox
datacenter_location:
driver: "cmd:cat /etc/qualification | tr [A-Z] [a-z]"
regex: "datacenter: (?P<datacenter>[A-Za-z0-9]+)"
# driver: 'cmd:lldpctl'
# regex: 'SysName: .*\.([A-Za-z0-9]+)'
#
# driver: "file:/tmp/datacenter"
# regex: "(.*)"
# Enable rack location feature in Netbox
# rack_location:
# driver: 'cmd:lldpctl'
# match SysName: sw-dist-a1.dc42
# regex: 'SysName:[ ]+[A-Za-z]+-[A-Za-z]+-([A-Za-z0-9]+)'
#
# driver: "file:/tmp/datacenter"
# regex: "(.*)"
# Enable local inventory reporting
inventory: true
Register Device
python3 -m netbox_agent.cli --register
Update network
python3 -m netbox_agent.cli --update-network
Update Inventory
python3 -m netbox_agent.cli --update-inventory