Skip to main content

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

NetBox Loki Logs Plugin

A NetBox plugin that displays recent Loki logs on Device, VirtualMachine, and optional Endpoint detail pages.

NetBox Version Python Version License

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, or hostname
  • 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_endpoints is 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_label should 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_url is only used for opening the log platform from the UI; API calls still use loki_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_label points to the correct Loki label.
  • Check stream_selector and loki_job are not overly restrictive.
  • Enable fallback_to_ip if your logs are labeled by IP rather than hostname.

Connection test fails

  • Verify loki_url is 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_token or loki_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

netbox_loki-0.0.8.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netbox_loki-0.0.8-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

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

Hashes for netbox_loki-0.0.8.tar.gz
Algorithm Hash digest
SHA256 3e6e19e0353ca14c5afa2fba5bdbf6aaf4102c4b81a3281a63ff6af2b1d4c04b
MD5 90c0c548093b242c94d3c7de1849fc39
BLAKE2b-256 c6c864ff6f9acbc4c0cad3e8f8ada964e83508dde7f6712370a5d5ece40a55c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for netbox_loki-0.0.8.tar.gz:

Publisher: release.yml on SerhiiZahuba/netbox-loki

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for netbox_loki-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1a63a75c27a71f57fe8bd28918fdc441860e2ef919a127df9cb1648c6f47ac1e
MD5 c7bb4bc685630a234243c45c8ed801fd
BLAKE2b-256 4f5b5591d5e1a4bbf10644e2f762da87c49602b061cb81573f9611da2181c1ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for netbox_loki-0.0.8-py3-none-any.whl:

Publisher: release.yml on SerhiiZahuba/netbox-loki

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page