Current File : //usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/foreman.cpython-312.pyc
�

-�_g�;���ddlmZddlmZddlmZmZmZmZm	Z	Gd�de�Z
Gd�de
e�ZGd�d	e
ee�Zy
)�)�match)�quote)�Plugin�RedHatPlugin�DebianPlugin�UbuntuPlugin�	PluginOptc��eZdZdZdZdZdZdZdZdZ	dZ
d	diZed
dd�
�eddd�
�eddd�
�gZ
dZd�Zd�Zd�Zdd�Zd�Zy)�Foremanz$Foreman/Satellite systems management�foremani)�sysmgmt)rN�	localhost��
PGPASSWORD�days�z!number of days for dynflow output)�default�desc�
proxyfeaturesFz!collect features of smart proxies�puma-gczcollect Puma GC statsz/pumactl %s -S /usr/share/foreman/tmp/puma.statec��d}	d}t|dd��5}|j�j�}ddd�D]�}|r|ddk(r�|jd�rd	}�"|r$t	d
|�r|j�d|_|r$t	d|�r|j�d|_|jd
�r��d}��	|jjd�r|jjd�s6|jjd�r/|jjd�r|jdd|_d|ji|_
|jddddd��|jddg�|jd�d}|j�}|jd�d}|j�}|jdd|j �d�gd��|jd d!d"d#d$d%d&d'd(d)d*d+d,d-d|j �d.�d|j �d/�d|j �d0�d1|j �d2�d1|j �d3�d|j �d4�g�|j#d5d6d7d8d9d:|��d:|��d;g�|j%d<d=gd	�>�|j#d?d@�A�|j#dBdCdD�E�|j#dFdG�A�|j'dHdI�A�|j)dJ�K�|j+dL�r |j#|j,dMzdN�A�|j#|j,dOzdP�A�|j#dQ�|j/dR�}|j#|dS|j�T�|j1�|j3�y#1swY��vxYw#t$rY���wxYw)UNFz/etc/foreman/database.yml�rzUTF-8)�encodingr�#zproduction:Tz\s+host:\s+\S+�z\s+password:\s+\S+� �"�'���r�foreman_production_log�foreman_tasks_config�foreman_ssl_access_ssl_log)z!/var/log/foreman/production.log.*z/etc/sysconfig/foreman-tasks�/etc/sysconfig/dynflowdz)/var/log/httpd/foreman-ssl_access_ssl.logz/etc/foreman/*key.pemz/etc/foreman/encryption_key.rb�hostname�outputzhostname -fz/var/log/foreman/production.logz	/var/log/z*/foreman-ssl_*_ssl.logi�)�	sizelimitz
/etc/foreman/z/etc/sysconfig/foremanr#z/etc/default/foremanz&/var/log/foreman/dynflow_executor*log*z*/var/log/foreman/dynflow_executor*.output*z#/var/log/foreman/apipie_cache*.log*z/var/log/foreman/cron*.log*z /var/log/foreman/db_migrate*log*z/var/log/foreman/db_seed*log*z$/var/log/foreman/production.log[.-]*z$/var/log/foreman-selinux-install.logz&/var/log/foreman-proxy-certs-generate*z/usr/share/foreman/Gemfile*z
*/foreman*z&*/katello-reverse-proxy_error_ssl.log*z*/error_log*z/etc/z*/conf/z	*/conf.d/z'*/katello-reverse-proxy_access_ssl.log*zforeman-selinux-relabel -nvzpassenger-status --show poolz passenger-status --show requestsz"passenger-status --show backtraceszpassenger-memory-statsz
ping -c1 -W1 zping -c1 -W1 localhostz/root/ssl-buildz/usr/share/foreman/config/hooks)�	recursivez�qpid-stat -b amqps://localhost:5671 -q                     --ssl-certificate=/etc/pki/katello/qpid_router_client.crt                     --ssl-key=/etc/pki/katello/qpid_router_client.key                     --sasl-mechanism=ANONYMOUSzqpid-stat_-q)�suggest_filenamezhammer ping�hammer_ping�x)�tags�timeoutzsystemctl list-units dynflow*�
dynflow_unitsz!"system-dynflow\x2dsidekiq.slice"�dynflow_sidekiq_statuszdynflow-sidekiq@*)�unitsrzgc-statszpumactl_gc-stats�stats�
pumactl_statsz/usr/sbin/foreman-puma-statusa[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�foreman_db_tables_sizes)r(�env)�open�read�
splitlines�
startswithr�split�dbhost�dbpasswd�IOError�endswithr3�
add_file_tags�add_forbidden_path�exec_cmd�strip�
add_copy_spec�	apachepkg�add_cmd_output�add_dir_listing�add_service_status�add_journal�
get_option�pumactl�build_query_cmd�collect_foreman_db�collect_proxies)	�self�production_scope�
foreman_db�dfile�
foreman_lines�line�	_hostname�_host_f�_cmds	         �</usr/lib/python3/dist-packages/sos/report/plugins/foreman.py�setupz
Foreman.setup(s,��
!��	�4�J��j�#��8�
:�E� %�
�
�� 7� 7� 9�
�
:�%�

-���t�A�w�#�~���?�?�=�1�'+�$��#��.?��(F�"&�*�*�,�q�/�D�K�#��.C�T�(J�$(�J�J�L��O�D�M����s�+�',�$�

-�$
�M�M�$�$�S�)�d�m�m�.D�.D�S�.I��M�M�$�$�T�*�t�}�}�/E�/E�d�/K� �M�M�!�B�/�D�M�!�$�-�-�0������1I�,B�'=�,�
�	�	
���#�,�!
�	�
�M�M�*�-�h�7�	��O�O�%�	��-�-�
�.�x�8���-�-�/�����-�����'�'>�?�
��	�	�	
����$�%�"�4�8�1�)�.�+�2�2�4�)�����'�z�2�����'�'M�N�����'�|�4��D�N�N�#�7�+��D�N�N�#�9�-�����'�'N�O�)
�	�.	
���)�*�.�0�$��I�;�'��G�9�%�$�	
�		�	
����-�
��	�	�
	
���
0�,�	�	
�	
���M�
�s��K�	
���;�-<�	�	>���� D�1I�	 �	K����2��3��?�?�9�%�������z� 9�1C�
 �
E����D�L�L�7�2�-<�	�	>����;�<��#�#�
�
��	
���D�3L� $���	�	*����!�����S
:�
:�� �	��	�s.�N4�N'�B	N4�=N4�'N1�,N4�4	O�Oc	��|jd��d�}t|�}d}d|�d�}d|�d�}d|�d�}d	|�d�}d
}|ddd
dd|dd�}	||||d�}
|	j�D]6\}}|j|�}
|j	|
|dd|j
���8|j
d�}|
j�D]D\}}d}|dk7r|rd}|j|d|��}
|j	|
|dd|j
���Fy)z% Collect foreman db and dynflow data rz dayszRselect id,name,value from settings where name not similar to '%(pass|key|secret)%'zFselect * from foreman_tasks_tasks where started_at > NOW() - interval z order by started_at ascz�select dynflow_execution_plans.* from foreman_tasks_tasks join dynflow_execution_plans on (foreman_tasks_tasks.external_id = dynflow_execution_plans.uuid::varchar) where foreman_tasks_tasks.started_at > NOW() - interval z, order by foreman_tasks_tasks.started_at ascz�select dynflow_actions.* from foreman_tasks_tasks join dynflow_actions on (foreman_tasks_tasks.external_id = dynflow_actions.execution_plan_uuid::varchar) where foreman_tasks_tasks.started_at > NOW() - interval z�select dynflow_steps.* from foreman_tasks_tasks join dynflow_steps on (foreman_tasks_tasks.external_id = dynflow_steps.execution_plan_uuid::varchar) where foreman_tasks_tasks.started_at > NOW() - interval z�WITH prefix_counts AS (SELECT split_part(name,'::',1) FROM fact_names) SELECT COUNT(*), split_part AS "fact_name_prefix" FROM prefix_counts GROUP BY split_part ORDER BY count DESC LIMIT 100zselect * from schema_migrationsz`select id,type,name,host,port,account,base_dn,attr_login,onthefly_register,tls from auth_sourcesz!select * from dynflow_schema_infozselect count(*) from auditszselect count(*) from logsz2select name,url,download_policy from smart_proxies)�foreman_settings_table�foreman_schema_migrations�foreman_auth_table�dynflow_schema_info�audits_table_count�logs_table_count�fact_names_prefixes�
smart_proxies)�foreman_tasks_tasks�dynflow_execution_plans�dynflow_actions�
dynflow_stepsiX�d)r(r,r&r3z
dynflow-utils�psqlr`z /usr/libexec/psql-msgpack-decodeT)�csv�binaryN)rGr�itemsrIrCr3�is_installed)rLr�interval�scmd�dtaskcmd�dyncmd�
dactioncmd�	dstepscmd�factnamescmd�	foremandb�
foremancsv�table�valrT�dynutils�dynrgs                 rUrJzForeman.collect_foreman_db�s����/�/�&�)�*�%�0����;��
$�	
�
(�(0�z�1I�K��
-�.6�J�71�
1�	�B�CK��L;�;�	�
A�BJ�
�K:�
:�	�
�	�'+�)J�#6�$G�"?� ;�#/�2�
�	�"$,�'-�)�&�	
�
�$�/�/�+�	=�J�E�3��'�'��,�D�����u�c�*-�4�8�8�
 �
=�	=��$�$�_�5��"�(�(�*�	=�H�C���F��+�+��;���'�'���f�'�E�D�����s�C�*-�4�8�8�
 �
=�	=�c�V�|jd�r�|jdd��}|j||j��}|ddk(rM|dj	�d	d
D]4}|jd�}d|d	�d
�}|j
||ddd���6|jgd��y
)z Collect foreman proxies rz"select name,url from smart_proxiesT)rf)r3�statusrr%rN�,zNcurl -s --key /etc/foreman/client_key.pem --cert /etc/foreman/client_cert.pem z/v2/features�smart_proxies_features�
)r(�subdirr,)�
HTTP_PROXY�HTTPS_PROXY�NO_PROXY�	ALL_PROXY)rGrIr?r3r6r8rC�add_env_var)rLrT�proxies�proxys    rUrKzForeman.collect_proxiess����?�?�?�+��'�'�(L�,0�(�2�D��m�m�D�d�h�h�m�7�G��x� �A�%�$�X�.�9�9�;�A�B�?�4�E�!�K�K��,�E�B�#�A�h�Z�|�5�D��'�'��u�Q�x�/G�02�(�4�
4�	
���
�	rwc�L�|rd|�d�}d}|||jt|�fzS)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
        zCOPY (z6) TO STDOUT WITH (FORMAT 'csv', DELIMITER ',', HEADER)z:%s --no-password -h %s -p 5432 -U foreman -d foreman -c %s)r9r)rL�queryrfrg�_dbcmds     rUrIzForeman.build_query_cmd2s;����U�G�$A�A�E�M�������e�E�l�;�;�;rwc��|jddd�|jddd�|jdg�|jddd	�y)
Nz/etc/foreman/(.*)((conf)(.*)?)z5((\:|\s*)(passw|cred|token|secret|key).*(\:\s|=))(.*)z
\1********z"/etc/foreman/(.*)((yaml|yml)(.*)?)z\1"********"z /var/log/foreman/production.log*zfrom settings wherez(http(s)?://)\S+:\S+(@.*)z\1******:******\3)�do_path_regex_sub�do_paths_http_sub�do_cmd_output_sub)rLs rU�postproczForeman.postproc@sc�����-�D��	�
	
���1�D��	�
	
���.� 
�	�	
���!�(� �	"rw)Fre)�__name__�
__module__�__qualname__�
short_desc�plugin_name�plugin_timeout�profiles�packagesrBr9r:r3r	�option_listrHrVrJrKrIr��rwrUrrs���7�J��K��N��H��H��I�
�F��H���
�C��&�"�:�	<��/�5�:�	<��)�U�.�	0��K�@�G�Q�fY=�v�8<�"rwrc�"��eZdZdZ�fd�Z�xZS)�
RedHatForeman�httpdc�j��|jddi�t�|�	�|jd�y)Nz"/usr/share/foreman/.ssh/ssh_config�ssh_foreman_configzgem list)r=�superrVrC)rL�	__class__s �rUrVzRedHatForeman.setup\s5������0�2F�
�	�	��
�����J�'rw)r�r�r�rBrV�
__classcell__)r�s@rUr�r�Xs����I�(�(rwr�c��eZdZdZy)�
DebianForeman�apache2N)r�r�r�rBr�rwrUr�r�fs���Irwr�N)
�rer�shlexr�sos.report.pluginsrrrrr	rr�r�r�rwrU�<module>r�sD����9�9�@"�f�@"�L
(�G�\�(��G�\�<�rw