Exemplo n.º 1
0
class Layer3Link(object):
    """
    Provides an API for navigating paired groups of brains.
    """
    def __init__(self, dmd, twokeydict):
        a, b = twokeydict.items()
        aid, self.abrains = a
        bid, self.bbrains = b
        self.a = dmd.unrestrictedTraverse(aid)
        self.b = dmd.unrestrictedTraverse(bid)
        self.zep = getFacade('zep', dmd)
        self.idmgr = Manager(dmd)

    def _getComponentUuid(self, devuuid, compid):
        try:
            dev = self.idmgr.getElementByUuid(devuuid)
            compuuid = self.idmgr.getElementUuidById(dev, Device, compid)
            return compuuid
        except Exception:
            return None

    def getStatus(self):
        brains = self.abrains + self.bbrains

        # lookup all device uuids, make sure at least one exists
        devUuids = [self.idmgr.findDeviceUuid(a.deviceId.split("/")[-1], None) for a in brains if a.deviceId]
        validDevUuids = filter(None, devUuids)
        if not validDevUuids:
            return SEVERITY_CLEAR

        # if there is any open /Status/Ping event on any device, return CRITICAL severity
        statusPingFilter = self.zep.createEventFilter(
            tags = validDevUuids,
            event_class = '/Status/Ping/',
            status = (STATUS_NEW, STATUS_ACKNOWLEDGED),
            severity = (SEVERITY_WARNING, SEVERITY_ERROR, SEVERITY_CRITICAL)
        )
        maxpingrec = self.zep.getEventSummaries(0, filter=statusPingFilter, sort=(('count','desc'),), limit=1)
        if maxpingrec and maxpingrec['total'] > 0:
            return SEVERITY_CRITICAL

        # no /Status/Ping events found, just return worst severity of all events on all interface components
        devCompPairs = zip(devUuids, (a.interfaceId for a in brains))
        compUuids = (self._getComponentUuid(devuuid, compid)
                        for devuuid, compid in devCompPairs
                        if devuuid is not None)
        components = filter(None, compUuids)
        if components:
            sev = self.zep.getWorstSeverity(components)
            return sev

        return SEVERITY_CLEAR

    def getAddresses(self):
        return (self.a.address, self.b.address)

    def getUids(self):
        return ("/".join(self.a.getPhysicalPath()), "/".join(self.b.getPhysicalPath()))
Exemplo n.º 2
0
class Layer3Link(object):
    """
    Provides an API for navigating paired groups of brains.
    """
    def __init__(self, dmd, twokeydict):
        a, b = twokeydict.items()
        aid, self.abrains = a
        bid, self.bbrains = b
        self.a = dmd.unrestrictedTraverse(aid)
        self.b = dmd.unrestrictedTraverse(bid)
        self.zep = getFacade('zep', dmd)
        self.idmgr = Manager(dmd)

    def _getComponentUuid(self, devuuid, compid):
        try:
            dev = self.idmgr.getElementByUuid(devuuid)
            compuuid = self.idmgr.getElementUuidById(dev, Device, compid)
            return compuuid
        except Exception:
            return None

    def getStatus(self):
        brains = self.abrains + self.bbrains

        # lookup all device uuids, make sure at least one exists
        devUuids = [
            self.idmgr.findDeviceUuid(a.deviceId.split("/")[-1], None)
            for a in brains if a.deviceId
        ]
        validDevUuids = filter(None, devUuids)
        if not validDevUuids:
            return SEVERITY_CLEAR

        # if there is any open /Status/Ping event on any device, return CRITICAL severity
        statusPingFilter = self.zep.createEventFilter(
            tags=validDevUuids,
            event_class='/Status/Ping/',
            status=(STATUS_NEW, STATUS_ACKNOWLEDGED),
            severity=(SEVERITY_WARNING, SEVERITY_ERROR, SEVERITY_CRITICAL))
        maxpingrec = self.zep.getEventSummaries(0,
                                                filter=statusPingFilter,
                                                sort=(('count', 'desc'), ),
                                                limit=1)
        if maxpingrec and maxpingrec['total'] > 0:
            return SEVERITY_CRITICAL

        # no /Status/Ping events found, just return worst severity of all events on all interface components
        devCompPairs = zip(devUuids, (a.interfaceId for a in brains))
        compUuids = (self._getComponentUuid(devuuid, compid)
                     for devuuid, compid in devCompPairs
                     if devuuid is not None)
        components = filter(None, compUuids)
        if components:
            sev = self.zep.getWorstSeverity(components)
            return sev

        return SEVERITY_CLEAR

    def getAddresses(self):
        return (self.a.address, self.b.address)

    def getUids(self):
        return ("/".join(self.a.getPhysicalPath()),
                "/".join(self.b.getPhysicalPath()))