
    ([Qh"                      H    d dl Z d dlZd dlZd dlmZmZmZ  G d dee      Zy)    N)PluginUbuntuPlugin	PluginOptc            	           e Zd ZdZdZdZdZdZ edde	d	       ed
de
d	       edde
d	       edde
d	      gZdZd Zd Zd Zy)Jujua3  The Juju plugin is aimed at collecting Juju-related logs,
    configurations, and controller/model state(s).

    Logs and agent configuration information (/var/log/juju and /var/lib/juju)
    is collected by default since these are useful for troubleshooting.

    The Juju state collection is disabled by default and can be enabled with
    the 'juju-state' option. Collecting Juju state is safe in theory, but it
    does act on the live controller(s)/model(s) and is therefore optional.

    The default Juju state collection collects all controllers and models that
    the 'juju-user' (default=ubuntu) has access to.

    Specific controllers or models can be collected using the 'controllers'
    and 'models' options.

    Important: the string list is whitespace delimited, not colon delimited
    (sos plugin standard). This is due to the underlying Juju CLI accepting
    specific models in the format 'controller:model' and whitespaces are not
    allowed in either controller and model names.

    Example: models="controller_a:model_x controller_b:model_y"
    zJuju orchestration tooljuju)virtsysmgmt)/var/log/juju
juju-stateFz Include Juju state in the report)defaultval_typedesc	juju-userubuntuzJuju client user.controllers z[Collect Juju state for specified controllers. Uses a             whitespace delimited list.modelszVCollect Juju state for specified models. Uses a whitespace             delimited list.c           
         | j                  d      D ]$  }| j                  |       | j                  |       & dddddddd	d
d	}| j                  d      r:|j	                         D ]'  \  }}| j                  | j                  |      |       ) | j                  d       | j                  ddgd       | j                  d      r6| j                  g d       | j                  d       | j                  d       n| j                  d       | j                  d      sy | j                  d      }	 t        j                  |       | j                  d      r#| j                  d      r| j                  d       y | j                  d|       }|d!   d"k(  rgt!        | j                  d      j#                  d#            }|r	|d$hk7  r|}n5t!        t%        j&                  |d%         d   j)                               }ni }| j                  d      r?| j                  d      j#                  d#      D ]  }	d&|	 d'}
| j                  |
|         y |D ]e  }| j+                  d(| d'|       }|d!   d"k(  s#t%        j&                  |d%         d   }|D ]#  }	|	d)   }d&| d*| d'}
| j                  |
|        % g y # t        $ r | j                  d| d       Y y w xY w)+Nzjuju*	depenginezdebug/pprof/goroutine?debug=1zdebug/pprof/heap?debug=1metricspubsubpresence	statepoolz&debug/pprof/juju/state/tracker?debug=1zunits?action=status)	juju_engine_reportjuju_goroutinesjuju_heap_profilejuju_metricsjuju_pubsub_reportjuju_presence_reportjuju_statepool_reportjuju_statetracker_reportjuju_unit_status/var/lib/juju/agents)suggest_filenamez!/var/lib/juju/agents/*/agent.confz/var/log/juju*z/var/lib/juju*T)	recursiveall_logs)r   z/var/lib/jujuz/var/lib/juju/**/.*z/var/lib/juju/kvmz/var/lib/juju/toolsz/var/log/juju/*.logr   r   zUser "z4" does not exist, will not collect Juju information.r   r   zWOptions: controllers, models are mutually exclusive. Will not collect Juju information.zjuju controllers --format=json)runasstatusr    r   outputzjuju status -m z --format=jsonzjuju models --all -c z
short-name:)get_service_namesadd_journaladd_service_statuspath_existsitemsadd_cmd_output_juju_agentadd_copy_specadd_dir_listing
get_optionadd_forbidden_pathpwdgetpwnamKeyError	_log_warncollect_cmd_outputsetsplitjsonloadskeysexec_cmd)selfservicejuju_agent_cmdscmd	agent_cmd	juju_usercontrollers_jsondesired_controllersr   modelcommand
controllermodels_jsonr   
short_names                  9/usr/lib/python3/dist-packages/sos/report/plugins/juju.pysetupz
Juju.setupR   s[    --g6 	-GW%##G,	-
 #.>!;%"*$.%0*3 5
 23"1"7"7"9 Y##$$Y/%( $  	>? 	
  	 	
 ??:&    
 ##$78##$9: 45 |,OOK0		LL# ??=)dooh.GNN5 22,I 3 
 H%*"%.44S9#
 #':rd'B1!JJ/9:%df K ??8$288= >+E7.A##G9#=> * F
"mm+J<~F# ,  x(A-!ZZH(=>xHF!' F%*<%8
-j\:, G, -   ++G9+EFFW  	NN $5 5 	s   2J: :KKc                     | j                   dk(  r5| j                  d      D ]!  }t        j                  d|      s|| _          n d| j                    d| S )Nr   r$   z$machine-*|controller-*|application-*zjuju-introspect --agent=r*   )
agent_namelistdirresearch)rC   rL   dir_names      rP   r3   zJuju._juju_agent   sZ    ??b  LL)?@ 99CXN&.DO
 *$//):!G9EE    c                     d}g d}ddj                  |       d}d}| j                  |||       | j                  |       | j                  d       y )Nz/var/lib/juju/agents/*)sharedsecretapipasswordoldpasswordstatepasswordz(^\s*(|z)\s*:\s*)(.*)z\1*********zjuju controllers)joindo_path_regex_subdo_file_private_subdo_cmd_private_sub)rC   agents_pathprotect_keys
keys_regex	sub_regexs        rP   postproczJuju.postproc   s\    .
 sxx56mD
"	{J	B  - 23rX   N)__name__
__module____qualname____doc__
short_descplugin_nameprofilesfilesr   boolstroption_listrS   rQ   r3   rg    rX   rP   r   r      s    0 +JK#H E 	3		
 	$		
 	(		
 			
)K: JsFjF4rX   r   )r8   r?   rU   sos.report.pluginsr   r   r   r   rs   rX   rP   <module>ru      s&      	 > >N46< N4rX   