(self, oid, host, port, community)
return ret
Perform SNMP get for a given OID
Perform SNMP get for a given OID
Perform SNMP get for a given OID
def get(self, oid, host, port, community):
        """
        Perform SNMP get for a given OID
        """
        # Initialize return value
        ret = {}

        # Convert OID to tuple if necessary
        if not isinstance(oid, tuple):
            oid = self._convert_to_oid(oid)

        # Convert Host to IP if necessary
        host = socket.gethostbyname(host)

        # Assemble SNMP Auth Data
        snmpAuthData = cmdgen.CommunityData(
            'agent-{}'.format(community),
            community)

        # Assemble SNMP Transport Data
        snmpTransportData = cmdgen.UdpTransportTarget(
            (host, port),
            int(self.config['timeout']),
            int(self.config['retries']))

        # Assemble SNMP Next Command
        result = self.snmpCmdGen.getCmd(snmpAuthData, snmpTransportData, oid)
        varBind = result[3]

        # TODO: Error check

        for o, v in varBind:
            ret[str(o)] = v.prettyPrint()

        return ret
def get ( self , oid , host , port , community ) : # Initialize return value ret = { } # Convert OID to tuple if necessary if not isinstance ( oid , tuple ) : oid = self . _convert_to_oid ( oid ) # Convert Host to IP if necessary host = socket . gethostbyname ( host ) # Assemble SNMP Auth Data snmpAuthData = cmdgen . CommunityData ( 'agent-{}' . format ( community ) , community ) # Assemble SNMP Transport Data snmpTransportData = cmdgen . UdpTransportTarget ( ( host , port ) , int ( self . config [ 'timeout' ] ) , int ( self . config [ 'retries' ] ) ) # Assemble SNMP Next Command result = self . snmpCmdGen . getCmd ( snmpAuthData , snmpTransportData , oid ) varBind = result [ 3 ] # TODO: Error check for o , v in varBind : ret [ str ( o ) ] = v . prettyPrint ( ) return ret