Skip to content

Commit f15b01a

Browse files
committed
Align Docker bridge with HACS: use Basic Auth
Both HACS integration and Docker bridge now use the same auth: - NTOPNG_USERNAME (default: admin) - NTOPNG_PASSWORD (required) Removed NTOPNG_TOKEN in favor of username/password. Updated .env.example and docker-compose.yaml.
1 parent 3f518d1 commit f15b01a

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

.env.example

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
# URL of your ntopng instance (include https:// if using SSL)
66
NTOPNG_URL=https://your-ntopng-server:3000
77

8-
# API token from ntopng (Settings -> Users -> Edit User -> API Token)
9-
NTOPNG_TOKEN=your_api_token_here
8+
# ntopng username (default: admin)
9+
NTOPNG_USERNAME=admin
10+
11+
# ntopng password
12+
NTOPNG_PASSWORD=your_password_here
1013

1114
# Interface ID to monitor (default: 0, use ntopng UI to find interface ID)
1215
NTOPNG_IFID=0

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,11 @@ When adding the integration, you'll need:
152152

153153
### Docker Bridge Environment Variables
154154

155-
> **Note:** The Docker bridge currently uses token authentication. For the HACS integration, use username/password (Basic Auth).
156-
157155
| Variable | Description | Default |
158156
|----------|-------------|---------|
159157
| `NTOPNG_URL` | ntopng server URL | `https://localhost:3000` |
160-
| `NTOPNG_TOKEN` | API authentication token | (required) |
158+
| `NTOPNG_USERNAME` | ntopng username | `admin` |
159+
| `NTOPNG_PASSWORD` | ntopng password | (required) |
161160
| `NTOPNG_IFID` | Interface ID to monitor | `0` |
162161
| `NTOPNG_VERIFY_SSL` | Verify SSL certificate | `false` |
163162
| `HA_MQTT_BROKER` | MQTT broker hostname | `homeassistant.local` |

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ services:
77
restart: unless-stopped
88
environment:
99
- NTOPNG_URL=${NTOPNG_URL:-https://localhost:3000}
10-
- NTOPNG_TOKEN=${NTOPNG_TOKEN}
10+
- NTOPNG_USERNAME=${NTOPNG_USERNAME:-admin}
11+
- NTOPNG_PASSWORD=${NTOPNG_PASSWORD}
1112
- NTOPNG_IFID=${NTOPNG_IFID:-0}
1213
- NTOPNG_VERIFY_SSL=${NTOPNG_VERIFY_SSL:-false}
1314
- HA_MQTT_BROKER=${HA_MQTT_BROKER:-homeassistant.local}

ntopng-ha-bridge.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
# --- ntopng Server Settings ---
3232
NTOPNG_URL = os.environ.get("NTOPNG_URL", "https://localhost:3000")
33-
NTOPNG_TOKEN = os.environ.get("NTOPNG_TOKEN", "")
33+
NTOPNG_USERNAME = os.environ.get("NTOPNG_USERNAME", "admin")
34+
NTOPNG_PASSWORD = os.environ.get("NTOPNG_PASSWORD", "")
3435
NTOPNG_IFID = os.environ.get("NTOPNG_IFID", "0")
3536
NTOPNG_VERIFY_SSL = os.environ.get("NTOPNG_VERIFY_SSL", "false").lower() == "true"
3637

@@ -117,20 +118,16 @@ def ntopng_get(endpoint):
117118
"""
118119
Make a GET request to ntopng REST API.
119120
120-
Uses token-based authentication via Authorization header.
121+
Uses HTTP Basic Authentication.
121122
Handles self-signed certificates based on NTOPNG_VERIFY_SSL setting.
122123
"""
123124
url = f"{NTOPNG_URL}{endpoint}"
124-
headers = {
125-
"Authorization": f"Token {NTOPNG_TOKEN}",
126-
"Content-Type": "application/json"
127-
}
128125

129126
try:
130127
debug_log(f"API request: {url}")
131128
response = requests.get(
132129
url,
133-
headers=headers,
130+
auth=(NTOPNG_USERNAME, NTOPNG_PASSWORD),
134131
verify=NTOPNG_VERIFY_SSL,
135132
timeout=30
136133
)
@@ -596,8 +593,8 @@ def main():
596593
sys.exit(0)
597594

598595
# Validate configuration
599-
if not NTOPNG_TOKEN:
600-
print("ERROR: NTOPNG_TOKEN environment variable is required")
596+
if not NTOPNG_PASSWORD:
597+
print("ERROR: NTOPNG_PASSWORD environment variable is required")
601598
sys.exit(1)
602599

603600
# Connect to MQTT broker

0 commit comments

Comments
 (0)