a >h @sBddlZddlZddlZddlmZmZmZGdddeeZdS)N)Plugin UbuntuPlugin PluginOptc @sxeZdZdZdZdZdZdZedde dd ed d e d d ed de dd edde dd gZ dZ ddZ ddZddZdS)Jujua3The 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" zJuju orchestration toolZjuju)ZvirtZsysmgmt) /var/log/juju juju-stateFz Include Juju state in the report)defaultZval_typeZdesc juju-userZubuntuzJuju client user. controllersz[Collect Juju state for specified controllers. Uses a whitespace delimited list.modelszVCollect Juju state for specified models. Uses a whitespace delimited list.c CsX|dD]}||||q dddddddd d d }|d rl|D]\}}|j|||d qN|d|jddgdd| dr|gd| d| dn |d| dsdS| d}zt |Wn(t y|d|dYdS0| dr6| dr6|ddS|jd|d }|d!d"krt| dd#}|r~|d$hkr~|}ntt|d%d}ni}| dr| dd#D] } d&| d'} |j| |d qnv|D]p} |jd(| d'|d } | d!d"krt| d%d} | D].} | d)}d&| d*|d'} |j| |d q qdS)+Nzjuju*Z depenginezdebug/pprof/goroutine?debug=1zdebug/pprof/heap?debug=1ZmetricsZpubsubZpresenceZ statepoolz&debug/pprof/juju/state/tracker?debug=1zunits?action=status) Zjuju_engine_reportZjuju_goroutinesZjuju_heap_profileZ juju_metricsZjuju_pubsub_reportZjuju_presence_reportZjuju_statepool_reportZjuju_statetracker_reportZjuju_unit_status/var/lib/juju/agents)Zsuggest_filenamez!/var/lib/juju/agents/*/agent.confz/var/log/juju*z/var/lib/juju*T) recursiveZall_logs)rz /var/lib/jujuz/var/lib/juju/**/.*z/var/lib/juju/kvmz/var/lib/juju/toolsz/var/log/juju/*.logrr zUser "z4" does not exist, will not collect Juju information.r r zWOptions: controllers, models are mutually exclusive. Will not collect Juju information.zjuju controllers --format=json)Zrunasstatusr r outputzjuju status -m z --format=jsonzjuju models --all -c z short-name:)Zget_service_namesZ add_journalZadd_service_statusZ path_existsitemsZadd_cmd_output _juju_agentZ add_copy_specZadd_dir_listingZ get_optionZadd_forbidden_pathpwdgetpwnamKeyErrorZ _log_warnZcollect_cmd_outputsetsplitjsonloadskeysZexec_cmd)selfZserviceZjuju_agent_cmdscmdZ agent_cmdZ juju_userZcontrollers_jsonZdesired_controllersr ZmodelcommandZ controllerZ models_jsonr Z short_namer ;/usr/lib/python3.9/site-packages/sos/report/plugins/juju.pysetupRs               z Juju.setupcCsB|jdkr0|dD]}td|r||_q0qd|jd|S)Nr r z$machine-*|controller-*|application-*zjuju-introspect --agent=r) agent_namelistdirresearch)rrZdir_namer r r!rs   zJuju._juju_agentcCsVd}gd}dd|d}d}|||||ddd |||d dS) Nz/var/lib/juju/agents/*)Z sharedsecretZ apipasswordZ oldpasswordZ statepasswordz(^\s*(|z )\s*:\s*)(.*)z \1*********z)/var/log/juju/unit-nova-compute-(.*).log*zauth\(key=(.*)\)zauth(key=******)zjuju controllers)joinZdo_path_regex_subZdo_file_private_subZdo_cmd_private_sub)rZ agents_pathZ protect_keysZ keys_regexZ sub_regexr r r!postprocs z Juju.postprocN)__name__ __module__ __qualname____doc__Z short_descZ plugin_nameZprofilesfilesrboolstrZ option_listr#r"rr)r r r r!rsDu r)rrr%Zsos.report.pluginsrrrrr r r r! s