def _from_pdu_v2c(host, proto_module, version, pdu): varbinds = [] trapoid = None trap_type = "trap2" request_id = proto_module.apiTrapPDU.getRequestID(pdu).prettyPrint() # Need to do initial loop to pull out trapoid for oid, val in proto_module.apiPDU.getVarBindList(pdu): oid = oid.prettyPrint() val = val.getComponentByName("value").getComponent().getComponent() pval = val.prettyPrint() if oid == SNMP_TRAP_OID: trapoid = pval continue varbinds.append((oid, ASN_TO_NAME_MAP.get(val.__class__, "octet"), pval)) if not trapoid: return now = utcnow() trunc_now = now.replace(minute=now.minute / 10 * 10).strftime("%Y%m%d%H%M") trap = Notification( host=host, sent=now, trunc_sent=trunc_now, trap_type=trap_type, request_id=request_id, version=version, oid=trapoid) for oid, val_type, val in varbinds: trap.varbinds.append(VarBind(oid=oid, value_type=val_type, value=val)) return trap
def _from_pdu_v1(host, proto_module, version, pdu): trapoid = str(proto_module.apiTrapPDU.getEnterprise(pdu)) generic = int(proto_module.apiTrapPDU.getGenericTrap(pdu)) specific = int(proto_module.apiTrapPDU.getSpecificTrap(pdu)) if generic == 6: # Enterprise Specific Traps trapoid = "%s.0.%s" % (trapoid, specific) else: trapoid = "%s.%s" % (trapoid, generic + 1) trap_type = "trap" # v1 doesn't have request_id. Use timestamp in it's place. request_id = int(proto_module.apiTrapPDU.getTimeStamp(pdu)) now = utcnow() trunc_now = now.replace(minute=now.minute / 10 * 10).strftime("%Y%m%d%H%M") trap = Notification(host=host, sent=now, trunc_sent=trunc_now, trap_type=trap_type, request_id=request_id, version=version, oid=trapoid) for oid, val in proto_module.apiTrapPDU.getVarBinds(pdu): oid = oid.prettyPrint() pval = val.prettyPrint() val_type = ASN_TO_NAME_MAP.get(val.__class__, "octet") trap.varbinds.append( VarBind(oid=oid, value_type=val_type, value=pval)) return trap
def _from_pdu_v1(host, proto_module, version, pdu): trapoid = str(proto_module.apiTrapPDU.getEnterprise(pdu)) generic = int(proto_module.apiTrapPDU.getGenericTrap(pdu)) specific = int(proto_module.apiTrapPDU.getSpecificTrap(pdu)) if generic == 6: # Enterprise Specific Traps trapoid = "%s.0.%s" % (trapoid, specific) else: trapoid = "%s.%s" % (trapoid, generic + 1) trap_type = "trap" # v1 doesn't have request_id. Use timestamp in it's place. request_id = int(proto_module.apiTrapPDU.getTimeStamp(pdu)) now = utcnow() trunc_now = now.replace(minute=now.minute / 10 * 10).strftime("%Y%m%d%H%M") trap = Notification( host=host, sent=now, trunc_sent=trunc_now, trap_type=trap_type, request_id=request_id, version=version, oid=trapoid) for oid, val in proto_module.apiTrapPDU.getVarBinds(pdu): oid = oid.prettyPrint() pval = val.prettyPrint() val_type = ASN_TO_NAME_MAP.get(val.__class__, "octet") trap.varbinds.append(VarBind(oid=oid, value_type=val_type, value=pval)) return trap
def _from_pdu_v2c(host, proto_module, version, pdu): varbinds = [] trapoid = None trap_type = "trap2" request_id = proto_module.apiTrapPDU.getRequestID(pdu).prettyPrint() # Need to do initial loop to pull out trapoid for oid, val in proto_module.apiPDU.getVarBindList(pdu): oid = oid.prettyPrint() val = val.getComponentByName("value").getComponent().getComponent() pval = val.prettyPrint() if oid == SNMP_TRAP_OID: trapoid = pval continue varbinds.append((oid, ASN_TO_NAME_MAP.get(val.__class__, "octet"), pval)) if not trapoid: return now = utcnow() trunc_now = now.replace(minute=now.minute / 10 * 10).strftime("%Y%m%d%H%M") trap = Notification(host=host, sent=now, trunc_sent=trunc_now, trap_type=trap_type, request_id=request_id, version=version, oid=trapoid) for oid, val_type, val in varbinds: trap.varbinds.append( VarBind(oid=oid, value_type=val_type, value=val)) return trap