o
    vaF                     @   sX   d Z ddl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G dd deZ	dS )zThe stats manager.    N)GlancesStats)	iteritems)loggerZlinuxZmacZbsdZwindowsZciscoZesxiZnetapp)z	.*Linux.*z
.*Darwin.*z.*BSD.*z.*Windows.*z	.*Cisco.*z.*VMware ESXi.*z
.*NetApp.*c                       s:   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Z  ZS )GlancesStatsClientSNMPz?This class stores, updates and gives stats for the SNMP client.Nc                    s0   t t|   || _|| _d | _| | j d S )N)superr   __init__configargsZos_nameZload_modules)selfr   r	   	__class__ ;/usr/lib/python3/dist-packages/glances/stats_client_snmp.pyr   *   s
   zGlancesStatsClientSNMP.__init__c                 C   s   ddl m} || jj| jj| jj| jj| jj| jjd}|	di k}|rQ|	d}z| 
|d | _td| j W |S  tyP   d| _td Y |S w |S )	z(Chek if SNMP is available on the server.r   )GlancesSNMPClient)ZhostZportversionZ	communityuserZauthz1.3.6.1.2.1.1.5.0z1.3.6.1.2.1.1.1.0zSNMP system name detected: {}NzCannot detect SNMP system name)Zglances.snmpr   r	   ZclientZ	snmp_portZsnmp_versionZsnmp_communityZ	snmp_userZ	snmp_authZ
get_by_oidget_system_namesystem_namer   infoformatKeyErrorZwarning)r
   r   Z
clientsnmpretZoid_os_namer   r   r   
check_snmp9   s*   
z!GlancesStatsClientSNMP.check_snmpc                 C   s<   d}|dkr|S t tD ]\}}t||r|} |S q|S )z2Get the short os name from the OS name OID string.N )r   oid_to_short_system_nameresearch)r
   Zoid_system_nameshort_system_namervr   r   r   r   T   s   z&GlancesStatsClientSNMP.get_system_namec                 C   s   | j D ]J}| j |  rqd| j | _| j| j | _z	| j |   W n ty> } ztd	|| W Y d}~qd}~ww | j | 
  | j |   qdS )zUpdate the stats using SNMP.ZsnmpzUpdate {} failed: {}N)Z_pluginsZis_disabledZinput_methodr   r   update	Exceptionr   errorr   Zupdate_stats_historyZupdate_views)r
   per   r   r   r    c   s   
zGlancesStatsClientSNMP.update)NN)	__name__
__module____qualname____doc__r   r   r   r    __classcell__r   r   r   r   r   &   s    r   )
r(   r   Zglances.statsr   Zglances.compatr   Zglances.loggerr   r   r   r   r   r   r   <module>   s   	