403Webshell
Server IP : 167.99.254.82  /  Your IP : 216.73.216.188
Web Server : Apache
System : Linux host.techisquad.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64
User : pawluxera ( 1011)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/loki.cpython-310.pyc
o

G%@iT�@s^ddlmZddlmZmZmZddlmZmZmZddl	m
Z
mZmZGdd�de
e�Z
dS)�)�Optional)�datetime�	timedelta�timezone)�JSONDecodeError�dumps�loads)�Plugin�IndependentPlugin�	PluginOptc
@s�eZdZdZdZdZdZdZdZdZ	e
dd	d
d�e
dd	d
d�e
dd	dd�e
ddedd�e
ddedd�gZde
ede
efdd�Zde
ede
efdd�Zdd�Zdd �Zd!d"�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
    zLoki service�loki)�servicesi��d)r
�collect-logsFzcollect logs from Loki API)�default�desc�
detect-labelszTfetch logs for all available labels. May result in multiple files with the same logs�paginatez'fetch all available logs from Loki API.�labels�z1colon-delimited list of labels to fetch logs from)r�val_typer�endpoint�http://localhost:3100zDloki endpoint to fetch logs from. Defaults to http://localhost:3100.�start�endcCs`|st�tj�}|s|tdd�}|�d�}|�d�}d|�d|�d|�d|�dtj�d	�}|S)
N�)�daysz%Y-%m-%dT%H:%M:%S.%fZ�curl -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�utcr�strftimer�LOKI_QUERY_LIMIT)�selfr�labelrr�start_formatted�
end_formatted�command�r(�9/usr/lib/python3/dist-packages/sos/report/plugins/loki.py�
query_command<s"

�����zLoki.query_commandcCsR|�|�||||��}zt|d�WSty(|�d|�d��|dYSw)N�outputz-An error was returned from Loki API on label z-. Error message stored, not querying further.)�exec_cmdr*rr�	_log_warn)r#rr$rrr+r(r(r)�get_logsOs
��z
Loki.get_logscCsR|dd}tt����d�}|D]}|dD]
}t|d�}t||�}qq|S)N�data�result�ʚ;�valuesr)�intrr�	timestamp�min)r#�logs�log_streams�earliest_log�stream�logr4r(r(r)�get_earliest_log_timestamp[s�zLoki.get_earliest_log_timestampcCsF|�||dd�}|�|�d���}|�t|dd��Wd�n1s$wYt|t�r0dS|r�|�|�}tt�	��
�d�}d}|tjkr�||kr�t�
|d�}	|�||d|	�}
|�|�d|����}|�t|
dd��Wd�n1sywYt|
t�r�dS|}|�|
�}|d7}|tjkr�||ksLdSdSdSdSdS)Nz.log�)�indentr1rz.log.r)r.�collection_file�writer�
isinstance�strr;r3rrr4r�MAX_PAGINATION_ITERATIONS�
fromtimestamp)r#rr$rr6�logfiler8�previous_earliest_log�iterations_count�
log_timestamp�new_logsr(r(r)�get_logs_for_labelesD�

�
��
�
���zLoki.get_logs_for_labelcCs�|�d�}|�|�|�d�}|�|�|�d�|�d�|�d�rb|�d�p)d}g|_|�d�}rDt|t�rD|rD|j�|�d	��|�d
�rd|�	d|�d��}t
|d
�}|j�|d�dSdSdS)Nz/etc/loki/*.yamlz/etc/worker/*.yamlz/var/log/loki/*zpebble logs loki -n 10000rrrr�:rrz/loki/api/v1/labels'r+r/)�	path_join�
add_copy_spec�add_cmd_output�
get_optionrr@rA�extend�split�collect_cmd_outputr)r#�els_config_file�coordinated_workers_config_filer�
labels_option�
labels_cmd�labels_jsonr(r(r)�setup�s(








��z
Loki.setupcCs6|�d�pd}|jD]}|�d�}|�|||�q
dS)Nrrr)rNrrI)r#rr$rr(r(r)�collect�s


�zLoki.collectcCs^ddg}gd�}dd�|��d�}dd�|��d�}|D]}|�||d�|�||d�qdS)	N�
access_key_id�secret_access_key)z /etc/loki/loki-local-config.yamlz/etc/loki/config.yamlz/etc/loki/local-config.yamlz/etc/loki/loki.yamlz/etc/worker/config.yaml�(�|z)\s*(:|=)(\S*\n.*?\\n)z)\s*(:|=)\s*[a-zA-Z0-9]*z
\1\2*********)�join�do_file_sub)r#�protect_keys�
loki_files�match_exp_multil�	match_exp�filer(r(r)�postproc�s ����z
Loki.postprocN)�__name__�
__module__�__qualname__�__doc__�
short_desc�plugin_name�profilesr"rB�packagesrrA�option_listrrr*r.r;rIrWrXrdr(r(r(r)rsF������

�

�
rN)�typingrrrr�jsonrrr�sos.report.pluginsr	r
rrr(r(r(r)�<module>s


Youez - 2016 - github.com/yon3zu
LinuXploit