title: Is there any right format for adding context name to the snmp agent?
body: <p>I am new to SNMP Context.I am setting up a SNMP agent in the cloud. This is the basic format we got from the snmplabs.com which uses the context name. But the problem is when we use context name in the snmpwalk request it give reply like </p>
  
  <p>"SNMPv2-SMI::dod = No more variables left in this MIB View (It is past the end of the MIB tree)"</p>
  
  <p>We follow the format 
  <a href="http://snmplabs.com/pysnmp/examples/v3arch/asyncore/agent/cmdrsp/agent-side-mib-implementations.html" rel="nofollow noreferrer">http://snmplabs.com/pysnmp/examples/v3arch/asyncore/agent/cmdrsp/agent-side-mib-implementations.html</a></p>
  
  <pre class="lang-py prettyprint-override"><code># Serve non-default MIB tree
  
  # Listen and respond to SNMP GET / SET / GETNEXT / GETBULK queries with
  # the following options:
  
  #  SNMPv3
  #  with USM username usr - md5 - none
  #  using alternative set of Managed Objects addressed by
  #  contextName: my - context
  #  allow access to SNMPv2 - MIB objects (1.3.6.1.2.1)
  #  over IPv4 / UDP, listening at 127.0.0.1:161
  
  from pysnmp.entity import engine, config
  
  from pysnmp.entity.rfc3413 import cmdrsp, context
  
  from pysnmp.carrier.asyncore.dgram import udp
  
  from pysnmp.smi import instrum, builder
  
  from pysnmp.proto.api import v2c
  
  snmpEngine = engine.SnmpEngine()
  
  config.addTransport(
      snmpEngine,
      udp.domainName,
      udp.UdpTransport().openServerMode(('127.0.0.1', 161))
  )
  
  # SNMPv3/USM setup
  
  # user: usr-md5-none, auth: MD5, priv NONE
  config.addV3User(
      snmpEngine, 'usr-md5-none',
      config.usmHMACMD5AuthProtocol, 'authkey1'
  )
  
  # Allow full MIB access for each user at VACM
  config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
  
  snmpContext = context.SnmpContext(
      snmpEngine
  )
  
  # Create an [empty] set of Managed Objects (MibBuilder), pass it to
  # Management Instrumentation Controller and register at SNMP Context
  # under ContextName 'my-context'
  snmpContext.registerContextName(
      v2c.OctetString('my-context'),  # Context Name
      instrum.MibInstrumController(builder.MibBuilder().loadModules)  # Managed Objects
  )
  
  # Register SNMP Applications at the SNMP engine for particular SNMP context
  cmdrsp.GetCommandResponder(snmpEngine, snmpContext)
  cmdrsp.SetCommandResponder(snmpEngine, snmpContext)
  cmdrsp.NextCommandResponder(snmpEngine, snmpContext)
  cmdrsp.BulkCommandResponder(snmpEngine, snmpContext)
  
  # Register an imaginary never-ending job to keep I/O dispat#cher running forever
  snmpEngine.transportDispatcher.jobStarted(1)
  
  # Run I/O dispatcher which would receive queries and send responses
  try:
      snmpEngine.transportDispatcher.runDispatcher()
  except:
      snmpEngine.transportDispatcher.closeDispatcher()
      raise
  
  </code></pre>
  
  <pre><code>snmpwalk -v3 -u usr-md5-none -l authNoPriv -A authkey1  -n my-context 127.0.0.1 .1.3.6
  </code></pre>
  
  <p>While using the above snmpwalk, we will get output like</p>
  
  <pre><code>SNMPv2-SMI::dod = No more variables left in this MIB View (It is past the end of the MIB tree)
  </code></pre>
  
  <p>But if use the following snmpwalk </p>
  
  <pre><code>snmpwalk -v3 -u usr-md5-none -l authNoPriv -A authkey1 127.0.0.1 .1.3.6
  </code></pre>
  
  <p>we will get output</p>
  
  <pre><code>SNMPv2-MIB::sysDescr.0 = STRING: PySNMP engine version 4.4.11, Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)]
  
  SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.20408
  DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (14) 0:00:00.14
  
  SNMPv2-MIB::sysContact.0 = STRING:
  
  SNMPv2-MIB::sysName.0 = STRING: 
  SNMPv2-MIB::sysLocation.0 = STRING: 
  SNMPv2-MIB::sysServices.0 = INTEGER: 0
  SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00
  SNMPv2-MIB::snmpInPkts.0 = Counter32: 10
  SNMPv2-MIB::snmpOutPkts.0 = Counter32: 0
  SNMPv2-MIB::snmpInBadVersions.0 = Counter32: 0
  SNMPv2-MIB::snmpInBadCommunityNames.0 = Counter32: 0
  SNMPv2-MIB::snmpInBadCommunityUses.0 = Counter32: 0
  SNMPv2-MIB::snmpInASNParseErrs.0 = Counter32: 0
  SNMPv2-MIB::snmpInTooBigs.0 = Counter32: 0
  SNMPv2-MIB::snmpInNoSuchNames.0 = Counter32: 0
  SNMPv2-MIB::snmpInBadValues.0 = Counter32: 0
  SNMPv2-MIB::snmpInReadOnlys.0 = Counter32: 0
  SNMPv2-MIB::snmpInGenErrs.0 = Counter32: 0
  SNMPv2-MIB::snmpInTotalReqVars.0 = Counter32: 0
  SNMPv2-MIB::snmpInTotalSetVars.0 = Counter32: 0
  SNMPv2-MIB::snmpInGetRequests.0 = Counter32: 0
  SNMPv2-MIB::snmpInGetNexts.0 = Counter32: 0
  SNMPv2-MIB::snmpInGetResponses.0 = Counter32: 0
  SNMPv2-MIB::snmpInTraps.0 = Counter32: 0
  SNMPv2-MIB::snmpOutTooBigs.0 = Counter32: 0
  SNMPv2-MIB::snmpOutNoSuchNames.0 = Counter32: 0
  SNMPv2-MIB::snmpOutBadValues.0 = Counter32: 0
  SNMPv2-MIB::snmpOutGenErrs.0 = Counter32: 0
  SNMPv2-MIB::snmpOutSetRequests.0 = Counter32: 0
  SNMPv2-MIB::snmpOutGetResponses.0 = Counter32: 0
  SNMPv2-MIB::snmpOutTraps.0 = Counter32: 0
  SNMPv2-MIB::snmpEnableAuthenTraps.0 = INTEGER: enabled(1)
  SNMPv2-MIB::snmpSilentDrops.0 = Counter32: 0
  SNMPv2-MIB::snmpProxyDrops.0 = Counter32: 0
  
  </code></pre>
  
  <p>So for getting the same output for context name what change I should take care</p>