o
    id	                     @   s&   d dl mZmZ G dd deeZdS )    )PluginRedHatPluginc                   @   s4   e Zd ZdZd ZdZdZdd Zdd Zdd	 Z	d
S )sapnwzSAP NetWeaver)sap)z/usr/sapc                    s  | j ddd}|d dkrd S d}d}d}d	}t }|d
  D ]}d|vr|ds|  }t|dk r8q |d }	|d }
|d }||	 d|	 }| |sSq | 	|D ]a t
 fdd|	|
|fD rd|	 }d|	 }  }| j||||	|f d| d | j||||
f d|	|
f d | j||||
f d|	|
f d |	 }d|	||
f }| j|||
f |d qXq |D ]	}	| d|	  qd S )Nz9/usr/sap/hostctrl/exe/saphostctrl -function ListInstancesSAPInstancessuggest_filenamestatusr   z7env -i %s %s/sappfpar all pf=/usr/sap/%s/SYS/profile/%sz7env -i %s %s/sapcontrol -nr %s -function GetProcessListz7env -i %s %s/sapcontrol -nr %s -function GetVersionInfoz:su - %sadm -c "sapcontrol -nr %s -function GetEnvironment"outputDAAzNo instances found            z/usr/sap/%s/SYS/profile/c                 3   s    | ]}| v V  qd S )N ).0fliner   :/usr/lib/python3/dist-packages/sos/report/plugins/sapnw.py	<genexpr>3   s    z/sapnw.collect_list_instances.<locals>.<genexpr>z'LD_LIBRARY_PATH=/usr/sap/%s/SYS/exe/runz"/usr/sap/%s/SYS/exe/uc/linuxx86_64z%s_parametersz%s_%s_GetProcListz%s_%s_GetVersInfoz%s_%sadm_%s_userenvz/usr/sap/%s/*DVEB*/work/dev_w0)collect_cmd_outputset
splitlines
startswithstripsplitlenaddpath_existslistdiralladd_cmd_outputloweradd_copy_spec)selfinst_outprof_cmdinst_cmdvers_cmduser_cmd
sidsunique	inst_linefieldssidinstvhostpathldenvptprofilelowsidfnamer   r   r   collect_list_instances   sh   




zsapnw.collect_list_instancesc                 C   s  | j ddd}|d dkrd S |d  D ]u}d|v r|  }|d d d	 }|d
 d d	 }|dd   }|dkrK| jd| d||f d q|dkra|d d d	 }| d||f  q|dkru|d d d	 }| d|  q|dkr|d d d	 }| d||f  qd S )Nz9/usr/sap/hostctrl/exe/saphostctrl -function ListDatabasesSAPDatabasesr   r	   r   r
   zInstance name   r   r   db6zsu - %s -c "db2 get dbm cfg"z%s_%s_db2_infor   z/sapdb/%s/data/config/%s.pahoraz/oracle/%s/*/dbs/init.orasybz/sybase/%s/ASE*/%s.cfg)r   r   r   r   upperr"   r$   )r%   db_outr   r-   dbadmdbtyper.   r   r   r   collect_list_dbsX   s<   

zsapnw.collect_list_dbsc                 C   s:   |    |   | ds| dr| jddd d S d S )Nz)/etc/security/limits.d/99-sap-limits.confallow_system_changesz
sapconf -nsapconf_checkmoder   )r7   rB   r   
get_optionr"   )r%   r   r   r   setup   s   

zsapnw.setupN)
__name__
__module____qualname__
short_descplugin_nameprofilesfilesr7   rB   rF   r   r   r   r   r      s    E)r   N)sos.report.pluginsr   r   r   r   r   r   r   <module>   s   