o
    Ìv›a¡  ã                
   @   sŠ   d Z ddlmZ ddlmZ ddlmZ zddlmZ W n e	y8 Z
 zdZe d e
¡¡ W Y dZ
[
ndZ
[
ww d	ZG d
d„ deƒZdS )zRAID plugin.é    )Úiterkeys)Úlogger)ÚGlancesPlugin)ÚMdStatTz0Missing Python Lib ({}), Raid plugin is disabledNFc                       sH   e Zd ZdZd‡ fdd„	Zejejdd„ ƒƒZddd„Z	d	d
„ Z
‡  ZS )ÚPluginzKGlances RAID plugin.

    stats is a dict (see pymdstat documentation)
    Nc                    s   t t| ƒj||d d| _dS )zInit the plugin.)ÚargsÚconfigTN)Úsuperr   Ú__init__Zdisplay_curse)Úselfr   r   ©Ú	__class__© ú>/usr/lib/python3/dist-packages/glances/plugins/glances_raid.pyr
   *   s   
zPlugin.__init__c              
   C   s„   |   ¡ }tr	| jS | jdkr6ztƒ }| ¡ d }W n" ty5 } zt d| ¡ | jW  Y d}~S d}~ww | jdkr<	 || _| jS )z)Update RAID stats using the input method.ZlocalÚarrayszCan not grab RAID stats (%s)NZsnmp)	Zget_init_valueÚimport_error_tagÚstatsZinput_methodr   Z	get_statsÚ	Exceptionr   Údebug)r   r   ZmdsÚer   r   r   Úupdate1   s    
€þ
zPlugin.updatec                 C   s|  g }| j r	|  ¡ r|S |d }djd|d}| |  |d¡¡ d d¡}| |  |¡¡ d d¡}| |  |¡¡ tt| j ƒƒ}|D ]x}| |  ¡ ¡ |  | j | d	 | j | d
 | j | d | j | d ¡}| j | d durz| j | d  	¡ nd}	d |	|¡}
dj|
|d}| |  |¡¡ | j | d dkrÇ| j | d	 dkrÇd t
| j | d ƒ¡}| |  ||¡¡ d d¡}| |  ||¡¡ n | j | d	 dkr÷d | j | d
 ¡}| |  ||¡¡ d | j | d ¡}| |  ||¡¡ np| j | d	 dkrg| |  ¡ ¡ d | j | d	 ¡}| |  ||¡¡ tt| j | d ƒƒ}t|ƒD ]<\}}|t
|ƒd kr:d}nd}| |  ¡ ¡ d || j | d | ¡}| |  |¡¡ d |¡}| |  |¡¡ q*| j | d dkr»| j | d
 | j | d k r»| |  ¡ ¡ d}| |  ||¡¡ t
| j | d ƒdk r»| |  ¡ ¡ d | j | d  dd ¡¡}| |  |¡¡ qB|S )!z2Return the dict to display in the curse interface.é   z
{:{width}}z
RAID disks)ÚwidthZTITLEz{:>7}ZUsedZAvailÚstatusÚusedÚ	availableÚtypeNZUNKNOWNz{} {}Úraid0ZactiveÚ
componentsú-Úinactiveu   â””â”€ Status {}é   u   â””â”€u   â”œâ”€z   {} disk {}: z{}u   â””â”€ Degraded moder   é   u      â””â”€ {}Ú_ÚA)r   Zis_disabledÚformatÚappendZcurse_add_lineÚsortedr   Zcurse_new_lineÚ
raid_alertÚupperÚlenÚ	enumerateÚreplace)r   r   Z	max_widthÚretZname_max_widthÚmsgr   Zarrayr   Z
array_typeZ	full_namer   ÚiZ	componentZ	tree_charr   r   r   Ú	msg_curseP   sx   ÿ


ý(ÿ$

2€zPlugin.msg_cursec                 C   s<   |dkrdS |dkrdS |du s|du rdS ||k rdS dS )zÜRAID alert messages.

        [available/used] means that ideally the array may have _available_
        devices however, _used_ devices are in use.
        Obviously when used >= available then things are good.
        r   ZOKr    ZCRITICALNZDEFAULTZWARNINGr   )r   r   r   r   r   r   r   r   r(   š   s   zPlugin.raid_alert)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Z_check_decoratorZ_log_result_decoratorr   r0   r(   Ú__classcell__r   r   r   r   r   $   s    
Jr   )r4   Zglances.compatr   Zglances.loggerr   Zglances.plugins.glances_pluginr   Zpymdstatr   ÚImportErrorr   r   Zwarningr%   r   r   r   r   r   Ú<module>   s   €þ