o
    O6ufX  ã                   @   s>   d dl mZ d dlmZ d dlmZmZ G dd„ deeƒZdS )é    )Úmatch)Úquote)ÚPluginÚRedHatPluginc                   @   s>   e Zd ZdZdZdZdZdZdZdd„ Z	ddd	„Z
d
d„ ZdS )Ú	Candlepinz Candlepin entitlement managementÚ	candlepin)r   Nc              	   C   sV  d| _ d| _d}zUt|ddd��}| ¡  ¡ }W d   ƒ n1 s!w   Y  |D ]3}|r2|d dkr3q(td	|ƒrN| d
¡d | _ | j  d¡d  d¡d | _ td|ƒr[| d
¡d | _q(W n ttfyh   Y nw |  	ddddœ¡ d| ji| _
| jddgdd� |  g d¢¡ |  d¡ |  d¡}| j|d| j
d� |  d¡}| j|d| j
d� d S )NÚ	localhostÚ ú/etc/candlepin/candlepin.confÚrzUTF--8)Úencodingr   ú#z&^\s*org.quartz.dataSource.myDS.URL=\S+ú=é   ú/é   ú:z+^\s*org.quartz.dataSource.myDS.password=\S+Úcandlepin_logÚcandlepin_error_logÚcandlepin_conf)z"/var/log/candlepin/candlepin.log.*z/var/log/candlepin/err.log.*r
   Ú
PGPASSWORDz/var/log/candlepin/error.logz /var/log/candlepin/candlepin.log)Ú	sizelimit)r
   ú/etc/candlepin/broker.xmlz/var/log/candlepin/audit*.log*z%/var/log/candlepin/candlepin.log[.-]*z/var/log/candlepin/cpdb*.log*z/var/log/candlepin/cpinit*.log*z!/var/log/candlepin/error.log[.-]*z/var/log/tomcat*/catalina*log*z"/var/log/tomcat*/host-manager*log*z/var/log/tomcat*/localhost*log*z/var/log/tomcat*/manager*log*zdu -sh /var/lib/candlepin/*/*a[  SELECT table_name, pg_size_pretty(total_bytes) AS total, pg_size_pretty(index_bytes) AS INDEX , pg_size_pretty(toast_bytes) AS toast, pg_size_pretty(table_bytes) AS TABLE FROM ( SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME, c.reltuples AS row_estimate, pg_total_relation_size(c.oid) AS total_bytes, pg_indexes_size(c.oid) AS index_bytes, pg_total_relation_size(reltoastrelid) AS toast_bytes FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE relkind = 'r') a) a order by total_bytes DESCÚcandlepin_db_tables_sizes)Úsuggest_filenameÚenvzN            SELECT displayname, content_access_mode             FROM cp_owner;Úsimple_content_access)ÚdbhostÚdbpasswdÚopenÚreadÚ
splitlinesr   ÚsplitÚIOErrorÚ
IndexErrorÚadd_file_tagsr   Úadd_copy_specÚadd_cmd_outputÚbuild_query_cmd)ÚselfÚcfg_fileÚcfileÚcandle_linesÚlineÚ_cmd© r/   ú>/usr/lib/python3/dist-packages/sos/report/plugins/candlepin.pyÚsetup   sZ   ÿ

€öþý	þý
ÿÿ

þzCandlepin.setupFc                 C   s$   |rdnd}d}|| j |t|ƒf S )aI  
        Builds the command needed to invoke the pgsql query as the postgres
        user.
        The query requires significant quoting work to satisfy both the
        shell and postgres parsing requirements. Note that this will generate
        a large amount of quoting in sos logs referencing the command being run
        z
-A -F , -Xr	   zUpsql --no-password -h %s -p 5432 -U candlepin                   -d candlepin %s -c %s)r   r   )r)   ÚqueryÚcsvÚ	csvformatÚ_dbcmdr/   r/   r0   r(   t   s   zCandlepin.build_query_cmdc                 C   sL   d}d}|   d||¡ d}|   d||¡ dD ]}|   dd|› d	�d
¡ qd S )Nz$(((.*)(pass|token|secret)(.*))=)(.*)z
\1********r
   z(--password=)([a-zA-Z0-9]*)z/var/log/candlepin/cpdb.log)ÚtrustStorePasswordÚkeyStorePasswordr   ú(z)=(\w*)([;<])z\1=********\3)Údo_file_sub)r)   ÚregÚreplÚcpdbregÚkeyr/   r/   r0   Úpostproc�   s   
þÿzCandlepin.postproc)F)Ú__name__Ú
__module__Ú__qualname__Ú
short_descÚplugin_nameÚpackagesr   r   r   r1   r(   r>   r/   r/   r/   r0   r      s    
Yr   N)Úrer   Úshlexr   Úsos.report.pluginsr   r   r   r/   r/   r/   r0   Ú<module>   s   
