3 'jm @ s^ d dl mZ d dlmZmZmZ d dlmZmZmZ d dl m Z mZmZ G dd de eZ dS ) )Optional)datetime timedeltatimezone)JSONDecodeErrordumpsloads)PluginIndependentPlugin PluginOptc @ s e Zd ZdZdZdZd&ZdZdZd'Z e ddd d e dddd e d ddd e ddedde ddeddgZe e e e dddZe e e e dddZdd Zdd Zdd Zd!d" Zd#d$ Zd%S )(Lokia Collects logs and configuration from Loki. This plugin interacts with the Loki API to fetch logs based on specified labels and provides options for pagination and label detection. It also collects relevant configuration files and masks sensitive information. It works with both charmed and non-charmed Loki. To fetch internal Loki logs, run it from the Loki container. You can also run it from another machine and fetch only logs from Loki API, by providing the following parameters: `-k loki.collect-logs=true -k loki.endpoint=LOKI_URL` Usage: sos report -o loki -k loki.collect-logs=true -k loki.labels=severity:charm -k loki.detect-labels=true -k loki.paginate=true -k loki.endpoint=LOKI_URL zLoki servicelokiservicesi d zcollect-logsFzcollect logs from Loki API)defaultdescz detect-labelszTfetch logs for all available labels. May result in multiple files with the same logspaginatez'fetch all available logs from Loki API.labels z1colon-delimited list of labels to fetch logs from)r Zval_typer endpointzhttp://localhost:3100zDloki endpoint to fetch logs from. Defaults to http://localhost:3100.)startendc C s` |st jtj}|s"|tdd }|jd}|jd}d| d| d| d| dtj d }|S ) N )Zdaysz%Y-%m-%dT%H:%M:%S.%fZzcurl -G -s 'z3/loki/api/v1/query_range' --data-urlencode 'query={z!=~".+"}' --data-urlencode 'start=z' --data-urlencode 'end=z' --data-urlencode 'limit=z' )r nowr Zutcr Zstrftimer LOKI_QUERY_LIMIT)selfr labelr r Zstart_formattedZ end_formattedZcommand r /usr/lib/python3.6/loki.py query_command<