Skip to main content

Kibana 账号密码鉴权的 ES 日志查询 + 索引运维 CLI 工具

Project description

nlog-cli

纯 Kibana 账号密码鉴权的 ES 日志查询 + 索引运维 CLI 工具。

特性

  • 只需 Kibana 账号 + 密码,无需 ES 地址、无需浏览器登录
  • 1:1 复刻 Kibana DevTools DSL,复制即用
  • 全链路能力:日志检索、索引列表、索引统计、Mapping、Settings
  • 支持时间范围、traceId、关键词检索,自动生成 ES Bool DSL
  • 输出格式:json / 单行日志 / 表格展示

项目结构

nlog-cli/
├── pyproject.toml          # 项目构建与 PyPI 发布配置
├── setup.sh                # 一键安装脚本
├── README.md
├── LICENSE
├── nlog_cli/
│   ├── __init__.py         # 版本号
│   ├── cli.py              # typer 子命令入口
│   ├── client.py           # Kibana HTTP 客户端(Basic Auth + Console Proxy)
│   ├── config.py           # ~/.nlog-cli/config.toml 配置读写
│   └── formatter.py        # json / text / table 输出格式化
└── docs/
    └── superpowers/specs/
        └── 2026-04-17-nlog-cli-design.md   # 设计文档

安装

方式一:一键安装(推荐)

git clone https://github.com/yanxiao/nlog-cli.git
cd nlog-cli
bash setup.sh

脚本会自动完成:检查 Python 环境 → 安装 CLI → 引导配置 Kibana 连接。

已配置过可跳过认证步骤:

bash setup.sh --skip-auth

方式二:远程安装(PyPI)

pip install nlog-cli

安装后需手动配置连接:

nlog config

方式三:本地源码安装

git clone https://github.com/yanxiao/nlog-cli.git
cd nlog-cli
pip install -e .
nlog config

安装完成后验证:

nlog -h

快速开始

# 配置 Kibana 连接
nlog config

# 查询日志
nlog search -i app-log-* -q "error" --time-from "now-1h"

# 按 traceId 查询
nlog search -i app-log-* -t "abc-123-def"

# 表格输出
nlog search -i app-log-* -q "timeout" -f table

# 列出索引
nlog indices "app-log-*"

# 查看索引统计
nlog stats app-log-2026.04.17

# 查看 Mapping
nlog mapping app-log-2026.04.17

# 查看 Settings
nlog settings app-log-2026.04.17

# 原生 DSL 透传
nlog dsl "GET /app-log-*/_search" --body '{"query":{"match_all":{}},"size":5}'

# 从文件读取 DSL
nlog dsl "POST /app-log-*/_search" --body-file query.json

命令列表

命令 说明
nlog config 配置 Kibana 连接信息
nlog search 日志检索
nlog indices 列出索引
nlog stats 索引统计
nlog mapping 查看 Mapping
nlog settings 查看 Settings
nlog dsl 原生 DSL 透传

每个命令都支持 -h / --help 查看详细帮助。

配置文件

配置存放在 ~/.nlog-cli/config.toml

[default]
kibana_url = "https://kibana.example.com"
username = "your-username"
password = "your-password"
space = "default"

支持多 profile:

nlog config --profile prod
nlog search -i app-log-* -q "error" --profile prod

卸载

# 卸载 CLI
pip uninstall nlog-cli

# 删除配置文件(可选)
rm -rf ~/.nlog-cli

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

nlog_cli-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

nlog_cli-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file nlog_cli-0.1.0.tar.gz.

File metadata

  • Download URL: nlog_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for nlog_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ae2841604ad49e1f15f06d27bb1c2a3bae807ae72f3725ccb5ddb4ac18c008c6
MD5 0416d35a25af8b879573cc1fee8ae9b1
BLAKE2b-256 8cf1c5e7c399165183e0ae4e015575160dfd4de4074564e13c1ced75113a4a27

See more details on using hashes here.

File details

Details for the file nlog_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nlog_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for nlog_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 269001b4bb1ecb2612e36614b9dc29f888121236eaefeeb1804612bc264d8cb9
MD5 76c3c72055e2e1d52c33dd3f5683c716
BLAKE2b-256 4a48780adb3823fcc0ca31cd7dc9bcc510c2fff943efec2a25370f01215742b3

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