def cfgNtfOrg(self, authData, transportTarget, notifyType): addrName, paramsName = self.cfgCmdGen(authData, transportTarget) tagList = transportTarget.tagList.split() if not tagList: tagList = [''] for tag in tagList: k = paramsName, tag, notifyType if k in self.__knownNotifyNames: notifyName, _ = self.__knownNotifyNames[k] else: notifyName = 'n%s' % nextID() config.addNotificationTarget(self.snmpEngine, notifyName, paramsName, tag, notifyType) self.__knownNotifyNames[k] = notifyName, paramsName k = (authData.securityModel, authData.securityName, authData.securityLevel) if k not in self.__knownAuths: subTree = (1, 3, 6) config.addTrapUser(self.snmpEngine, authData.securityModel, authData.securityName, authData.securityLevel, subTree) self.__knownAuths[k] = subTree if self.snmpContext is None: self.snmpContext = context.SnmpContext(self.snmpEngine) config.addContext( self.snmpEngine, '' # this is leaky ) return notifyName
def cfgNtfOrg(self, snmpEngine, authData, transportTarget, notifyType): cache = self._getNtfCache(snmpEngine) addrName, paramsName = self.cfgCmdGen(snmpEngine, authData, transportTarget) tagList = transportTarget.tagList.split() if not tagList: tagList = [''] for tag in tagList: notifyNameKey = paramsName, tag, notifyType if notifyNameKey in cache['name']: notifyName, paramsName, useCount = cache['name'][notifyNameKey] cache['name'][ notifyNameKey] = notifyName, paramsName, useCount + 1 else: notifyName = 'n%s' % nextID() config.addNotificationTarget(snmpEngine, notifyName, paramsName, tag, notifyType) cache['name'][notifyNameKey] = notifyName, paramsName, 1 authDataKey = authData.securityName, authData.securityModel if authDataKey in cache['auth']: authDataX, subTree, useCount = cache['auth'][authDataKey] cache['auth'][authDataKey] = authDataX, subTree, useCount + 1 else: subTree = (1, 3, 6) config.addTrapUser(snmpEngine, authData.securityModel, authData.securityName, authData.securityLevel, subTree) cache['auth'][authDataKey] = authData, subTree, 1 return notifyName
def cfgNtfOrg(self, authData, transportTarget, notifyType, tagList): addrName, paramsName = self.cfgCmdGen( authData, transportTarget, tagList ) k = paramsName, tagList, notifyType if self.__knownNotifyNames.has_key(k): notifyName, _ = self.__knownNotifyNames[k] else: notifyName = 'n%s' % cmdgen.nextID() config.addNotificationTarget( self.snmpEngine, notifyName, paramsName, tagList, notifyType ) self.__knownNotifyNames[k] = notifyName, paramsName if not self.__knownAuths.has_key(authData): subTree = (1,3,6) config.addTrapUser( self.snmpEngine, authData.securityModel, authData.securityName, authData.securityLevel, subTree ) self.__knownAuths[authData] = subTree if self.snmpContext is None: self.snmpContext = context.SnmpContext(self.snmpEngine) config.addContext( self.snmpEngine, '' # this is leaky ) return notifyName
def configure(self, snmpEngine, authData, transportTarget, notifyType): cache = self._getCache(snmpEngine) # Create matching transport tags if not given by user. Not good! if not transportTarget.tagList: transportTarget.tagList = str( hash((authData.securityName, transportTarget.transportAddr)) ) if isinstance(authData, CommunityData) and not authData.tag: authData.tag = transportTarget.tagList.split()[0] addrName, paramsName = self._cmdGenLcdCfg.configure(snmpEngine, authData, transportTarget) tagList = transportTarget.tagList.split() if not tagList: tagList = [''] for tag in tagList: notifyNameKey = paramsName, tag, notifyType if notifyNameKey in cache['name']: notifyName, paramsName, useCount = cache['name'][notifyNameKey] cache['name'][notifyNameKey] = notifyName, paramsName, useCount + 1 else: notifyName = 'n%s' % self.nextID() config.addNotificationTarget( snmpEngine, notifyName, paramsName, tag, notifyType ) cache['name'][notifyNameKey] = notifyName, paramsName, 1 authDataKey = authData.securityName, authData.securityModel if authDataKey in cache['auth']: authDataX, subTree, useCount = cache['auth'][authDataKey] cache['auth'][authDataKey] = authDataX, subTree, useCount + 1 else: subTree = (1,3,6) config.addTrapUser( snmpEngine, authData.securityModel, authData.securityName, authData.securityLevel, subTree ) cache['auth'][authDataKey] = authData, subTree, 1 return notifyName
def cfgNtfOrg(self, authData, transportTarget, notifyType): addrName, paramsName = self.cfgCmdGen(authData, transportTarget) tagList = transportTarget.tagList.split() if not tagList: tagList = [''] for tag in tagList: notifyNameKey = paramsName, tag, notifyType if notifyNameKey in self.__knownNotifyNames: notifyName, paramsName, useCount = self.__knownNotifyNames[notifyNameKey] self.__knownNotifyNames[notifyNameKey] = notifyName, paramsName, useCount + 1 else: notifyName = 'n%s' % nextID() config.addNotificationTarget( self.snmpEngine, notifyName, paramsName, tag, notifyType ) self.__knownNotifyNames[notifyNameKey] = notifyName, paramsName, 1 authDataKey = authData.securityName, authData.securityModel if authDataKey in self.__knownAuths: authDataX, subTree, useCount = self.__knownAuths[authDataKey] self.__knownAuths[authDataKey] = authDataX, subTree, useCount + 1 else: subTree = (1,3,6) config.addTrapUser( self.snmpEngine, authData.securityModel, authData.securityName, authData.securityLevel, subTree ) self.__knownAuths[authDataKey] = authData, subTree, 1 if self.snmpContext is None: self.snmpContext = context.SnmpContext(self.snmpEngine) config.addContext( self.snmpEngine, '' # this is leaky ) return notifyName
def cfgNtfOrg(self, snmpEngine, authData, transportTarget, notifyType): cache = self._getNtfCache(snmpEngine) addrName, paramsName = self.cfgCmdGen( snmpEngine, authData, transportTarget ) tagList = transportTarget.tagList.split() if not tagList: tagList = [''] for tag in tagList: notifyNameKey = paramsName, tag, notifyType if notifyNameKey in cache['name']: notifyName, paramsName, useCount = cache['name'][notifyNameKey] cache['name'][notifyNameKey] = notifyName, paramsName, useCount + 1 else: notifyName = 'n%s' % nextID() config.addNotificationTarget( snmpEngine, notifyName, paramsName, tag, notifyType ) cache['name'][notifyNameKey] = notifyName, paramsName, 1 authDataKey = authData.securityName, authData.securityModel if authDataKey in cache['auth']: authDataX, subTree, useCount = cache['auth'][authDataKey] cache['auth'][authDataKey] = authDataX, subTree, useCount + 1 else: subTree = (1,3,6) config.addTrapUser( snmpEngine, authData.securityModel, authData.securityName, authData.securityLevel, subTree ) cache['auth'][authDataKey] = authData, subTree, 1 return notifyName
def sendTrap(self, version, enterprise, varList, community=False, destPort=False): if destPort: trapPort = destPort else: trapPort = TRAP_PORT if community: comm = community else: comm = DEFAULT_COMM snmpEngine = engine.SnmpEngine() # v1/2 setup config.addV1System(snmpEngine, TEST_AGENT, comm) # v3 setup config.addV3User(snmpEngine, TEST_USER, config.usmHMACMD5AuthProtocol, 'authKey1', config.usmDESPrivProtocol, 'privKey1') # Transport params config.addTargetParams(snmpEngine, PARAM, TEST_USER, AUTHPRIV) #config.addTargetParams(snmpEngine, 'myParams', 'test-agent', 'noAuthNoPriv', 0) # Transport addresses config.addTargetAddr(snmpEngine, NMS, config.snmpUDPDomain, (self.dataCollector, trapPort), PARAM, tagList='myManagementStations') # Notification targets config.addNotificationTarget( # snmpEngine, 'myNotifyName', 'myParams', 'myManagementStations', 'trap' snmpEngine, 'myNotifyName', PARAM, 'myManagementStations', 'inform') # Setup transport endpoint config.addSocketTransport(snmpEngine, udp.domainName, udp.UdpSocketTransport().openClientMode()) # Agent-side VACM setup config.addContext(snmpEngine, '') config.addTrapUser(snmpEngine, 1, 'test-agent', 'noAuthNoPriv', (1, 3, 6)) # v1 config.addTrapUser(snmpEngine, 2, 'test-agent', 'noAuthNoPriv', (1, 3, 6)) # v2c config.addTrapUser(snmpEngine, 3, 'test-user', 'authPriv', (1, 3, 6)) # v3 # SNMP context snmpContext = context.SnmpContext(snmpEngine) def cbFun(sendRequestHandle, errorIndication, cbCtx): if errorIndication: print errorIndication ntforg.NotificationOriginator(snmpContext).sendNotification( snmpEngine, 'myNotifyName', ('SNMPv2-MIB', 'coldStart'), (((1, 3, 6, 1, 2, 1, 1, 5), v2c.OctetString('Example Notificator')), ), cbFun) snmpEngine.transportDispatcher.runDispatcher()
colIdx = colIdx + 1 if val is None or not cbCtx['myHeadVars'][colIdx].isPrefixOf(oid): continue sys.stdout.write('%s\n' % cbCtx['mibViewProxy'].getPrettyOidVal( cbCtx['mibViewController'], oid, val)) inTableFlag = 1 if not inTableFlag: return # stop on end-of-table return 1 # continue walking snmpContext = context.SnmpContext(snmpEngine) # Agent-side VACM setup config.addContext(snmpEngine, '') config.addTrapUser(snmpEngine, 1, ctx['securityName'], 'noAuthNoPriv', (1, 3, 6)) # v1 config.addTrapUser(snmpEngine, 2, ctx['securityName'], 'noAuthNoPriv', (1, 3, 6)) # v2c config.addTrapUser(snmpEngine, 3, ctx['securityName'], 'authPriv', (1, 3, 6)) # v3 ctx['notificationName'] = 'myNotifyName' config.addNotificationTarget(snmpEngine, ctx['notificationName'], ctx['paramsName'], ctx['transportTag'], 'trap') ntforg.NotificationOriginator(snmpContext).sendNotification( snmpEngine, ctx['notificationName'], ('SNMPv2-MIB', ctx['GenericTrap']), ctx['varBinds'], cbFun, ctx) try: snmpEngine.transportDispatcher.runDispatcher()