+
    i&  c                   sN    ^ RI t ^ RIt^ RIHtHtHt ^ RIHt  ! R R]]4      tR# )i    N)Plugin	PluginOptUbuntuPlugin)is_executablec            
       s   a  ] tR t^t o RtRtRt. R+OtRtRt	Rt
RtRtR	R
RRRRRRRR/t]! RR]RR7      ]! RR]RR7      ]! RR]RR7      ]! RR]RR7      .tR  tR! tR" tR# tR$ tR% tR& tR' tR( tR)tV tR*# ),CharmedMySQLaq  
The Charmed MySQL plugin is used to collect MySQL configuration and logs
from the Charmed MySQL snap package or K8s deployment.
It also collects MySQL Router and MySQL Shell configuration and logs
where available, journal logs for the snap, and snap info.

If the `dumpdbs` option is set to `True`, the plugin will also try and
collect the names of the databases that the user has access to. The
`mysql` user is used by default, but that can be set using the `dbuser`
option. When using the `dumpdbs` option, you must then provide the
password for the user using the `dbpass` option or the `MYSQL_PWD`
environment variable.
zCharmed MySQLZcharmed_mysqlzcharmed-mysqlz/var/snap/charmed-mysql/commonz/var/snap/charmed-mysql/currentZkubectlz app.kubernetes.io/name=mysql-k8s
MYSQL_CONFz
/etc/mysql
MYSQL_LOGSz/var/log/mysqlMYSQL_ROUTER_CONFz/etc/mysqlrouterMYSQL_ROUTER_LOGSz/var/log/mysqlrouterMYSQL_SHELL_LOGSz/var/log/mysqlshdbusermysqlz%Username for database dump collection)ZdefaultZval_typeZdescdbpassZ z%Password for database dump collectiondumpdbsFzGet name of all databases
logs_sinceZ48hz9How far back to fetch logs with kubectl --since, K8s onlyc                s:   V P                  R 4      pV P                  R4      pR\        P                  9   d>   V'       g6   V P                  P	                  R4       \        P                  R,          pW3# V'       g   V P                  P                  R4       R# W3# )r
   r   	MYSQL_PWDzWMYSQL_PWD present: Using MYSQL_PWD environment variable, user did not provide password.zHdumpdbs_error: option is set, but username and password are not provided)NN)
get_optionosZenvironZsoslogZinfoZwarning)selfdb_userdb_passs   &  E/usr/lib/python3.14/site-packages/sos/report/plugins/charmed_mysql.py_get_db_credentialsZ CharmedMySQL._get_db_credentials[   s    //(+//(+"**$WKK1 jj-G  KK#     c                s    V P                  V P                   R V P                   R24      pVR,          ^ 8X  d8   \        \	        VR,          P                  4       P                  4       4      4      # . # )z get pods -A -l z- -o jsonpath='{.items[*].metadata.namespace}'statusoutput)exec_cmdkube_cmdselectorZlistZsetstripsplit)r   
namespaces   & r   _determine_namespacesZ"CharmedMySQL._determine_namespacesn   si    ]]}}o-dmm_ =; ;

 h1$Jx0668>>@ABB	r   c                s    V P                  V P                   R V RV P                   R24      pVR,          ^ 8X  d&   VR,          P                  4       P	                  4       # . # ) -n z get pods -l z( -o jsonpath='{.items[*].metadata.name}'r   r   )r   r   r   r   r   )r   	namespacepodss   && r   _get_pod_namesZCharmedMySQL._get_pod_namesw   sc    }}}}oT)M$-- I6 6
 >Q>'')//11	r   c                s   V P                    R V 2pV P                  V RV P                   R2V RV P                   2.4       V P                  V RV P                   RV R24       RpV P                  V4      pV P	                  4       pV P
                  P                  4        FU  w  rxV FJ  p	\        P                  ! V RV	 RV 2R	R
7       V RV RV	 RV RV RV	 RV 2p
V P                  V
4       KL  	  KW  	  V P                  V R2V R2.4       V P                  R4      '       Ed0   V P                  4       w  rV'       d	   V'       g   R# RV 2pRV R2pRP                  R V P                   4       4      p\        P                   ! 4       ;_uu_ 4       pRpVR,           V,           p\#        VRRR7      ;_uu_ 4       pVP%                  V4       RRR4       V Fn  p	V RV RV	 RV 2pV P                  V4       V RV RV RV	 RV 2	p
V P                  V
4       V RV RV	 RV RV RV RV 2pV P                  VV	 R 2R!7       Kp  	  RRR4       R# R#   + '       g   i     L; i  + '       g   i     R# ; i)"r"   z get all -l z -o widez describe pods -l z	 logs -l z	 --since=z* --all-containers=true --prefix --all-podsr   Z/T)Zexist_okz cp -c Z Z:z/*/MYSQL_CONF/*.pemz/*/MYSQL_CONF/*.keyr   N-h 127.0.0.1 -umysql  -ec              3   sF   "   T F  pVP                  R R4      x  K  	  R# 5i)Z"z\"N)Zreplace)Z.0queryr    r   Z	<genexpr>Z6CharmedMySQL._collect_per_namespace.<locals>.<genexpr>   s%      /E dF++/s   !Z	mysql_pwdZwZutf8)Zencodingz	 exec -c z -- mkdir -p z -- sh -lc 'MYSQL_PWD=$(cat z) z "z"' && rm -rf z_dbs.txt)Zsuggest_filename)r   add_cmd_outputr   r%   Zget_cmd_output_path
conf_pathsZitemsr   Zmakedirsr   add_forbidden_pathr   r   joinmysql_queriestempfileZTemporaryDirectoryZopenZwrite)r   r#   r   r   Z
mysql_contr$   Zdump_files_pathZnamepathZpodZcopy_cmdr   r   optssql_cmdZqueriesZtmpdirZpwd_fileZpwd_pathZfZ	mkdir_cmdZqueries_cmds   &&&                   r   _collect_per_namespaceZ#CharmedMySQL._collect_per_namespace   s   mm_D4 	jT]]O8<j*4==/:
 	 	j	$--	* F8 8	

 
""9- 224////1JD/qQtf=Mj
|1SE4&&'qQtf6  h'  2 	2323!
 	 ??9%%#779G'$WI.DtfC(Ghh !// G
 ,,..&&!C<(2(C&99QGGG$ :  C#*Ij\3% @$$*8-  MM), $*GJ<q#*AcU!H:7  MM(+ $*Ij\3% @33;*B")3wi 0%%+H.   ''#,/5)9 ( '   /. &  :9	 /..s%   )I3I 	A<I3 I0+I33J	c                s    V Uu. uF+  q3P                  \        P                  P                  4      NK-  	  pp\        P                  P                  ! V.VO5!  # u upi N)Zlstripr   r0   Zsepr-   )r   ZbaseZpartsZpZstripped_partss   &&*  r   _join_conf_pathZCharmedMySQL._join_conf_path   sC    9>?A((277;;/?ww||D2>22 @s   1Ac                s|    V P                  R 4      pV P                  4       pV F  pV P                  W14       K  	  R# )r   N)r   r!   r3   )r   r   r   r#   s   &   r   _process_k8sZCharmedMySQL._process_k8s   s6    __\2
//1
#I''	> $r   c                s    V P                  V P                  V P                  V P                  R ,          R4      V P                  V P                  V P                  R ,          R4      .4       V P	                  V P                  V P                  V P                  R ,          4      V P                  V P
                  V P                  R,          4      V P                  V P                  V P                  R,          4      V P                  V P
                  V P                  R,          4      V P                  V P
                  V P                  R,          4      .4       V P                  R4       V P                  R4       V P                  R	4      '       dh   V P                  4       w  rV'       d	   V'       g   R
# RV/pRV 2pRV R2pT P                  V P                   Uu. uF
  qe RV R2NK  	  upVR7       R
# R
# u upi )r   z*.pemz*.keyr   r   r   r	   zsnap.charmed-mysql.*zsnap info charmed-mysqlr   Nr   r&   r'   r(   z 'Z')Zenv)r,   r5   snap_path_currentr+   Zadd_copy_specsnap_path_commonZadd_journalr*   r   r   r.   )r   r   r   Z	mysql_envr1   r2   r)   s   &      r   _process_snapZCharmedMySQL._process_snap   s     &&-
   &&-!
 	 	  &&-   %%-   && 34   %% 34   %% 23#
 	0 	/0 	56 ??9%%#779G'$g.I$WI.DtfC(G595G5GH5GE9BugQ'5GH    & Is   G;c                s    V P                  V P                  4      '       d   R # \        V P                  V P                  4      ;'       d    \        V P                  4       4      # )T)is_installedsnap_packager   r   sysrootboolr!   r      &r   check_enabledZCharmedMySQL.check_enabled  sP    T..// $--6 / /++-.	
r   c                s    V P                  V P                  4      '       d   V P                  4        \        V P                  V P
                  4      '       d   V P                  4        R # R # r4   )r:   r;   r9   r   r   r<   r6   r>   r?   r   setupZCharmedMySQL.setup  sK    T..// 55 6r    N)zshow databases;z*select * from mysql.juju_units_operations;zPselect * from performance_schema.replication_group_members order by MEMBER_HOST;z"show global status like "%conne%";z,select * from performance_schema.host_cache;zshow ENGINE InnoDB STATUS;)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__Z
short_descZplugin_namer.   r;   r8   r7   r   r   r+   r   Zstrr=   Zoption_listr   r!   r%   r3   r5   r6   r9   r@   rA   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r   r      s      !J!KM. #L79H1H 	l&/3.J 	g8	
 	b38	
 	ut,	
 	%#L	
K& &L\3?:x	
   r   r   )	r   r/   Zsos.report.pluginsr    r   r   Zsos.utilitiesr   r   rB   r   r   <module>rC      s&    
  > > 'T 6< T r   