def setElement (self, trxContext, keyPath, newValue): self._log("set-element").debug2("called. trxContext=%s, keyPath=%s, newValue=%s", trxContext, keyPath, newValue) entryName = keyPath.getAt(keyPath.getLen()-2).asString() valLeafTag = keyPath.getAt(keyPath.getLen()-1).asXmlTag() self._log("set-element-details").debug2("read details: entry-name=%s, valLeafTag=%s. trxContext=%s, keyPath=%s, newValue=%s", entryName, valLeafTag, trxContext, keyPath, newValue) doWrite = False tagValueList = TagValues() if valLeafTag[0] == "contact": valContact = Value() valContact.setString(newValue.asString()) tagValueList.push(("sysContact", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valContact) doWrite = True elif valLeafTag[0] == "location": valLocation = Value() valLocation.setString(newValue.asString()) tagValueList.push(("sysLocation", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valLocation) doWrite = True if doWrite: res = self._maapiDomain.writeMaapi(tagValueList, self._keyPathSnmpV2, trxContext) if res != ReturnCodes.kOk: self._log('set-element-domain-failed').error('self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError return ReturnCodes.kOk
def _internalRead (self, show, readAllOrFail, trxContext): self.myInitGuard.isInitOrCrash() for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail) if readAllOrFail: self._clearAllReadData() tagValueList = TagValues() res = self._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS') return ReturnCodes.kGeneralError keyPath = self._getSelfKeyPath(show, None) res = self.domain.readMaapi(tagValueList, keyPath, trxContext) if res != ReturnCodes.kOk: for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS') return ReturnCodes.kGeneralError res = self._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS') return ReturnCodes.kGeneralError for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail) return ReturnCodes.kOk
def _internalWrite (self, show, trxContext): self.myInitGuard.isInitOrCrash() for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS') tagValueList = TagValues() res = self._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS') return ReturnCodes.kGeneralError itemsToDelete = [] res = self._collectItemsToDelete(show, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS') return ReturnCodes.kGeneralError keyPath = self._getSelfKeyPath(show, None) res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS') return ReturnCodes.kOk
def setVersionInTargetParamTableEntry (self, trxContext, entryName, snmpVersion): """ sets the entry with the entryName in SNMP-TARGET-MIB snmpTargetParamsTable snmpTargetParamsEntry set snmpTargetParamsMPModel to 0 (v1) or 1 (v2c) set snmpTargetParamsSecurityModel to 1 (v1) or 2 (v2c) """ self._log("set-version-in-target-param-table-entry").debug2("called. trxContext=%s, entryName=%s, snmpVersion=%s", trxContext, entryName, snmpVersion) targetKeyPath = KeyPath() valTarget = Value() (tag, ns, prefix) = ("SNMP-TARGET-MIB", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTarget.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valTarget) valTargetParamTable = Value() (tag, ns, prefix) = ("snmpTargetParamsTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetParamTable.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valTargetParamTable) valEntry = Value() (tag, ns, prefix) = ("snmpTargetParamsEntry", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valEntry.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valEntry) valKey = Value() valKey.setString(entryName) targetKeyPath.addKeyPathPostfix(valKey) tagValueList = TagValues() valMPModel = Value() # snmpTargetParamsMPModel to 0 (v1) or 1 (v2c) if snmpVersion == SnmpNotificationVersionType.kV1: valMPModel.setInt32(self.MP_MODEL_V1) elif snmpVersion == SnmpNotificationVersionType.kV2c: valMPModel.setInt32(self.MP_MODEL_V2C) tagValueList.push(("snmpTargetParamsMPModel", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valMPModel) # snmpTargetParamsSecurityModel to 1 (v1) valSecurityModel = Value() if snmpVersion == SnmpNotificationVersionType.kV1: valSecurityModel.setInt32(self.SECURITY_MODEL_V1) elif snmpVersion == SnmpNotificationVersionType.kV2c: valSecurityModel.setInt32(self.SECURITY_MODEL_V2C) tagValueList.push(("snmpTargetParamsSecurityModel", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valSecurityModel) res = self._maapiDomain.writeMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('create-target-param-table-entry-write-domain-failed').error('self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError self._log("set-version-in-target-param-table-entry-done").debug2("done. trxContext=%s, entryName=%s, snmpVersion=%s", trxContext, entryName, snmpVersion) return ReturnCodes.kOk
def replyObject (self, dpTrxCtx, keyPath, operData): for logFunc in self._log("reply-object").debug3Func(): logFunc("called. dpTrxCtx=%s, operData=%s, keyPath=%s", dpTrxCtx, operData.debugStr(True), keyPath) tagValueList = TagValues() res = self.fillTagValues(keyPath, tagValueList, operData) if res != ReturnCodes.kOk: for logFunc in self._log("reply-object-fill-tag-values-failed").errorFunc(): logFunc( "fillTagValues() failed. operData=%s, keyPath=%s", operData.debugStr(True), keyPath) return ReturnCodes.kGeneralError res = self.myDomain.sendTagValues(dpTrxCtx, tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log("reply-object-send-tag-values-failed").errorFunc(): logFunc( "myDomain.sendTagValues() failed. operData=%s, keyPath=%s", operData.debugStr(True), keyPath) return ReturnCodes.kGeneralError return ReturnCodes.kOk
def getCommunityName(self, trxContext, entryName): self._log("get-community-name").debug2( "called. trxContext=%s, entryName=%s", trxContext, entryName) tagValueList = TagValues() valCommName = Value() tagValueList.push( ("snmpCommunityName", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z"), valCommName) targetKeyPath = KeyPath() valCommunity = Value() (tag, ns, prefix) = ( "SNMP-COMMUNITY-MIB", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z", "SNMP_COMMUNITY_MIB") valCommunity.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valCommunity) valCommunityTable = Value() (tag, ns, prefix) = ( "snmpCommunityTable", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z", "SNMP_COMMUNITY_MIB") valCommunityTable.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valCommunityTable) valEntry = Value() (tag, ns, prefix) = ( "snmpCommunityEntry", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z", "SNMP_COMMUNITY_MIB") valEntry.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valEntry) valKey = Value() valKey.setBuf((entryName, len(entryName))) targetKeyPath.addKeyPathPostfix(valKey) res = self._maapiDomain.readMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('get-community-name-domain-failed').error( 'self._maapiDomain.readMaapi() failed. PARAMS') return None communityName = tagValueList.getAt(tagValueList.getLen() - 1)[1].asBuf() self._log("get-community-name-done").debug2( "done. trxContext=%s, entryName=%s, communityName=%s", trxContext, entryName, communityName) return communityName
def setElement(self, trxContext, keyPath, newValue): self._log("set-element").debug2( "called. trxContext=%s, keyPath=%s, newValue=%s", trxContext, keyPath, newValue) entryName = keyPath.getAt(keyPath.getLen() - 2).asString() valLeafTag = keyPath.getAt(keyPath.getLen() - 1).asXmlTag() self._log("set-element-details").debug2( "read details: entry-name=%s, valLeafTag=%s. trxContext=%s, keyPath=%s, newValue=%s", entryName, valLeafTag, trxContext, keyPath, newValue) doWrite = False tagValueList = TagValues() if valLeafTag[0] == "contact": valContact = Value() valContact.setString(newValue.asString()) tagValueList.push( ("sysContact", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valContact) doWrite = True elif valLeafTag[0] == "location": valLocation = Value() valLocation.setString(newValue.asString()) tagValueList.push( ("sysLocation", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valLocation) doWrite = True if doWrite: res = self._maapiDomain.writeMaapi(tagValueList, self._keyPathSnmpV2, trxContext) if res != ReturnCodes.kOk: self._log('set-element-domain-failed').error( 'self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError return ReturnCodes.kOk
def readSnmpCounters(self, operData): self._log("read-snmp-counters").debug3("called. operData=%s", operData) tagValueList = TagValues() if operData.isInPacketsRequested(): posValInPkts = tagValueList.getLen() valInPkts = Value() tagValueList.push( ("snmpInPkts", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInPkts) if operData.isInBadVersionPacketsRequested(): posValInBadVersions = tagValueList.getLen() valInBadVersions = Value() tagValueList.push( ("snmpInBadVersions", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInBadVersions) if operData.isInBadCommunityPacketsRequested(): posValInBadCommunityNames = tagValueList.getLen() valInBadCommunityNames = Value() tagValueList.push( ("snmpInBadCommunityNames", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInBadCommunityNames) if operData.isInBadCommunityUsePacketsRequested(): posValInBadCommunityUses = tagValueList.getLen() valInBadCommunityUses = Value() tagValueList.push( ("snmpInBadCommunityUses", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInBadCommunityUses) if operData.isInAsnParseErrorsRequested(): posValInASNParseErrs = tagValueList.getLen() valInASNParseErrs = Value() tagValueList.push( ("snmpInASNParseErrs", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInASNParseErrs) if operData.isSilentDroppedPacketsRequested(): posValSilentDrops = tagValueList.getLen() valSilentDrops = Value() tagValueList.push( ("snmpSilentDrops", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valSilentDrops) res = self._maapiDomain.readMaapi(tagValueList, self.targetKeyPath, None) if res != ReturnCodes.kOk: self._log('read-snmp-counters-domain-failed').error( 'self._maapiDomain.readMaapi() failed. operData=%s', operData) return None if operData.isInPacketsRequested(): operData.setInPackets( tagValueList.getAt(posValInPkts)[1].asUint32()) if operData.isInBadVersionPacketsRequested(): self._log("read-snmp-counters-got-in-bad-version").debug3( "got snmpInBadVersions=%s", tagValueList.getAt(posValInBadVersions)[1]) operData.setInBadVersionPackets( tagValueList.getAt(posValInBadVersions)[1].asUint32()) if operData.isInBadCommunityPacketsRequested(): operData.setInBadCommunityPackets( tagValueList.getAt(posValInBadCommunityNames)[1].asUint32()) if operData.isInBadCommunityUsePacketsRequested(): operData.setInBadCommunityUsePackets( tagValueList.getAt(posValInBadCommunityUses)[1].asUint32()) if operData.isInAsnParseErrorsRequested(): operData.setInAsnParseErrors( tagValueList.getAt(posValInASNParseErrs)[1].asUint32()) if operData.isSilentDroppedPacketsRequested(): operData.setSilentDroppedPackets( tagValueList.getAt(posValSilentDrops)[1].asUint32()) self._log("read-snmp-counters-done").debug3("returning: operData=%s", operData) return ReturnCodes.kOk
def createSecToGroupTableEntry (self, trxContext, securityModel, securityName): self._log("create-sec-to-group-table-entry").debug2("called. trxContext=%s, securityModel=%s, securityName=%s", trxContext, securityModel, securityName) """ create an entry with the securityName in SNMP-VIEW-BASED-ACM-MIB vacmSecurityToGroupTable vacmSecurityToGroupEntry set vacmSecurityModel to securityModel set vacmSecurityName to securityName set vacmGroupName to notif-only """ self._log("create-sec-to-group-table-entry").debug2("called. trxContext=%s, securityModel=%s, securityName=%s", trxContext, securityModel, securityName) targetKeyPath = KeyPath() valVacm = Value() (tag, ns, prefix) = ("SNMP-VIEW-BASED-ACM-MIB", "http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z", "SNMP_VIEW_BASED_ACM_MIB") valVacm.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valVacm) tagValueList = TagValues() valVacmSecToGroupTable = Value() (tag, ns, prefix) = ("vacmSecurityToGroupTable", "http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z", "SNMP_VIEW_BASED_ACM_MIB") valVacmSecToGroupTable.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valVacmSecToGroupTable) valBegin = Value() (tag, ns, prefix) = ("vacmSecurityToGroupEntry", "http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z", "SNMP_VIEW_BASED_ACM_MIB") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKeyModel = Value() valKeyModel.setInt32(securityModel) tagValueList.push(("vacmSecurityModel", "http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z"), valKeyModel) valKeySecName = Value() valKeySecName.setString(securityName) tagValueList.push(("vacmSecurityName", "http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z"), valKeySecName) # vacmGroupName to notif-only valGroupName = Value() valGroupName.setString(self.AC_NOTIF_ONLY) tagValueList.push(("vacmGroupName", "http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z"), valGroupName) valEnd = Value() valEnd.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valEnd) valTargetParamTable = Value() (tag, ns, prefix) = ("vacmSecurityToGroupTable","http://tail-f.com/ns/mibs/SNMP-VIEW-BASED-ACM-MIB/200210160000Z", "SNMP_VIEW_BASED_ACM_MIB") valTargetParamTable.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetParamTable) res = self._maapiDomain.writeMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('create-sec-to-group-table-entry-write-domain-failed').error('self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError self._log("create-sec-to-group-table-entry-done").debug2("done. trxContext=%s, securityModel=%s, securityName=%s", trxContext, securityModel, securityName) return ReturnCodes.kOk
def createTargetParamTableEntry (self, trxContext, entryName): """ create an entry with the entryName in SNMP-TARGET-MIB snmpTargetParamsTable snmpTargetParamsEntry set snmpTargetParamsMPModel to 0 (v1) set snmpTargetParamsSecurityModel to 1 (v1) set snmpTargetParamsSecurityName to _<entryName>_notif set snmpTargetParamsSecurityLevel to noAuthNoPriv """ self._log("create-target-param-table-entry").debug2("called. trxContext=%s, entryName=%s", trxContext, entryName) targetKeyPath = KeyPath() valTarget = Value() (tag, ns, prefix) = ("SNMP-TARGET-MIB", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTarget.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valTarget) tagValueList = TagValues() valTargetParamTable = Value() (tag, ns, prefix) = ("snmpTargetParamsTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetParamTable.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetParamTable) valBegin = Value() (tag, ns, prefix) = ("snmpTargetParamsEntry", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKey = Value() valKey.setString(entryName) tagValueList.push(("snmpTargetParamsName", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valKey) # snmpTargetParamsMPModel to 0 (v1) valMPModel = Value() valMPModel.setInt32(self.MP_MODEL_V1) tagValueList.push(("snmpTargetParamsMPModel", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valMPModel) # snmpTargetParamsSecurityModel to 1 (v1) valSecurityModel = Value() valSecurityModel.setInt32(self.SECURITY_MODEL_V1) tagValueList.push(("snmpTargetParamsSecurityModel", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valSecurityModel) # snmpTargetParamsSecurityName to all-traps valSecurityName = Value() valSecurityName.setString(self.makeSecurityName(entryName)) tagValueList.push(("snmpTargetParamsSecurityName", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valSecurityName) # snmpTargetParamsSecurityLevel to noAuthNoPriv valSecurityLevel = Value() valSecurityLevel.setEnum(self.SECURITY_LEVEL_NO_AUTH_NO_PRIV) tagValueList.push(("snmpTargetParamsSecurityLevel", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valSecurityLevel) valEnd = Value() valEnd.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valEnd) valTargetParamTable = Value() (tag, ns, prefix) = ("snmpTargetParamsTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetParamTable.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetParamTable) res = self._maapiDomain.writeMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('create-target-param-table-entry-write-domain-failed').error('self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError self._log("create-target-param-table-entry-done").debug2("done. trxContext=%s, entryName=%s", trxContext, entryName) return ReturnCodes.kOk
def createTargetAddrTableEntry (self, trxContext, entryName): """ create an entry with the same name in SNMP-TARGET-MIB snmpTargetAddrTable snmpTargetAddrEntry set snmpTargetAddrTDomain to 1.3.6.1.6.1.1 set snmpTargetAddrTAddress to 0.0.0.0.0.162 set snmpTargetAddrTagList to the same name set snmpTargetAddrParams to the same name set snmpTargetAddrMMS to 2048 """ self._log("create-target-addr-table-entry").debug2("called. trxContext=%s, entryName=%s", trxContext, entryName) targetKeyPath = KeyPath() valTarget = Value() (tag, ns, prefix) = ("SNMP-TARGET-MIB", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTarget.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valTarget) tagValueList = TagValues() valTargetAddrTable = Value() (tag, ns, prefix) = ("snmpTargetAddrTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetAddrTable.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetAddrTable) valBegin = Value() (tag, ns, prefix) = ("snmpTargetAddrEntry", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKey = Value() valKey.setString(entryName) tagValueList.push(("snmpTargetAddrName", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valKey) # snmpTargetAddrTDomain to 1.3.6.1.6.1.1 valTDomain = Value() valTDomain.setOid(self.T_DOMAIN_UDP_ADDR) tagValueList.push(("snmpTargetAddrTDomain", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valTDomain) # snmpTargetAddrTAddress to 0.0.0.0.0.162 valTAddr = Value() #addrStr = chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(162) addrStr = chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(162) valTAddr.setBinary(addrStr) tagValueList.push(("snmpTargetAddrTAddress", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valTAddr) # snmpTargetAddrTagList to the same name valTagName = Value() valTagName.setString(self.ALL_TRAPS_TAG_NAME) tagValueList.push(("snmpTargetAddrTagList", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valTagName) # snmpTargetAddrParams to the same name valParamName = Value() valParamName.setString(entryName) tagValueList.push(("snmpTargetAddrParams", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valParamName) # snmpTargetAddrMMS to 2048 valMMS = Value() valMMS.setInt32(self.MAX_MESSAGE_SIZE) tagValueList.push(("snmpTargetAddrMMS", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valMMS) valEnd = Value() valEnd.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valEnd) valTargetAddrTable = Value() (tag, ns, prefix) = ("snmpTargetAddrTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetAddrTable.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetAddrTable) res = self._maapiDomain.writeMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('create-target-addr-table-entry-write-domain-failed').error('self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError self._log("create-target-addr-table-entry-done").debug2("done. trxContext=%s, entryName=%s", trxContext, entryName) return ReturnCodes.kOk
def getDestinationInTargetTableEntry (self, trxContext, entryName): self._log("get-destination-in-target-table-entry").debug2("called. trxContext=%s, entryName=%s", trxContext, entryName) targetKeyPath = KeyPath() valTarget = Value() (tag, ns, prefix) = ("SNMP-TARGET-MIB", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTarget.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valTarget) tagValueList = TagValues() valTargetAddrTable = Value() (tag, ns, prefix) = ("snmpTargetAddrTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetAddrTable.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetAddrTable) valBegin = Value() (tag, ns, prefix) = ("snmpTargetAddrEntry", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKey = Value() valKey.setString(entryName) tagValueList.push(("snmpTargetAddrName", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valKey) valTAddr = Value() tagValueList.push(("snmpTargetAddrTAddress", "http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"), valTAddr) valEnd = Value() valEnd.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valEnd) valTargetAddrTable = Value() (tag, ns, prefix) = ("snmpTargetAddrTable","http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z", "SNMP_TARGET_MIB") valTargetAddrTable.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valTargetAddrTable) res = self._maapiDomain.readMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('get-destination-in-target-table-entry-read-domain-failed').error('self._maapiDomain.writeMaapi() failed. PARAMS') return None ipAddress = tagValueList.getAt(tagValueList.getLen()-3)[1].asBinary()[0:6] self._log("get-destination-in-target-table-entry-done").debug2("done. trxContext=%s, entryName=%s, ipAddress=%s", trxContext, entryName, ipAddress) return ipAddress
def readSnmpCounters (self, operData): self._log("read-snmp-counters").debug3("called. operData=%s", operData) tagValueList = TagValues() if operData.isInPacketsRequested(): posValInPkts = tagValueList.getLen() valInPkts = Value() tagValueList.push(("snmpInPkts", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInPkts) if operData.isInBadVersionPacketsRequested(): posValInBadVersions = tagValueList.getLen() valInBadVersions = Value() tagValueList.push(("snmpInBadVersions", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInBadVersions) if operData.isInBadCommunityPacketsRequested(): posValInBadCommunityNames = tagValueList.getLen() valInBadCommunityNames = Value() tagValueList.push(("snmpInBadCommunityNames", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInBadCommunityNames) if operData.isInBadCommunityUsePacketsRequested(): posValInBadCommunityUses = tagValueList.getLen() valInBadCommunityUses = Value() tagValueList.push(("snmpInBadCommunityUses", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInBadCommunityUses) if operData.isInAsnParseErrorsRequested(): posValInASNParseErrs = tagValueList.getLen() valInASNParseErrs = Value() tagValueList.push(("snmpInASNParseErrs", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valInASNParseErrs) if operData.isSilentDroppedPacketsRequested(): posValSilentDrops = tagValueList.getLen() valSilentDrops = Value() tagValueList.push(("snmpSilentDrops", "http://tail-f.com/ns/mibs/SNMPv2-MIB/200210160000Z"), valSilentDrops) res = self._maapiDomain.readMaapi(tagValueList, self.targetKeyPath, None) if res != ReturnCodes.kOk: self._log('read-snmp-counters-domain-failed').error('self._maapiDomain.readMaapi() failed. operData=%s', operData) return None if operData.isInPacketsRequested(): operData.setInPackets(tagValueList.getAt(posValInPkts)[1].asUint32()) if operData.isInBadVersionPacketsRequested(): self._log("read-snmp-counters-got-in-bad-version").debug3("got snmpInBadVersions=%s", tagValueList.getAt(posValInBadVersions)[1]) operData.setInBadVersionPackets(tagValueList.getAt(posValInBadVersions)[1].asUint32()) if operData.isInBadCommunityPacketsRequested(): operData.setInBadCommunityPackets(tagValueList.getAt(posValInBadCommunityNames)[1].asUint32()) if operData.isInBadCommunityUsePacketsRequested(): operData.setInBadCommunityUsePackets(tagValueList.getAt(posValInBadCommunityUses)[1].asUint32()) if operData.isInAsnParseErrorsRequested(): operData.setInAsnParseErrors(tagValueList.getAt(posValInASNParseErrs)[1].asUint32()) if operData.isSilentDroppedPacketsRequested(): operData.setSilentDroppedPackets(tagValueList.getAt(posValSilentDrops)[1].asUint32()) self._log("read-snmp-counters-done").debug3("returning: operData=%s", operData) return ReturnCodes.kOk
def createEntry(self, trxContext, entryName, communityName, securityName): self._log("create-entry").debug2( "called. trxContext=%s, entryName=%s, communityName=%s, securityName=%s", trxContext, entryName, communityName, securityName) # create an entry in SNMP-COMMUNITY-MIB snmpCommunityTable snmpCommunityEntry # set snmpCommunityCommunityName to communityName # set snmpCommunitySecurityName to securityName targetKeyPath = KeyPath() valCommunity = Value() (tag, ns, prefix) = ( "SNMP-COMMUNITY-MIB", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z", "SNMP_COMMUNITY_MIB") valCommunity.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valCommunity) valCommunityTable = Value() (tag, ns, prefix) = ( "snmpCommunityTable", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z", "SNMP_COMMUNITY_MIB") valCommunityTable.setXmlTag((tag, ns, prefix)) targetKeyPath.addKeyPathPostfix(valCommunityTable) tagValueList = TagValues() valBegin = Value() (tag, ns, prefix) = ( "snmpCommunityEntry", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z", "SNMP_COMMUNITY_MIB") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKey = Value() valKey.setBuf((entryName, len(entryName))) tagValueList.push( ("snmpCommunityIndex", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z"), valKey) valCommunityName = Value() valCommunityName.setString(communityName) tagValueList.push( ("snmpCommunityName", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z"), valCommunityName) valSecurityName = Value() valSecurityName.setString(securityName) tagValueList.push( ("snmpCommunitySecurityName", "http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z"), valSecurityName) valEnd = Value() valEnd.setXmlEnd((tag, ns, prefix)) tagValueList.push((tag, ns), valEnd) res = self._maapiDomain.writeMaapi(tagValueList, targetKeyPath, trxContext) if res != ReturnCodes.kOk: self._log('create-entry-write-domain-failed').error( 'self._maapiDomain.writeMaapi() failed. PARAMS') return ReturnCodes.kGeneralError return ReturnCodes.kOk