U
    -_g                     @   s:   d dl Z d dlZd dlmZmZmZ G dd deeZdS )    N)PluginUbuntuPlugin	PluginOptc                	   @   sl   e Zd ZdZdZdZdZdZedde	dd	ed
de
dd	edde
dd	edde
dd	gZdd Zdd ZdS )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 toolZjuju)ZvirtZsysmgmt)/var/log/juju
juju-stateFz Include Juju state in the report)defaultZval_typeZdesc	juju-userZ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                 C   s&  |  dD ]}| | | | q
| dddddddd	d
dg
 | d | jddgdd | dr| dddg | d n
| d | dsd S | d}zt	| W n( t
k
r   | d| d Y d S X | dr| dr| d d S | jd|d}|d  d!krht| dd"}|rL|d#hkrL|}ntt|d$ d  }ni }| dr| dd"D ] }d%| d&}| j||d qnv|D ]p}| jd'| d&|d}	|	d  d!krt|	d$ d }
|
D ].}|d( }d%| d)| d&}| j||d qqd S )*Nzjuju*Zjuju_engine_reportZjuju_goroutinesZjuju_heap_profileZjuju_leasesZjuju_metricsZjuju_pubsub_reportZjuju_presence_reportZjuju_statepool_reportZjuju_statetracker_reportZjuju_unit_statusz!/var/lib/juju/agents/*/agent.confz/var/log/juju*z/var/lib/juju*T)	recursiveZall_logsr   z/var/lib/jujuz/var/lib/juju/**/.*z/var/lib/juju/kvmz/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)ZrunasZstatusr    r   outputzjuju status -m z --format=jsonzjuju models --all -c z
short-name:)Zget_service_namesZadd_journalZadd_service_statusZadd_cmd_outputZadd_copy_specZadd_dir_listingZ
get_optionZadd_forbidden_pathpwdgetpwnamKeyErrorZ	_log_warnZcollect_cmd_outputsetsplitjsonloadskeysZexec_cmd)selfserviceZ	juju_userZcontrollers_jsonZdesired_controllersr
   ZmodelZcommandZ
controllerZmodels_jsonr   Z
short_name r   9/usr/lib/python3/dist-packages/sos/report/plugins/juju.pysetupO   s    






 
z
Juju.setupc                 C   sL   d}ddddg}dd | d}d	}| ||| | | | d
 d S )Nz/var/lib/juju/agents/*ZsharedsecretZapipasswordZoldpasswordZstatepasswordz(^\s*(|z)\s*:\s*)(.*)z\1*********zjuju controllers)joinZdo_path_regex_subZdo_file_private_subZdo_cmd_private_sub)r   Zagents_pathZprotect_keysZ
keys_regexZ	sub_regexr   r   r   postproc   s    
zJuju.postprocN)__name__
__module____qualname____doc__Z
short_descZplugin_nameZprofilesfilesr   boolstrZoption_listr   r    r   r   r   r   r      s@   mr   )r   r   Zsos.report.pluginsr   r   r   r   r   r   r   r   <module>   s   