Skip to content

Commit 67659dc

Browse files
committed
NetBox Custom Objects Quickstart guide
1 parent 80bc730 commit 67659dc

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed

custom-objects-quickstart/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
netbox-docker/
2+
environment
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
ENV_FILE="environment"
4+
5+
# Check if the environment file exists
6+
if [ -f "$ENV_FILE" ]; then
7+
echo "Environment file found. Using existing variables."
8+
else
9+
echo "Environment file not found. Generating new variables."
10+
11+
if [[ -z "${MY_EXTERNAL_IP}" ]]; then
12+
# Attempt to fetch the external IPv4 address
13+
EXTERNAL_IP=$(curl -4 -s ifconfig.me) # Use -4 to ensure IPv4 is returned
14+
# Check if the IP was retrieved successfully
15+
if [ -z "$EXTERNAL_IP" ]; then
16+
echo "Error: Unable to determine external IPv4 address."
17+
exit 1
18+
fi
19+
else
20+
EXTERNAL_IP=${MY_EXTERNAL_IP}
21+
fi
22+
23+
# Generate new variables
24+
MY_EXTERNAL_IP=$EXTERNAL_IP
25+
NETBOX_PORT="8000"
26+
NETBOX_TOKEN="1234567890"
27+
28+
# Write variables to the environment file
29+
cat <<EOF > "$ENV_FILE"
30+
MY_EXTERNAL_IP=$MY_EXTERNAL_IP
31+
NETBOX_PORT=$NETBOX_PORT
32+
NETBOX_TOKEN=$NETBOX_TOKEN
33+
EOF
34+
fi
35+
36+
# Export variables from the environment file
37+
while IFS='=' read -r key value; do
38+
export "$key=$value"
39+
done < "$ENV_FILE"
40+
41+
# Debug information to communicate values being used
42+
echo
43+
echo "--- Environment Variables Set ---"
44+
echo "External IP: $MY_EXTERNAL_IP"
45+
echo "NetBox will be deployed at: http://$MY_EXTERNAL_IP:$NETBOX_PORT"
46+
echo "NetBox username: admin"
47+
echo "NetBox password: admin"
48+
echo "NetBox token: $NETBOX_TOKEN"
49+
echo "-----------------------------------"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Check if all required environment variables are set
5+
REQUIRED_VARS=("MY_EXTERNAL_IP" "NETBOX_PORT" "NETBOX_TOKEN")
6+
7+
for var in "${REQUIRED_VARS[@]}"; do
8+
if [ -z "${!var:-}" ]; then
9+
echo "Error: Required environment variable '$var' is not set."
10+
exit 0
11+
fi
12+
done
13+
14+
echo
15+
echo "--- Cloning NetBox Docker ---"
16+
echo
17+
18+
# Clone netbox-docker
19+
git clone --branch 3.3.0 https://github.com/netbox-community/netbox-docker.git
20+
pushd netbox-docker
21+
22+
echo
23+
echo "--- Generating configuration files ---"
24+
echo
25+
26+
# Create Dockerfile for plugins
27+
cat <<EOF > Dockerfile-Plugins
28+
FROM netboxcommunity/netbox:v4.3-3.3.0
29+
30+
RUN uv pip install netboxlabs-netbox-custom-objects
31+
EOF
32+
33+
cat <<EOF > docker-compose.override.yml
34+
services:
35+
netbox:
36+
image: netbox:v4.3-3.3.0-plugins
37+
pull_policy: never
38+
ports:
39+
- "${NETBOX_PORT}:8080"
40+
build:
41+
context: .
42+
dockerfile: Dockerfile-Plugins
43+
environment:
44+
SKIP_SUPERUSER: "false"
45+
SUPERUSER_API_TOKEN: ${NETBOX_TOKEN}
46+
SUPERUSER_EMAIL: ""
47+
SUPERUSER_NAME: "admin"
48+
SUPERUSER_PASSWORD: "admin"
49+
healthcheck:
50+
test: curl -f http://${MY_EXTERNAL_IP}:${NETBOX_PORT}/login/ || exit 1
51+
start_period: 600s
52+
timeout: 3s
53+
interval: 15s
54+
netbox-worker:
55+
image: netbox:v4.3-3.3.0-plugins
56+
pull_policy: never
57+
netbox-housekeeping:
58+
image: netbox:v4.3-3.3.0-plugins
59+
pull_policy: never
60+
EOF
61+
62+
# Add the NetBox Service Mappings plugin
63+
cat <<EOF > configuration/plugins.py
64+
PLUGINS = ["netbox_custom_objects"]
65+
EOF
66+
67+
echo
68+
echo "--- Building NetBox ---"
69+
echo
70+
71+
docker compose build --no-cache
72+
73+
echo
74+
echo "--- Starting NetBox Docker ---"
75+
echo
76+
77+
docker compose up -d
78+
79+
# End
80+
popd
81+
echo "You can now access NetBox here: http://${MY_EXTERNAL_IP}:${NETBOX_PORT}"
82+
echo "username: admin"
83+
echo "password: admin"

custom-objects-quickstart/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# NetBox Custom Objects - Quickstart
2+
3+
This simple repo is intended to get you up and running with NetBox Custom Objects quickly, using NetBox Docker.
4+
5+
## Quick Setup
6+
7+
## Prerequisites
8+
- Docker
9+
- Python 3.8 or higher
10+
11+
### Setup
12+
13+
1. Clone this repository:
14+
```bash
15+
git clone https://github.com/netboxlabs/netbox-learning.git
16+
cd custom-object-testing
17+
```
18+
19+
2. Set up your environment:
20+
21+
[!NOTE]
22+
> By default NetBox will be exposed on your **external** IP address which will not work in most home environments.
23+
> To override this set the `EXTERNAL_IP` variable as shown below. `127.0.0.1` usually works, otherwise choose a local interface IP.
24+
25+
```bash
26+
# OPTIONAL: Set IP address
27+
export EXTERNAL_IP=127.0.0.1
28+
29+
# Set up environment variables
30+
source 1_set_envvars.sh
31+
```
32+
33+
34+
3. Start NetBox with Custom Objects
35+
36+
```bash
37+
# Start NetBox instance
38+
./2_start_netbox.sh
39+
```
40+
41+
### Notes
42+
43+
- Environment variables are written into `environment`. To start from fresh:
44+
45+
```bash
46+
# delete the environment file
47+
rm environment
48+
49+
# Stop NetBox and clean up temporary files
50+
cd netbox-docker
51+
docker compose down
52+
cd ..
53+
rm -fr netbox-docker
54+
55+
# Then go to step 2
56+
```
57+
58+
- The time taken for NetBox to start up depends greatly on the available hardware. The timeout is set to 600 seconds. You can change this in `2_start_netbox.sh`.
59+
- The latest available version of NetBox Custom Objects will be used. You can edit `2_start_netbox.sh` to change this behaviour.

0 commit comments

Comments
 (0)