Пример #1
0
def processCommandResponse(pluginId, snmpEngine, pdu, trunkMsg, reqCtx):
    varBinds = []

    for oid, val in v2c.apiPDU.getVarBinds(pdu):
        for oidPatt, valPatt, valRepl, replCount in rewriteList:
            if oidPatt.match(str(oid)):
                newVal = valPatt.sub(valRepl, str(val), replCount)
                if not newVal:
                    newVal = nullifyMap.get(val.tagSet, v2c.Null())
                val = val.clone(newVal)
                break

        varBinds.append((oid, val))

    v2c.apiPDU.setVarBinds(pdu, varBinds)

    return status.NEXT, pdu
Пример #2
0
# PDU v1/v2c two-way proxy
from pysnmp.proto import rfc1905, rfc3411, error
from pysnmp.proto.api import v1, v2c
from pysnmp import debug

# 2.1.1

__v1ToV2ValueMap = {
    v1.Integer.tagSet: v2c.Integer32(),
    v1.OctetString.tagSet: v2c.OctetString(),
    v1.Null.tagSet: v2c.Null(),
    v1.ObjectIdentifier.tagSet: v2c.ObjectIdentifier(),
    v1.IpAddress.tagSet: v2c.IpAddress(),
    v1.Counter.tagSet: v2c.Counter32(),
    v1.Gauge.tagSet: v2c.Gauge32(),
    v1.TimeTicks.tagSet: v2c.TimeTicks(),
    v1.Opaque.tagSet: v2c.Opaque()
}

__v2ToV1ValueMap = {  # XXX do not re-create same-type items?
    v2c.Integer32.tagSet: v1.Integer(),
    v2c.OctetString.tagSet: v1.OctetString(),
    v2c.Null.tagSet: v1.Null(),
    v2c.ObjectIdentifier.tagSet: v1.ObjectIdentifier(),
    v2c.IpAddress.tagSet: v1.IpAddress(),
    v2c.Counter32.tagSet: v1.Counter(),
    v2c.Gauge32.tagSet: v1.Gauge(),
    v2c.TimeTicks.tagSet: v1.TimeTicks(),
    v2c.Opaque.tagSet: v1.Opaque()
}
Пример #3
0
                        for skip, begin, end in oidsList]

            # we use this for pivoting dichotomy search
            endOids = [x[2] for x in oidsList]

        except Exception:
            raise SnmpfwdError('%s: config file load failure: %s' %
                               (PLUGIN_NAME, sys.exc_info()[1]))

    elif optionName == 'log-denials':
        logDenials = optionValue == 'true'
        info('%s: will log denied OIDs' % PLUGIN_NAME)

info('%s: plugin initialization complete' % PLUGIN_NAME)

null = v2c.Null()
noSuchInstance = v2c.NoSuchInstance()
endOfMibView = v2c.EndOfMibView()


def formatDenialMsg(pdu, trunkMsg):
    denialMsg = '%s: callflow-id %s %s' % (
        PLUGIN_NAME, trunkMsg['callflow-id'], pdu.__class__.__name__)
    denialMsg += ' from %s:%s' % (trunkMsg['snmp-peer-address'],
                                  trunkMsg['snmp-peer-port'])
    denialMsg += ' at %s:%s' % (trunkMsg['snmp-bind-address'],
                                trunkMsg['snmp-bind-port'])
    return denialMsg


def findAcl(oid, nextOid=False):