????

Your IP : 3.149.237.146


Current Path : /lib/python3.6/site-packages/glances/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/glances/__pycache__/snmp.cpython-36.opt-1.pyc

3

Eo�cQ�@sbddlZddlmZyddlmZWn(ek
rLejd�ejd�YnXGdd�de�Z	dS)�N)�logger)�cmdgenz;PySNMP library not found. To install it: pip install pysnmp�csJeZdZdZd�fdd	�	Zd
d�Zdd
�Zdd�Zdd�Zdd�Z	�Z
S)�GlancesSNMPClientz,SNMP client class (based on pysnmp library).�	localhost��2c�public�private�cs@tt|�j�tj�|_||_||_||_||_	||_
||_dS)N)�superr�__init__rZCommandGenerator�cmdGen�version�host�port�	community�user�auth)�selfrrrrrr)�	__class__��/usr/lib/python3.6/snmp.pyr
s
zGlancesSNMPClient.__init__cCsri}xh|D]`\}}t|�dkr,d||j�<q
|j�||j�<||j�jd�r
||j�dd�||j�<q
W|S)zBuild the results.rzb'r����)�strZprettyPrint�
startswith)r�varBinds�ret�name�valrrrZ
__buid_result(s zGlancesSNMPClient.__buid_resultcCsi}|s|r|j|�}|S)zPut results in table.)�_GlancesSNMPClient__buid_result)r�errorIndication�errorStatus�
errorIndexrrrrr�__get_result__5s
z GlancesSNMPClient.__get_result__cGs�|jdkrB|jjtj|j|j�tj|j|j	f�f|��\}}}}n2|jjtj
|j�tj|j|j	f�f|��\}}}}|j||||�S)z�SNMP simple request (list of OID).

        One request per OID list.

        :param oid: oid list
        :return: a dict
        �3)
rr�getCmdr�UsmUserDatarr�UdpTransportTargetrr�
CommunityDatarr%)r�oidr"r#r$rrrr�
get_by_oid<s
2,zGlancesSNMPClient.get_by_oidcCs2g}|s|r.x|D]}|j|j|��qW|S)N)�appendr!)rr"r#r$�varBindTablerZvarBindTableRowrrr�__bulk_result__Ns

z!GlancesSNMPClient.__bulk_result__c	Gs�|jjd�rF|jjtj|j|j�tj|j	|j
f�||f|��\}}}}|jjd�r�|jjtj|j
�tj|j	|j
f�||f|��\}}}}ngS|j||||�S)a�SNMP getbulk request.

        In contrast to snmpwalk, this information will typically be gathered in
        a single transaction with the agent, rather than one transaction per
        variable found.

        * non_repeaters: This specifies the number of supplied variables that
          should not be iterated over.
        * max_repetitions: This specifies the maximum number of iterations over
          the repeating variables.
        * oid: oid list
        > Return a list of dicts
        r&�2)rrrr'rr(rrr)rrZbulkCmdr*rr/)	rZ
non_repeatersZmax_repetitionsr+r"r#r$rr.rrr�getbulk_by_oidUs 
z GlancesSNMPClient.getbulk_by_oid)rrrr	r
r)�__name__�
__module__�__qualname__�__doc__r
r!r%r,r/r1�
__classcell__rr)rrrs
r)
�sysZglances.loggerrZpysnmp.entity.rfc3413.onelinerr�ImportErrorZcritical�exit�objectrrrrr�<module>
s