示例#1
0
class ZepDetailsInfo:
    """Contains information about the indexed event details on ZEP
    """

    def __init__(self):
        zep_url = config.ZEP_URI
        schema = getUtility(IQueueSchema)
        self._configClient = ZepConfigClient(zep_url, schema)
        self._initialized = False

    def _initDetails(self):
        self._sortMap = dict(ZepService.DEFAULT_SORT_MAP)
        response, content = self._configClient.getDetails()

        detailsResponseDict = to_dict(content)
        self._details = detailsResponseDict.get('details', [])
        self._unmappedDetails = []
        self._detailsMap = {}

        for detail_item in self._details:
            detailKey = detail_item['key']
            sortField = {'field': EventSort.DETAIL, 'detail_key': detailKey}

            mappedName = ZepService.ZENOSS_DETAIL_NEW_TO_OLD_MAPPING.get(detailKey, None)
            # If we have a mapped name, add it to the sort map to support sorting using old or new names
            if mappedName:
                self._sortMap[mappedName.lower()] = sortField
            else:
                self._unmappedDetails.append(detail_item)

            self._sortMap[detailKey.lower()] = sortField
            self._detailsMap[detailKey] = detail_item

        self._initialized = True

    def reload(self):
        """Reloads the event details configuration from ZEP
        """

        self._initialized = False
        self._initDetails()

    def getDetails(self):
        """Retrieve all of the indexed detail item
        @return type list of EventDetailItem dicts
        """

        if not self._initialized:
            self._initDetails()
        return self._details

    def getUnmappedDetails(self):
        """Return only non-zenoss details. This is used to get details that will not be mapped to another key
        (zenoss.device.production_state maps back to prodState, so will be excluded here)
        """

        if not self._initialized:
            self._initDetails()
        return self._unmappedDetails

    def getDetailsMap(self):
        """Return a mapping of detail keys to dicts of detail items
        """

        if not self._initialized:
            self._initDetails()
        return self._detailsMap

    def getSortMap(self):
        """Returns a mapping of a lowercase event field name to a dictionary which can be used
        to build the EventSort object to pass to ZEP
        """

        if not self._initialized:
            self._initDetails()
        return self._sortMap
示例#2
0
class ZepDetailsInfo:
    """
    Contains information about the indexed event details on ZEP.
    """

    def __init__(self):
        config = getGlobalConfiguration()
        schema = getUtility(IQueueSchema)
        zep_url = config.get('zep-uri', 'http://localhost:8084')
        self._configClient = ZepConfigClient(zep_url, schema)
        self._initialized = False

    def _initDetails(self):
        self._sortMap = dict(ZepFacade.DEFAULT_SORT_MAP)
        response, content = self._configClient.getDetails()

        detailsResponseDict = to_dict(content)
        self._details = detailsResponseDict.get('details', [])
        self._unmappedDetails = []
        self._detailsMap = {}
        for detail_item in self._details:
            detailKey = detail_item['key']
            sortField = { 'field': EventSort.DETAIL, 'detail_key': detailKey }
            mappedName = ZepFacade.ZENOSS_DETAIL_NEW_TO_OLD_MAPPING.get(detailKey, None)
            # If we have a mapped name, add it to the sort map to support sorting using old or new names
            if mappedName:
                self._sortMap[mappedName.lower()] = sortField
            else:
                self._unmappedDetails.append(detail_item)
            self._sortMap[detailKey.lower()] = sortField
            self._detailsMap[detailKey] = detail_item
        self._initialized = True

    def reload(self):
        """
        Reloads the event details configuration from ZEP.
        """
        self._initialized = False
        self._initDetails()

    def getDetails(self):
        """
        Retrieve all of the indexed detail items.

        @rtype list of EventDetailItem dicts
        """
        if not self._initialized:
            self._initDetails()
        return self._details

    def getUnmappedDetails(self):
        """
        Return only non-zenoss details. This is used to get details that will not be mapped to another key.
        (zenoss.device.production_state maps back to prodState, so will be excluded here)
        """
        if not self._initialized:
            self._initDetails()
        return self._unmappedDetails

    def getDetailsMap(self):
        """
        Return a mapping of detail keys to dicts of detail items
        """
        if not self._initialized:
            self._initDetails()
        return self._detailsMap

    def getSortMap(self):
        """
        Returns a mapping of a lowercase event field name to a dictionary which can be used
        to build the EventSort object to pass to ZEP.
        """
        if not self._initialized:
            self._initDetails()
        return self._sortMap