This repository contains Python scripts to fetch logs from Elasticsearch and Loki (Graphana Loki) in a convenient, interactive way.
es_log_fetcher.py: Interactively fetch logs from an Elasticsearch cluster. Supports searching by namespace, date range, and pod name keyword. It mimics the behavior of Loki's log retrieval but for ES indices.loki_log_fetcher.py: Interactively fetch logs from a Loki instance using LogQL. Supports namespace selection, date ranges (local or UTC), app keyword filtering, and container selection.
- Python 3.x
requestslibrary
-
Clone this repository:
git clone https://github.com/cracya01/log-fetcher-tools.git cd log-fetcher-tools -
Install dependencies:
pip install requests
Before running the scripts, you MUST update the configuration variables at the top of each script to match your environment.
Open the file and edit the following lines:
# 1. Configuration - PLEASE UPDATE THESE
es_host = "https://your-es-host.com" # Replace with your ES URL
auth = ("your_username", "your_password") # Replace with your ES credentialsOpen the file and edit the following lines:
# Configuration - PLEASE UPDATE THIS
url = "http://your-loki-host:3100" # Replace with your Loki URLRun the script:
python es_log_fetcher.pyFollow the interactive prompts:
- Namespace: Enter the Kubernetes namespace (e.g.,
dev). - Date: Enter a single date (
2025.12.01) or a range (2025.12.01-2025.12.03). - App Name Keyword: Enter a keyword to search for specific pods (e.g.,
api). - Log Count: Enter the number of logs to retrieve or
all. - Output: Choose to print to console or save to a file.
Run the script:
python loki_log_fetcher.pyFollow the interactive prompts:
- Namespace: Enter the Kubernetes namespace.
- Date: Enter date or range. You can also successfully choose between Local Time and UTC.
- App Name Keyword: Filter pods by name.
- Select Pods: Choose specific pods from the list.
- Select Containers: Choose specific containers.
- Log Count & Output: Similar to the ES fetcher.
MIT