o
    va                  
   @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddd	ddd
ddZddddddddddiZdd ZG dd deZdS )zSystem plugin.    N)open)logger)	iteritems)GlancesPluginz1.3.6.1.2.1.1.5.0z1.3.6.1.2.1.1.1.0)hostnamesystem_namez1.3.6.1.4.1.789.1.1.5.0)r   r   platform)defaultZnetappwindowszWindows 10 or Server 2016zWindows 8.1 or Server 2012R2zWindows 8 or Server 2012zWindows 7 or Server 2008R2zWindows Vista or Server 2008z Windows XP 64bits or 2003 serverz
Windows XPzWindows 2000)zWindows Version 10.0zWindows Version 6.3zWindows Version 6.2zWindows Version 6.1zWindows Version 6.0zWindows Version 5.2zWindows Version 5.1zWindows Version 5.0c               
   C   s   d} i }ddg}z:t tjdd'}|D ]}|D ]}||r0tdd| dd ||< qqW d	   n1 s<w   Y  W n t	t
fyO   |  Y S w |rgd|v rZ|d } d|v rg| d
|d 7 } | S )a  Try to determine the name of a Linux distribution.

    This function checks for the /etc/os-release file.
    It takes the name from the 'NAME' field and the version from 'VERSION_ID'.
    An empty string is returned if the above values cannot be determined.
     NAMEZ
VERSION_IDz/etcz
os-releasez^"|"$=   N {})r   ospathjoin
startswithresubstripsplitOSErrorIOErrorformat)Zpretty_nameZashtraykeysflinekey r   @/usr/lib/python3/dist-packages/glances/plugins/glances_system.py_linux_os_release4   s.   
 r!   c                       s@   e Zd ZdZd	 fdd	Zejejdd Zd	ddZ	  Z
S )
Pluginz6Glances' host/system plugin.

    stats is a dict
    Nc                    s4   t t| j||d d| _|  r| d dS dS )zInit the plugin.)argsconfigT<   N)superr"   __init__Zdisplay_curseZget_refreshZset_refresh)selfr#   r$   	__class__r   r    r'   W   s
   zPlugin.__init__c                 C   s>  |   }| jdkrt |d< t |d< t d |d< |d dkrVzt }W n ty7   t |d< Y nw |d dkrDt |d< nd		|d
d |d< t
 |d< nM|d dsc|d dkrjt
 |d< n9|d dkryt d |d< n*|d dkrt }d		|d
d
d |d< |d dkrdtjv rd|d< nd|d< |d dkr|d |d< nd|d |d |d< |d  d|d 7  < nO| jdkrz| jt| j d}W n ty   | jtd d}Y nw |d |d< | jdkrttd D ]\}}t||d r||d<  nq|d |d< || _| jS )z]Update the host/system info using the input method.

        Return the stats (dict)
        Zlocalos_namer   r   r   Linuxlinux_distror    N   
os_versionZBSDZSunOSZDarwinZWindowsZ32bitZPROCESSOR_ARCHITEW6432Z64bitZhr_namez{} {}r   snmp)snmp_oidr	   r   r
   )Zget_init_valueZinput_methodr   systemZnodeZarchitectureZlinux_distributionAttributeErrorr!   r   releaseendswithZmac_verZ	win32_verr   environr   Zget_stats_snmpr2   Zshort_system_nameKeyErrorr   snmp_to_humanr   searchstats)r(   r;   r-   r0   rvr   r   r    updateb   sh   


zPlugin.updatec                 C   s8  g }|j r=|j dkrd}|| |d n%|j dkr+d}|| |d n|j dkr=d}|| |d | jd	 }|| |d
 | jd dkrl| jd rld| jd | jd | jd | jd }n$zd| jd | jd | jd }W n ty   d| jd }Y nw || j|dd |S )z4Return the string to display in the curse interface.Z	connectedzConnected to ZOKr1   z
SNMP from ZdisconnectedzDisconnected from ZCRITICALr   ZTITLEr+   r,   r-   z ({} {} / {} {})r   r0   z ({} {} {})z ({})T)Zoptional)ZclientZ	cs_statuslowerappendZcurse_add_liner;   r   	Exception)r(   r#   Z	max_widthretmsgr   r   r    	msg_curse   s:   
zPlugin.msg_curse)NN)__name__
__module____qualname____doc__r'   r   Z_check_decoratorZ_log_result_decoratorr>   rD   __classcell__r   r   r)   r    r"   P   s    Er"   )rH   r   r   r   ior   Zglances.loggerr   Zglances.compatr   Zglances.plugins.glances_pluginr   r2   r9   r!   r"   r   r   r   r    <module>   s6   

