
    G%@iH                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	  G d de      Z
 G d de
e      Z G d d	e
ee      Zy
)    )match)quote)PluginRedHatPluginDebianPluginUbuntuPlugin	PluginOptc                       e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
d	iZ eddd       eddd       eddd       eddd      gZdZd Zd Zd Zd ZddZd Zy)Foremanz$Foreman/Satellite systems managementforemani  )sysmgmt)r   N	localhosti8   
PGPASSWORDdays   z!number of days for dynflow output)defaultdescproxyfeaturesFz!collect features of smart proxiespuma-gczcollect Puma GC stats	cvfiltersz'collect content view filters definitionz/pumactl %s -S /usr/share/foreman/tmp/puma.statec                    d}	 d}t        |dd      5 }|j                         j                         }d d d        D ]  }|r|d   dk(  r|j                  d      rd	}"|r$t	        d
|      r|j                         d   | _        |r$t	        d|      r|j                         d   | _        |r$t	        d|      r|j                         d   | _        |j                  d      rd} 	 | j                  j                  d      r| j                  j                  d      s6| j                  j                  d      r/| j                  j                  d      r| j                  dd | _        d| j                  i| _        | j                  ddddd       | j                  ddg       | j                  d      d   }|j                         }| j                  d      d   }|j                         }| j!                  dd| j"                   dgd        | j!                  d!d"d#d$d%d&d'd(d)d*d+d,d-d.d| j"                   d/d| j"                   d0d| j"                   d1d2| j"                   d3d2| j"                   d4d| j"                   d5g       | j%                  d6d7d8d9d:d;| d;| d<g       | j'                  g d=d	>       | j%                  d?d@A       | j%                  dBdCdDE       | j%                  dFdGA       | j)                  dHdIA       | j+                  dJK       | j-                  dL      r | j%                  | j.                  dMz  dNA       | j%                  | j.                  dOz  dPA       | j%                  dQ       | j1                  dR      }| j%                  |dS| j                  T       | j3                          | j5                          | j-                  dU      r| j7                          y y # 1 sw Y   xY w# t        $ r Y  w xY w)VNFz/etc/foreman/database.ymlrzUTF-8)encodingr   #zproduction:Tz\s+host:\s+\S+   z\s+port:\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outputzhostname -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*zforeman-selinux-relabel -nvzpassenger-status --show poolz passenger-status --show requestsz"passenger-status --show backtraceszpassenger-memory-statszping -c1 -W1 zping -c1 -W1 localhost)z/root/ssl-buildz/usr/share/foreman/config/hooksz"/var/lib/foreman/red_hat_inventory)	recursivezqpid-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_filenamezhammer pinghammer_pingx   )tagstimeoutzsystemctl list-units dynflow*dynflow_unitsz!"system-dynflow\x2dsidekiq.slice"dynflow_sidekiq_statuszdynflow-sidekiq@*)unitsr   zgc-statszpumactl_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)   envr   )openread
splitlines
startswithr   splitdbhostdbportdbpasswdIOErrorendswithr4   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collect_cv_filters)	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+   sa   
 !	4Jj#8 :E %

 7 7 9:% -tAw#~??=1'+$#.?(F"&**,q/DK#.?(F"&**,q/DK#.CT(J$(JJLODMs+',$-( MM$$S)dmm.D.DS.IMM$$T*t}}/E/Ed/K MM!B/DM !$--01I,B'=,
 	 	#,!
 	
 MM*-h7	OO%	--.x8--/-''>?
  	 	 	$%"481).+224)'z2''MN'|4DNN#7+DNN#9-''NO)
 	. 	)*.0$I;'G9%$	
 		 	 
 	 	 	 	0 , 	 	
 	MsK 	;-< 	 	> D1I 	  	K23 ??9%z 91C   EDLL72-< 	 	>;< ##
 	D3L $ 	 	*!??;'##% ([: :$  		s.   O< O/B/O< #O< /O94O< <	P	P	c           
      
   | j                  d       d}t        |      }d}d| d}d| d}d| d}d	| d}d
}d}	d}
|dd|ddd|	|
d	}||||d}|j                         D ]6  \  }}| j                  |      }| j	                  ||dd| j
                         8 | j                  d      }|j                         D ]D  \  }}d}|dk7  r|rd}| j                  |d|      }| j	                  ||dd| j
                         F y)z% Collect foreman db and dynflow data r   z 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 asczselect 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 asczselect 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 zselect 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 zSELECT id,network,mask,name,vlanid,gateway,dns_primary,dns_secondary,boot_mode,ipam,type,description,mtu,template_id,nic_delay,externalipam_id,externalipam_group,dhcp_id,tftp_id,dns_id,discovery_id,httpboot_id,externalipam_id FROM subnets ORDER BY id DESCzWITH 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 sp.id, sp.name, sp.url, sp.download_policy, STRING_AGG(f.name, ', ') AS features FROM smart_proxies AS sp INNER JOIN smart_proxy_features AS spf ON sp.id = spf.smart_proxy_id INNER JOIN features AS f ON spf.feature_id = f.id GROUP BY sp.idzselect * from schema_migrationsz`select id,type,name,host,port,account,base_dn,attr_login,onthefly_register,tls from auth_sourcesz!select * from dynflow_schema_infozselect count(*) from auditszselect count(*) from logs)	foreman_settings_tableforeman_schema_migrationsforeman_auth_tableforeman_subnets_tabledynflow_schema_infoaudits_table_countlogs_table_countfact_names_prefixessmart_proxies)foreman_tasks_tasksdynflow_execution_plansdynflow_actionsdynflow_stepsX  d   )r)   r-   r'   r4   zdynflow-utilspsqlrd   z /usr/libexec/psql-msgpack-decodeT)csvbinaryN)rI   r   itemsrK   rE   r4   is_installed)rO   r   intervalscmddtaskcmddyncmd
dactioncmd	dstepscmd
subnetscmdfactnamescmdsmartcmd	foremandb
foremancsvtablevalrW   dynutilsdynrl   s                      rX   rL   zForeman.collect_foreman_db   s    //&)*%0;$ 	
((0z1IK- .6J 711 	B CK L;; 	A BJ
 K:: 	H 	 	 	 '+)J#6 &0#F"? ;#/%
	" $,'-)&	

 $//+ 	=JE3'',Duc*-488   =	= $$_5"((* 	=HCF++;''f'EDsC*-488   =	=    c                 4   | j                  d      r| j                  dd      }| j                  || j                        }|d   dk(  rN|d   j	                         d	d
 D ]4  }|j                  d      }d|d	    d}| j                  ||d   dd       6 y
y
y
)z Collect foreman proxies r   z"select name,url from smart_proxiesT)rk   )r4   statusr   r&   r   N,zNcurl -s --key /etc/foreman/client_key.pem --cert /etc/foreman/client_cert.pem z/v2/featuressmart_proxies_features
   )r)   subdirr-   )rI   rK   rA   r4   r7   r9   rE   )rO   rW   proxiesproxys       rX   rM   zForeman.collect_proxies0  s    ???+ ''(L,0 ( 2DmmDdhhm7Gx A%$X.99;AB? 4E!KK,EB#AhZ|5D ''uQx/G02 ( 44 & ,r~   c           	          d}d}d}d}d}d}d}|||||||d}|j                         D ]7  \  }	}
| j                  |
      }| j                  ||	d	d
d| j                         9 y)z6 Collect content view filters definition if requested zselect f.id, f.name, f.type, f.content_view_id, cv.name as content_view_name, f.description from katello_content_view_filters as f inner join katello_content_views as cv on f.content_view_id = cv.idzpselect id, content_view_filter_id, name, min_version, max_version from katello_content_view_package_filter_ruleszbselect id, content_view_filter_id, name, uuid from katello_content_view_package_group_filter_ruleszxselect id, content_view_filter_id, errata_id, start_date, end_date, types from katello_content_view_erratum_filter_rulesz=select * from katello_content_view_module_stream_filter_ruleszUselect id, content_view_filter_id, name from katello_content_view_docker_filter_ruleszuselect id, content_view_filter_id, name, version, min_version, max_version from katello_content_view_deb_filter_rules)katello_cv_filterskatello_cv_package_ruleskatello_cv_group_ruleskatello_cv_errata_ruleskatello_cv_module_ruleskatello_cv_docker_ruleskatello_cv_deb_rulescontent_view_filtersrh   ri   )r)   r   r-   r'   r4   N)rm   rK   rE   r4   )rO   cv_filters_cmdcv_pkg_rules_cmdcv_group_rules_cmdcv_errata_rules_cmdcv_module_rules_cmdcv_docker_rules_cmdcv_deb_rules_cmdfilter_tablesrz   queryrW   s               rX   rN   zForeman.collect_cv_filtersD  s    + 	I 	
C 	
8 	> 	
< 	
9 	 #1(8&8':':':$4
 *//1 	JLE5''.Du'=(+s   J	Jr~   c                 b    |rd| d}d}||| j                   | j                  t        |      fz  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COPY (z6) TO STDOUT WITH (FORMAT 'csv', DELIMITER ',', HEADER)z8%s --no-password -h %s -p %s -U foreman -d foreman -c %s)r:   r;   r   )rO   r   rk   rl   _dbcmds        rX   rK   zForeman.build_query_cmdx  sA     UG $A AEKdkk5<HHHr~   c                     | j                  ddd       | j                  ddd       | j                  dg       | j                  ddd	       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*zfrom settings wherez(http(s)?://)\S+:\S+(@.*)z\1******:******\3)do_path_regex_subdo_paths_http_subdo_cmd_output_sub)rO   s    rX   postproczForeman.postproc  sc    -D	
 	1D	
 	. 
 	 	!( 	"r~   )Frj   )__name__
__module____qualname__
short_descplugin_nameplugin_timeoutprofilespackagesrD   r:   r;   r<   r4   r	   option_listrJ   rY   rL   rM   rN   rK   r    r~   rX   r   r      s    7JKNHHIFFH
C&":	</5:	<)U.	0+u@	B	K @GV&pk=Z4(2JhI"r~   r   c                   "     e Zd ZdZ fdZ xZS )RedHatForemanhttpdc                 j    | j                  ddi       t        | 	          | j                  d       y )Nz"/usr/share/foreman/.ssh/ssh_configssh_foreman_configzgem list)r?   superrY   rE   )rO   	__class__s    rX   rY   zRedHatForeman.setup  s5    02F
 	 	J'r~   )r   r   r   rD   rY   __classcell__)r   s   @rX   r   r     s    I( (r~   r   c                       e Zd ZdZy)DebianForemanapache2N)r   r   r   rD   r   r~   rX   r   r     s    Ir~   r   N)rer   shlexr   sos.report.pluginsr   r   r   r   r	   r   r   r   r   r~   rX   <module>r      sD     9 9F"f F"X(G\ (G\< r~   