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.10+
  • Grafana Loki reachable from the NetBox instance

Installation

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.5.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.5-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file netbox_loki-0.0.5.tar.gz.

File metadata

  • Download URL: netbox_loki-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 6ab602efd46a35991270158173f6b4068bea57035f4101c1711561502c3b390d
MD5 68118162ca42ff67bad3f816895a8b61
BLAKE2b-256 f8866ab9584925a8adcef25ca409c5e198425c2d8e8b8157880596513aa03a28

See more details on using hashes here.

Provenance

The following attestation bundles were made for netbox_loki-0.0.5.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.5-py3-none-any.whl.

File metadata

  • Download URL: netbox_loki-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 314d6d9c3e48109b558f0cc8405d0e86aaed1f69262e51f232299042f8b95c80
MD5 34edadbc05f01b5cb5fec33789838069
BLAKE2b-256 b76fcefefeb95bf519fc5f633e4fa618d9724d3e825004fcc7d6b3f8845572b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for netbox_loki-0.0.5-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