File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/report.zip
Back
PK ;;�Z3�:[5 5 reporting.pynu �[��� # Copyright (C) 2014 Red Hat, Inc., # Bryn M. Reeves <bmr@redhat.com> # # This file is part of the sos project: https://github.com/sosreport/sos # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # version 2 of the GNU General Public License. # # See the LICENSE file in the source distribution for further information. """ This provides a restricted tag language to define the sos report index/report """ try: import json except ImportError: import simplejson as json class Node: data = {} def __str__(self): return json.dumps(self.data) # pylint: disable=unused-argument def can_add(self, node): return False class Leaf(Node): """Marker class that can be added to a Section node""" class Report(Node): """The root element of a report. This is a container for sections.""" def __init__(self): self.data = {} def can_add(self, node): return isinstance(node, Section) def add(self, *nodes): for node in nodes: if self.can_add(node): self.data[node.name] = node.data def _decode(s): """returns a string text for a given unicode/str input""" return (s if isinstance(s, str) else s.decode('utf8', 'ignore')) class Section(Node): """A section is a container for leaf elements. Sections may be nested inside of Report objects only.""" def __init__(self, name): self.name = _decode(name) self.data = {} def can_add(self, node): return isinstance(node, Leaf) def add(self, *nodes): for node in nodes: if self.can_add(node): self.data.setdefault(node.ADDS_TO, []).append(node.data) class Command(Leaf): ADDS_TO = "commands" def __init__(self, name, return_code, href): self.data = {"name": _decode(name), "return_code": return_code, "href": _decode(href)} class CopiedFile(Leaf): ADDS_TO = "copied_files" def __init__(self, name, href): self.data = {"name": _decode(name), "href": _decode(href)} class CreatedFile(Leaf): ADDS_TO = "created_files" def __init__(self, name, href): self.data = {"name": _decode(name), "href": _decode(href)} class Alert(Leaf): ADDS_TO = "alerts" def __init__(self, content): self.data = _decode(content) class Note(Leaf): ADDS_TO = "notes" def __init__(self, content): self.data = _decode(content) def ends_bs(string): """ Return True if 'string' ends with a backslash, and False otherwise. Define this as a named function for no other reason than that pep8 now forbids binding of a lambda expression to a name: 'E731 do not assign a lambda expression, use a def' """ return string.endswith('\\') class PlainTextReport: """Will generate a plain text report from a top_level Report object""" HEADER = "" FOOTER = "" LEAF = " * %(name)s" ALERT = " ! %s" NOTE = " * %s" PLUGLISTHEADER = "Loaded Plugins:" PLUGLISTITEM = " {name}" PLUGLISTSEP = "\n" PLUGLISTMAXITEMS = 5 PLUGLISTFOOTER = "" PLUGINFORMAT = "{name}" PLUGDIVIDER = "=" * 72 subsections = ( (Command, LEAF, "- commands executed:", ""), (CopiedFile, LEAF, "- files copied:", ""), (CreatedFile, LEAF, "- files created:", ""), (Alert, ALERT, "- alerts:", ""), (Note, NOTE, "- notes:", ""), ) line_buf = [] def __init__(self, report_node): self.report_data = sorted(dict.items(report_node.data)) def unicode(self): self.line_buf = line_buf = [] if len(self.HEADER) > 0: line_buf.append(self.HEADER) # generate section/plugin list, split long list to multiple lines line_buf.append(self.PLUGLISTHEADER) line = "" i = 0 plugcount = len(self.report_data) for section_name, _ in self.report_data: line += f" {section_name}" i += 1 if (i % self.PLUGLISTMAXITEMS == 0) and (i < plugcount): line += self.PLUGLISTSEP line += self.PLUGLISTFOOTER line_buf.append(line) for section_name, section_contents in self.report_data: line_buf.append(self.PLUGDIVIDER) line_buf.append(f"{section_name}") for type_, format_, header, footer in self.subsections: self.process_subsection(section_contents, type_.ADDS_TO, header, format_, footer) if len(self.FOOTER) > 0: line_buf.append(self.FOOTER) output = '\n'.join(map(lambda i: (i if isinstance(i, str) else i.decode('utf8', 'ignore')), line_buf)) return output def process_subsection(self, section, key, header, format_, footer): if key in section: self.line_buf.append(header) for item in sorted( section.get(key), key=lambda x: x["name"] if isinstance(x, dict) else '' ): self.line_buf.append(format_ % item) if len(footer) > 0: self.line_buf.append(footer) class HTMLReport(PlainTextReport): """Will generate a HTML report from a top_level Report object""" HEADER = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Sos System Report</title> <style type="text/css"> td { padding: 0 5px; } </style> </head> <body>\n""" FOOTER = "</body></html>" LEAF = '<li><a href="%(href)s">%(name)s</a></li>' ALERT = "<li>%s</li>" NOTE = "<li>%s</li>" PLUGLISTHEADER = "<h3>Loaded Plugins:</h3><table><tr>" PLUGLISTITEM = '<td><a href="#{name}">{name}</a></td>\n' PLUGLISTSEP = "</tr>\n<tr>" PLUGLISTMAXITEMS = 5 PLUGLISTFOOTER = "</tr></table>" PLUGINFORMAT = '<h2 id="{name}">Plugin <em>{name}</em></h2>' PLUGDIVIDER = "<hr/>\n" subsections = ( (Command, LEAF, "<p>Commands executed:</p><ul>", "</ul>"), (CopiedFile, LEAF, "<p>Files copied:</p><ul>", "</ul>"), (CreatedFile, LEAF, "<p>Files created:</p><ul>", "</ul>"), (Alert, ALERT, "<p>Alerts:</p><ul>", "</ul>"), (Note, NOTE, "<p>Notes:</p><ul>", "</ul>"), ) class JSONReport(PlainTextReport): """Will generate a JSON report from a top_level Report object""" def unicode(self): output = json.dumps(self.report_data, indent=4, ensure_ascii=False) return output # vim: set et ts=4 sw=4 : PK ;;�Z�o�� � $ __pycache__/__init__.cpython-310.pycnu �[��� o -�_g�: � @ s> d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dl m Z d dl mZ d dl mZ d dlZd dlmZmZmZmZmZmZmZ d dlmZ d dlmZ d d lmZ d dlZd d lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ ej,ej-fZ.ddd�Z/dd� Z0g d�Z1G dd� de�Z2dS )� N)�datetime)�ThreadPoolExecutor)�TimeoutError)�rmtree)�ImporterHelper�SoSTimeoutError�bold�sos_get_command_output�TIMEOUT_DEFAULT�listdir� is_executable)�_sos)�__version__)�SoSComponent) �Report�Section�Command� CopiedFile�CreatedFile�Alert�Note�PlainTextReport� JSONReport� HTMLReport)� SoSCleanerF�, c C s� g }| }|r t | �d }nd}|D ]}t |�t |� t |� dkr(|�|� |}|| | }q|t |� d � |krC|d t |� � }|�|� |S )N� � �H )�len�append)� first_line�items�indent�sep�lines�line�newline�item� r) �5/usr/lib/python3/dist-packages/sos/report/__init__.py�_format_list- s r+ c C s t �| d�d�S )z� This function will format --since arg to append 0s if enduser didn't. It's used in the _get_parser. This will also be a good place to add human readable and relative date parsing (like '2 days ago') in the future z<014sz%Y%m%d%H%M%S)r �strptime)�dater) r) r* � _format_since? s r. )�auto�always�neverc s� e Zd ZdZdZdZi dd�dd�dd�dd �d d�dd�d d�dd�dd �dg �dg �dg �dd�dd�dd�dg �dd�i dg �dd�dg �dd �dd�dd�d d�d!d"�d#d�d$d%�d&g �d'g �d(g �d)d�d*d�d+d�d,d��i d-d�d.d �d/g �d0d�d1e�d2e�d3g �d4d�d5d�d6d�d7g �d8d�d9d�d:d�d;d�d<d�d=d��ddddddddd d d>� �Z� fd?d@�Ze dAdB� �Z e dCdD� �ZdEdF� ZdGdH� Z dIdJ� ZdKdL� ZdMdN� ZdOdP� ZdQdR� ZdSdT� ZdUdV� Zd�dWdX�ZdYdZ� Zd[d\� Zd]d^� Zd_d`� Zdadb� Zdcdd� Zdedf� Zdgdh� Zedidj� �Zd�dkdl�Z dmdn� Z!dodp� Z"dqdr� Z#dsdt� Z$dudv� Z%dwdx� Z&d�dzd{�Z'd|d}� Z(d~d� Z)d�d�� Z*d�d�� Z+d�d�� Z,d�d�� Z-d�d�� Z.d�d�� Z/d�d�� Z0d�d�� Z1d�d�� Z2d�d�d��Z3d�d�� Z4d�d�� Z5d�d�� Z6d�d�� Z7d�d�� Z8d�d�� Z9d�d�� Z:d�d�� Z;d�d�� Z<d�d�� Z=d�d�� Z>d�d�� Z?d�d�� Z@d�d�� ZAd�d�� ZBd�d�� ZCd�d�� ZDd�d�� ZEd�d�� ZFd�d�� ZGd�d�� ZH� ZIS )�� SoSReportzaRun a set of commands and file collections and save them to a report for future analysis z.Collect files and command output in an archiveT� alloptionsF�all_logs�build�case_idr �chrootr/ �clean�container_runtime�keep_binary_files�desc�domains�disable_parsers�skip_cleaning_files�dry_run� estimate_only�experimental�enable_plugins�journal_size�d �keywords�keyword_fileN�plugopts�label�list_plugins�list_presets� list_profiles�log_size� �low_priority�map_file� /etc/sos/cleaner/default_mapping� skip_commands� skip_files�skip_plugins� namespaces� no_report�no_env_vars�no_postproc� no_update�note�only_plugins�preset�plugin_timeout�cmd_timeout�profiles�since�verify�allow_system_changes� usernames�upload� upload_url�upload_directory�upload_user�upload_pass� upload_method) �upload_no_ssl_verify�upload_protocol�upload_s3_endpoint�upload_s3_region�upload_s3_bucket�upload_s3_access_key�upload_s3_secret_key�upload_s3_object_prefix� add_preset� del_presetc s t � �|||� g | _g | _g | _t� | _|| _d| _i | _ | � � | �� | j� � | _| jj�d�| _| �� d}| jj| _| jjrFd}n | j�� rS| jtjkrSd}| j�d| j� d|� d�� | jjtvr�| j�d | jj� �� t�� | j� � | �!d � | �"� | �#� | �$� d S )N�/�report�default�cmdline�policyzset sysroot to 'z' (�)zinvalid chroot mode: � )%�super�__init__�loaded_plugins�skipped_plugins�all_options�set�env_vars�_args�sysroot�estimated_plugsizes�print_header� _set_debugrw �is_root�_is_root�manifest� components�add_section� report_md�_set_directories�opts�in_container�osr$ �soslog�debugr7 �chroot_modes�error�logging�shutdown� tempfile_utilr8 �_exit�_check_container_runtime�_get_namespaces�_get_hardware_devices)�self�parser�argsrv �msg�� __class__r) r* r{ � s8 zSoSReport.__init__c C s� |� dd�}|jddddddd � |jd ddddd � |jd ddd tdd� |jdddddd � |jddddd� |jddddddd � |jdddd � |jd!d"tdd#d$d%� |jd&dd'd(� |jd)dd*d(� |jd+dd,dd-d � |jd.d/d0d1td2g d3� |jd4td5d6d7d8� |jd9d:d;d0d<td=g d3� |jd>d?dd@dAd� |jdBdCddDddEd � |jdFddGd(� |jdHddIddJd � |jdKddLtdMdNdO� |jdPdddQdR� |jdSd dTd � |jdUdVd0dWtdXg d3� |jdYddZdd[d � |jd\dd]dd^d � |jd_dd`ddadb� |jdctdd#ddd%� |jdedfd0dgtdhg d3� |jdidtdjddk� |jdld dmd � |jdnd dod � |jdpdqdrd0dstg dtdO� |jdug d0dvdwdx� |jdyg d0dzd{dx� |jd|dd}dd~d � |jddd�dd�d � |jd�ddd�dR� |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�dg d��d�d�� |jd�ddd�d�� |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�dg d��d�d�� |�� }|jd�tdd�d�� |jd�tdd�d�� |� d�d��}|jd�d�d�d�ddd�d�� |jd�d�g d0d�d�� |jd�d0g d�d�d�� |jd�d�d0g d�d�d�� |jd�d0g d�d�d�� |jd�d d�d�d�� |jd�ddd�d�d�� |jd�d�d�d�dȍ |jd�ddd�d�dx� |jd�d�g d0d�d�� d S )�NzReport Optionsz.These options control how report collects dataz-az--alloptions� store_truer3 Fz%enable all options for loaded plugins)�action�destru �helpz --all-logsr4 z-collect all available logs regardless of sizez--since�storer_ zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])r� r� ru �typer� z--buildr5 z;preserve the temporary directory and do not package resultsz --case-idr6 zspecify case identifier)r� r� r� z-cz--chrootr7 r/ zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)ru r� z--descz --descriptionr zDescription for a new preset)r� r� ru r� z --dry-runz#Run plugins but do not collect data)r� r� z--estimate-onlyzzApproximate disk space requirements for a real sos run; disables --clean and --collect, sets --threads=1 and --no-postprocz--experimentalrA zenable experimental pluginsz-ez--enable-plugins�extendrB zenable these plugins)r� r� r� r� ru z--journal-sizerD rC z+limit the size of collected journals in MiB)r� ru r� r� z-kz--plugin-optionz --plugoptsrG z7plugin options in plugname.option=value format (see -l)z--labelz--namerH z"specify an additional report labelz-lz--list-pluginsrI z)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrK zBdisplay a list of available profiles and plugins that they includez --log-sizerL rM z6limit the size of collected logs (not journals) in MiB)r� r� r� ru r� z--low-priorityz(generate report with low system priority)r� ru r� z--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrS zdisable these pluginsz--no-reportrU z disable plaintext/HTML reportingz --no-env-varsrV z$Do not collect environment variablesz --no-postprocrW zDisable all post-processing)ru r� r� r� z--notezBehaviour notes for new presetz-oz--only-pluginsrZ zenable these plugins onlyz--presetzA preset identifier)r� r� r� ru z--plugin-timeoutzset a timeout for all pluginsz --cmd-timeoutz%set a command timeout for all pluginsz-pz --profilez --profilesr^ z)enable plugins used by the given profilesz--skip-commandsrQ zdo not execute these commands)ru r� r� r� z--skip-filesrR zdo not collect these filesz--verifyr` z+perform data verification during collectionz--allow-system-changesra zJRun commands even if they can change the system (e.g. load kernel modules)z--uploadz+Upload archive to a policy-default locationz--upload-urlz&Upload the archive to specified serverz--upload-directoryz$Specify upload directory for archivez --upload-userz'Username to authenticate to server withz --upload-passz'Password to authenticate to server withz--upload-method)r/ �put�postz HTTP method to use for uploading)ru �choicesr� z--upload-no-ssl-verifyz'Disable SSL verification for upload url)ru r� r� z--upload-s3-endpointz#Endpoint to upload to for S3 bucketz--upload-s3-regionz!Region to upload to for S3 bucketz--upload-s3-bucketz"Name of the S3 bucket to upload toz--upload-s3-access-keyzAccess key for the S3 bucketz--upload-s3-secret-keyzSecret key for the S3 bucketz--upload-s3-object-prefixzPrefix for the S3 object/keyz--upload-protocol)r/ �https�ftp�sftp�s3z$Manually specify the upload protocol�--add-presetz#Add a new named command line preset)r� r� r� z--del-presetz$Delete the named command line presetzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz --cleanerz--maskr8 zObfuscate sensitive information)r� ru r� r� z --domainsr<