NetBox plugin to display Loki logs in device, VM, and endpoint detail pages
Project description
NetBox Loki Logs Plugin
Fork from https://github.com/sieteunoseis/netbox-graylog
A NetBox plugin that displays recent Loki logs on Device, VirtualMachine, and optional Endpoint detail pages.
What Changed
This fork replaces the unfinished Graylog integration with a Loki-based implementation:
- Queries Loki via
/loki/api/v1/query_range - Supports optional
X-Scope-OrgID, bearer token, and basic auth - Matches devices by a configurable Loki label such as
routerboard,host, orhostname - Can fall back to a NetBox primary IP when hostname lookup returns no results
- Provides a Loki summary dashboard widget based on LogQL aggregations
Features
- Logs tab on Device and VirtualMachine pages
- Optional Endpoint support when
netbox_endpointsis installed - Time range selector for 5m, 15m, 1h, 4h, 24h, and 7d
- Caching to reduce API load on Loki
- Connection test from the plugin settings page
- Shortname/FQDN matching for label-based hostname lookups
Requirements
- NetBox 4.0 or higher
- Python 3.11+
- Grafana Loki reachable from the NetBox instance
Installation
source /opt/netbox/venv/bin/activate
pip install netbox-loki
or for dev
git clone https://github.com/SerhiiZahuba/netbox-loki.git
cd netbox-graylog
pip install -e .
Configuration
Add the plugin to NetBox:
PLUGINS = [
"netbox_loki",
]
PLUGINS_CONFIG = {
"netbox_loki": {
"loki_url": "http://loki:3100",
"loki_external_url": "https://grafana.example.com/explore",
"loki_tenant": "loki_tenant",
"loki_username": "",
"loki_password": "",
"loki_bearer_token": "",
"loki_job": "syslog",
"device_label": "routerboard",
"stream_selector": "",
"log_limit": 100,
"time_range": 3600,
"timeout": 10,
"cache_timeout": 60,
"verify_tls": True,
"use_regex_matching": True,
"fallback_to_ip": True,
}
}
Loki Query Model
The plugin builds LogQL stream selectors like:
{job="syslog",routerboard=~"^edge-sw01(?:\\..+)?$"}
You can further narrow the stream by setting stream_selector, for example:
"stream_selector": 'site="kyiv",env="prod"'
Notes
device_labelshould point to the Loki label that contains the NetBox object name.- If your labels contain FQDNs while NetBox stores short names, leave
use_regex_matching=True. loki_external_urlis only used for opening the log platform from the UI; API calls still useloki_url.- Authorization in Loki is commonly provided by a reverse proxy or managed service. This plugin supports optional bearer token and basic auth for that case.
Troubleshooting
No logs appear
- Verify the object name in NetBox matches the configured Loki label value.
- Confirm
device_labelpoints to the correct Loki label. - Check
stream_selectorandloki_jobare not overly restrictive. - Enable
fallback_to_ipif your logs are labeled by IP rather than hostname.
Connection test fails
- Verify
loki_urlis reachable from the NetBox host or container. - If Loki uses multi-tenancy, set
loki_tenant. - If TLS is self-signed, set
verify_tls=False. - If access is proxied, configure
loki_bearer_tokenorloki_username/loki_password.
Development
pip install -e ".[dev]"
License
Apache License 2.0 - see LICENSE.
Reference
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file netbox_loki-0.0.8.tar.gz.
File metadata
- Download URL: netbox_loki-0.0.8.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e6e19e0353ca14c5afa2fba5bdbf6aaf4102c4b81a3281a63ff6af2b1d4c04b
|
|
| MD5 |
90c0c548093b242c94d3c7de1849fc39
|
|
| BLAKE2b-256 |
c6c864ff6f9acbc4c0cad3e8f8ada964e83508dde7f6712370a5d5ece40a55c6
|
Provenance
The following attestation bundles were made for netbox_loki-0.0.8.tar.gz:
Publisher:
release.yml on SerhiiZahuba/netbox-loki
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
netbox_loki-0.0.8.tar.gz -
Subject digest:
3e6e19e0353ca14c5afa2fba5bdbf6aaf4102c4b81a3281a63ff6af2b1d4c04b - Sigstore transparency entry: 1710061467
- Sigstore integration time:
-
Permalink:
SerhiiZahuba/netbox-loki@adc96bff8ea4ec91c700b3682b5e4fe85e2d41b1 -
Branch / Tag:
refs/tags/v0.0.8 - Owner: https://github.com/SerhiiZahuba
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@adc96bff8ea4ec91c700b3682b5e4fe85e2d41b1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file netbox_loki-0.0.8-py3-none-any.whl.
File metadata
- Download URL: netbox_loki-0.0.8-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a63a75c27a71f57fe8bd28918fdc441860e2ef919a127df9cb1648c6f47ac1e
|
|
| MD5 |
c7bb4bc685630a234243c45c8ed801fd
|
|
| BLAKE2b-256 |
4f5b5591d5e1a4bbf10644e2f762da87c49602b061cb81573f9611da2181c1ae
|
Provenance
The following attestation bundles were made for netbox_loki-0.0.8-py3-none-any.whl:
Publisher:
release.yml on SerhiiZahuba/netbox-loki
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
netbox_loki-0.0.8-py3-none-any.whl -
Subject digest:
1a63a75c27a71f57fe8bd28918fdc441860e2ef919a127df9cb1648c6f47ac1e - Sigstore transparency entry: 1710061473
- Sigstore integration time:
-
Permalink:
SerhiiZahuba/netbox-loki@adc96bff8ea4ec91c700b3682b5e4fe85e2d41b1 -
Branch / Tag:
refs/tags/v0.0.8 - Owner: https://github.com/SerhiiZahuba
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@adc96bff8ea4ec91c700b3682b5e4fe85e2d41b1 -
Trigger Event:
push
-
Statement type: