Skip to main content

A command-line tool for querying the Graylog API with rich terminal output

Project description

grapicli

PyPI version Python 3.14+ License: MIT

A command-line tool for querying the Graylog REST API, built with Typer and Rich.

Features

  • ๐Ÿ” Search logs by source host, message content, or any combination
  • ๐Ÿ• Flexible time ranges โ€” relative (last N minutes) or absolute (--since / --until)
  • ๐Ÿ“‹ Configurable result limits with --limit
  • ๐Ÿ”‘ Token-based authentication loaded automatically from a .env file
  • ๐Ÿ–ฅ๏ธ Rich terminal output โ€” results displayed in a colour-coded table

Installation

pip install grapicli

Or with Poetry:

poetry add grapicli

Configuration

Create a .env file in your working directory (or project root) with your Graylog credentials:

export GRAYLOG_URL=https://your-graylog-server
export GRAYLOG_TOKEN=your_api_token_here

Note: Never commit your .env file to version control.

Finding your API token

  1. Log in to the Graylog web interface.
  2. Go to System โ†’ Users and Teams โ†’ Edit Profile โ†’ API Tokens.
  3. Create a new token and copy the value into your .env file.

Usage

grapicli search [OPTIONS]

Options

Flag Short Type Default Description
--source -s TEXT โ€” Filter by source host or identifier
--message -m TEXT โ€” Filter by message text (Lucene substring match)
--limit -n INT 30 Maximum number of messages to return
--last -l INT 15 Return messages from the last N minutes
--since -S TEXT โ€” Start of an absolute time range
--until -U TEXT โ€” End of an absolute time range (defaults to now)

Time range

Relative (default) โ€” returns messages from the last 15 minutes:

grapicli search
grapicli search --last 60   # last hour

Absolute โ€” --since and/or --until switch to an exact range. All times are UTC.

Accepted formats: YYYY-MM-DD HH:MM:SS ยท YYYY-MM-DDTHH:MM:SS ยท YYYY-MM-DD HH:MM ยท YYYY-MM-DD

grapicli search --since "2026-04-17 08:00:00" --until "2026-04-17 09:00:00"

Examples

# Default: last 15 minutes, up to 30 messages
grapicli search

# Filter by source host
grapicli search --source myserver

# Filter by message text and increase result count
grapicli search --message "error" --limit 100

# Last hour
grapicli search --last 60

# Absolute range
grapicli search --since "2026-04-17 08:00:00" --until "2026-04-17 09:00:00"

# Combine source, message filter, and time range
grapicli search --source myserver --message "timeout" --since "2026-04-17 12:00:00"

Output

Query: source:"myserver"  Matches: 4821  Showing: 30/30
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Timestamp                โ”ƒ Source     โ”ƒ Message                            โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ 2026-04-17T10:00:01.000Z โ”‚ myserver   โ”‚ Service started successfully       โ”‚
โ”‚ 2026-04-17T10:00:02.000Z โ”‚ myserver   โ”‚ Connected to database              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Development

git clone https://github.com/mmackenna/grapicli.git
cd grapicli
poetry install --extras dev

Running tests

poetry run pytest

Coverage report is written to htmlcov/.

Building docs locally

poetry run mkdocs serve

License

MIT

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

grapicli-0.3.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

grapicli-0.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file grapicli-0.3.0.tar.gz.

File metadata

  • Download URL: grapicli-0.3.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.14.4 Linux/5.14.0-611.47.1.el9_7.x86_64

File hashes

Hashes for grapicli-0.3.0.tar.gz
Algorithm Hash digest
SHA256 77a5442286dd48a1b3b86c711c22573fcb5df35a7b64b8323e77c2fa1cc46fa2
MD5 be17663b05fc9ae0d285910075561eca
BLAKE2b-256 c97922826b3ebd347a5f396065279177ab8ccbb77e4c18e3e2acfc7adfa2dba5

See more details on using hashes here.

File details

Details for the file grapicli-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: grapicli-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.14.4 Linux/5.14.0-611.47.1.el9_7.x86_64

File hashes

Hashes for grapicli-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a07d357d04abba5f473d7ed97842a6f980b039800d0863e027b24353dac98e12
MD5 32b70d716b8ba3af9b18682e11638d2f
BLAKE2b-256 bbdc42eab25e71b0002f8c7676d5aed75fb0cbd6f7c08ab76f9eccca0b20709d

See more details on using hashes here.

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