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

Uploaded Python 3

File details

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

File metadata

  • Download URL: netbox_loki-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 2569b646a3f0a2989e8fefc75e41f36c0f7ddbe464a445b5d106a2e91667f0c6
MD5 c203803b382ed40626b0c7fa3bd9e8b1
BLAKE2b-256 0519d71e8cc43c2c083cf8d3322ca5611e614f4d2e49527244fe964b24c39e0d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: netbox_loki-0.0.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 580a8dec0e40e5791e0b7c11639e01a78d6f285b6ddb39325d031d1bdc0d9f7b
MD5 144f752e1a1dfc5d7cf5fdfd78f36640
BLAKE2b-256 f87a3e2205d6ae2eb301d96bf6ae0c227828fd48194048a66ea061741b5f3bc3

See more details on using hashes here.

Provenance

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