Ejemplo n.º 1
0
 def setCmd(self, authData, transportTarget, varBinds, cbInfo):
     (cbFun, cbCtx) = cbInfo
     addrName, paramsName = self.cfgCmdGen(
         authData, transportTarget
         )
     __varBinds = []
     for varName, varVal in varBinds:
         name, oid = mibvar.mibNameToOid(
             self.mibViewController, varName
             )
         if not isinstance(varVal, base.AbstractSimpleAsn1Item):
             ((symName, modName), suffix) = mibvar.oidToMibName(
                 self.mibViewController, name + oid
                 )
             syntax = mibvar.cloneFromMibValue(
                 self.mibViewController, modName, symName, varVal
                 )
             if syntax is None:
                 raise error.PySnmpError(
                     'Value type MIB lookup failed for %r' % (varName,)
                     )
             varVal = syntax.clone(varVal)
         __varBinds.append((name + oid, varVal))
     return cmdgen.SetCommandGenerator().sendReq(
         self.snmpEngine, addrName, __varBinds, cbFun, cbCtx,
         authData.contextEngineId, authData.contextName
         )
    def __call__(self,
                 response_object,
                 destination,
                 table=False,
                 from_trap=False,
                 trap_metadata=None,
                 split_bulk_output=False,
                 mibView=None):
        splunkevent = ""

        #handle traps
        if from_trap:
            for oid, val in response_object:
                try:
                    (symName,
                     modName), indices = mibvar.oidToMibName(mibView, oid)
                    splunkevent += '%s::%s.%s =  ' % (
                        modName, symName, '.'.join(
                            [v.prettyPrint() for v in indices]))
                except:  # catch *all* exceptions
                    e = sys.exc_info()[1]
                    logging.error(
                        "Exception resolving MIB name in the caught trap: %s" %
                        str(e))
                    splunkevent += '%s =  ' % (oid)
                try:
                    decodedVal = mibvar.cloneFromMibValue(
                        mibView, modName, symName, val)
                    splunkevent += '%s ' % (decodedVal.prettyPrint())
                except:  # catch *all* exceptions
                    e = sys.exc_info()[1]
                    logging.error(
                        "Exception resolving MIB value in the caught trap: %s"
                        % str(e))
                    splunkevent += '%s ' % (val.prettyPrint())
            splunkevent = trap_metadata + splunkevent
            print_xml_single_instance_mode(destination, splunkevent)

        #handle tables
        elif table:
            for varBindTableRow in response_object:
                for name, val in varBindTableRow:
                    output_element = '%s = "%s" ' % (name.prettyPrint(),
                                                     val.prettyPrint())
                    if split_bulk_output:
                        print_xml_single_instance_mode(destination,
                                                       output_element)

                    else:
                        splunkevent += output_element
            print_xml_single_instance_mode(destination, splunkevent)
        #handle scalars
        else:
            for name, val in response_object:
                splunkevent += '%s = "%s" ' % (name.prettyPrint(),
                                               val.prettyPrint())
            print_xml_single_instance_mode(destination, splunkevent)
    def __call__(self, response_object,destination,table=False,from_trap=False,trap_metadata=None,split_bulk_output=False,mibView=None):
        splunkevent =""

        #handle traps
        if from_trap:
            for oid, val in response_object:
                try:
                    (symName, modName), indices = mibvar.oidToMibName(mibView, oid)
                    splunkevent +='%s::%s.%s =  ' % (modName, symName,'.'.join([ v.prettyPrint() for v in indices]))
                except: # catch *all* exceptions
                    e = sys.exc_info()[1]
                    splunkevent +='%s =  ' % (oid)
                try:
                    decodedVal = mibvar.cloneFromMibValue(mibView,modName,symName,val)
                    splunkevent +='%s ' % (decodedVal.prettyPrint())
                except: # catch *all* exceptions
                    e = sys.exc_info()[1]
                    splunkevent +='%s ' % (val.prettyPrint())
            splunkevent = trap_metadata + splunkevent
            print_xml_single_instance_mode(destination, splunkevent)

        #handle tables
        elif table:
            for varBindTableRow in response_object:
                for name, val in varBindTableRow:
                    output_element = '%s = "%s" ' % (name.prettyPrint(), val.prettyPrint())
                    if split_bulk_output:
                        print_xml_single_instance_mode(destination, output_element)

                    else:
                        splunkevent += output_element
            print_xml_single_instance_mode(destination, splunkevent)
        #handle scalars
        else:
            for name, val in response_object:
                output_element = '%s = "%s" ' % (name.prettyPrint(), val.prettyPrint())
                if split_bulk_output:
                    print_xml_single_instance_mode(destination, output_element)
                else:
                    splunkevent += output_element
            print_xml_single_instance_mode(destination, splunkevent)
Ejemplo n.º 4
0
    def sendNotification(
        self, authData, transportTarget, notifyType,
        notificationType, varBinds=None, cbInfo=(None, None)
        ):
        (cbFun, cbCtx) = cbInfo         
        tagList = str(transportTarget.transportAddr).replace(' ', '_')
        notifyName = self.cfgNtfOrg(authData, transportTarget,
                                    notifyType, tagList)
        if notificationType:
            name, oid = mibvar.mibNameToOid(
                self.mibViewController, notificationType
                )
            notificationType = name + oid
        if varBinds:
            __varBinds = []
            for varName, varVal in varBinds:
                name, oid = mibvar.mibNameToOid(
                    self.mibViewController, varName
                    )
                if not isinstance(varVal, base.Asn1ItemBase):
                    ((symName, modName), suffix) = mibvar.oidToMibName(
                        self.mibViewController, name + oid
                        )
                    syntax = mibvar.cloneFromMibValue(
                        self.mibViewController, modName, symName, varVal
                        )
                    if syntax is None:
                        raise error.PySnmpError(
                            'Value type MIB lookup failed for %r' % (varName,)
                            )
                    varVal = syntax.clone(varVal)
                __varBinds.append((name + oid, varVal))
        else:
            __varBinds = None

        return ntforg.NotificationOriginator(self.snmpContext).sendNotification(self.snmpEngine, notifyName, notificationType, __varBinds, cbFun, cbCtx)
Ejemplo n.º 5
0
        addrName, paramsName = self.cfgCmdGen(authData, transportTarget)
        varBinds = []
        for varName in varNames:
            name, oid = mibvar.mibNameToOid(self.mibViewController, varName)
            varBinds.append((name + oid, self._null))
        return cmdgen.GetCommandGenerator().sendReq(self.snmpEngine, addrName,
                                                    varBinds, cbFun, cbCtx)

    def asyncSetCmd(self, authData, transportTarget, varBinds, (cbFun, cbCtx)):
        addrName, paramsName = self.cfgCmdGen(authData, transportTarget)
        __varBinds = []
        for varName, varVal in varBinds:
            name, oid = mibvar.mibNameToOid(self.mibViewController, varName)
            if not type(varVal) == types.InstanceType:
                ((symName, modName),
                 suffix) = mibvar.oidToMibName(self.mibViewController,
                                               name + oid)
                syntax = mibvar.cloneFromMibValue(self.mibViewController,
                                                  modName, symName, varVal)
                if syntax is None:
                    raise error.PySnmpError(
                        'Value type MIB lookup failed for %s' % repr(varName))
                varVal = syntax.clone(varVal)
            __varBinds.append((name + oid, varVal))
        return cmdgen.SetCommandGenerator().sendReq(self.snmpEngine, addrName,
                                                    __varBinds, cbFun, cbCtx)

    def asyncNextCmd(self, authData, transportTarget, varNames, (cbFun,
                                                                 cbCtx)):
        addrName, paramsName = self.cfgCmdGen(authData, transportTarget)
        varBinds = []
        for varName in varNames:
Ejemplo n.º 6
0
            )

    def asyncSetCmd(
        self, authData, transportTarget, varBinds, (cbFun, cbCtx)
        ):
        addrName, paramsName = self.cfgCmdGen(
            authData, transportTarget
            )
        __varBinds = []
        for varName, varVal in varBinds:
            name, oid = mibvar.mibNameToOid(
                self.mibViewController, varName
                )
            if not type(varVal) == types.InstanceType:
                ((symName, modName), suffix) = mibvar.oidToMibName(
                    self.mibViewController, name + oid
                    )
                syntax = mibvar.cloneFromMibValue(
                    self.mibViewController, modName, symName, varVal
                    )
                if syntax is None:
                    raise error.PySnmpError(
                        'Value type MIB lookup failed for %s' % repr(varName)
                        )
                varVal = syntax.clone(varVal)
            __varBinds.append((name + oid, varVal))
        return cmdgen.SetCommandGenerator().sendReq(
            self.snmpEngine, addrName, __varBinds, cbFun, cbCtx
            )
        
    def asyncNextCmd(
Ejemplo n.º 7
0
#    (('TCP-MIB', ''),),
    (('SNMPv2-MIB', ''),),
#    (('IF-MIB', ''),),
#    (('', 'interfaces'),),
#    (1,3,6,1,2,1)
#    (('','system'),)
    )

if errorIndication:
    print errorIndication
else:
    if errorStatus:
        print '%s at %s\n' % (
            errorStatus.prettyPrint(),
            varBindTable[-1][int(errorIndex)-1]
            )
    else:
        for varBindTableRow in varBindTable:
            for oid, val in varBindTableRow:
                (symName, modName), indices = mibvar.oidToMibName(
                    cmdGen.mibViewController, oid
                    )
                val = mibvar.cloneFromMibValue(
                    cmdGen.mibViewController, modName, symName, val
                    )
                print '%s::%s.%s = %s' % (
                    modName, symName,
                    string.join(map(lambda v: v.prettyPrint(), indices), '.'),
                    val.prettyPrint()
                    )