Beispiel #1
0
class IpInterfaceIndexable(ComponentIndexable): # IpInterface inherits from this class

    @indexed(StringFieldType(stored=True), attr_query_name="interfaceId")
    def idx_interfaceId(self):
        interface_id = None
        if self.interfaceId():
            interface_id = self.interfaceId()
        return interface_id

    def _idx_get_ip(self):
        if hasattr(self, 'getIpAddress') and self.getIpAddress():
            return self.getIpAddress().partition('/')[0]
        else:
            return None

    @indexed(IPAddressFieldType(stored=True, index_formatter=ipunwrap, query_formatter=ipunwrap), attr_query_name="text_ipAddress")
    def idx_text_ipAddress(self):
        return self._idx_get_ip()

    """ Layer 2 catalog indexes """
    @indexed(StringFieldType(stored=True), attr_query_name="lanId")
    def idx_lanId(self):
        lan_id = None
        if self.lanId() and self.lanId()!="None":
            lan_id = self.lanId()
        return lan_id

    @indexed(StringFieldType(stored=True), attr_query_name="macaddress")
    def idx_macaddress(self):
        return self.macaddress
Beispiel #2
0
class IpNetworkIndexable(object):
    """ IpNetwork indexes """

    # largest 128 decimal is 340282366920938463463374607431768211456
    # we need to fill to 39 chars for range queries to work

    @indexed(StringFieldType(stored=True,
                             index_formatter=decimal_ipAddress_formatter,
                             query_formatter=decimal_ipAddress_formatter),
             attr_query_name="firstDecimalIp")
    def idx_firstDecimalIp(self):
        first_decimal_ip = None
        if isip(self.id):
            net = IPNetwork(ipunwrap(self.id))
            first_decimal_ip = str(int(net.network))
        return first_decimal_ip

    @indexed(StringFieldType(stored=True,
                             index_formatter=decimal_ipAddress_formatter,
                             query_formatter=decimal_ipAddress_formatter),
             attr_query_name="lastDecimalIp")
    def idx_lastDecimalIp(self):
        last_decimal_ip = None
        if isip(self.id):
            net = IPNetwork(ipunwrap(self.id))
            first_decimal_ip = long(int(net.network))
            last_decimal_ip = str(
                long(first_decimal_ip +
                     math.pow(2, net.max_prefixlen - self.netmask) - 1))
        return last_decimal_ip
Beispiel #3
0
class ComponentIndexable(object):  # DeviceComponent inherits from this class
    @indexed(StringFieldType(stored=True), attr_query_name="deviceId")
    def idx_deviceId(self):
        """ device the component belongs to """
        device_id = None
        if self.device():
            device_id = self.device().idx_uid()
        return device_id

    @indexed(StringFieldType(stored=True), attr_query_name="description")
    def idx_description(self):
        """ description of the component """
        description = None
        if self.description:
            description = self.description
        return description
Beispiel #4
0
class IpAddressIndexable(object):  # IpAddress inherits from this class
    """ Layer 3 catalog indexes """
    @indexed(StringFieldType(stored=True), attr_query_name="interfaceId")
    def idx_interfaceId(self):
        interface_id = None
        if self.interfaceId():
            interface_id = self.interface().interfaceId()
        return interface_id

    @indexed(StringFieldType(stored=True), attr_query_name="ipAddressId")
    def idx_ipAddressId(self):
        return self.ipAddressId()

    @indexed(UntokenizedStringFieldType(stored=True),
             attr_query_name="networkId")
    def idx_networkId(self):
        return self.networkId()

    @indexed(StringFieldType(stored=True), attr_query_name="deviceId")
    def idx_deviceId(self):
        """ device the ipaddress belongs to. Since IpAddress does not inherit from DeviceComponent """
        device_id = None
        if self.device():
            device_id = self.device().idx_uid()
        return device_id

    """ ipSearch catalog indexes """
    index("idx_decimal_ipAddress",
          NOINDEX_TYPE)  # disable BaseIndexable implementation

    @indexed(StringFieldType(stored=True,
                             index_formatter=decimal_ipAddress_formatter,
                             query_formatter=decimal_ipAddress_formatter),
             attr_query_name="decimal_ipAddress")
    def idx_ipaddress_decimal_ipAddress(self):
        return str(self.ipAddressAsInt())

    @indexed(IPAddressFieldType(stored=True,
                                index_formatter=ipunwrap,
                                query_formatter=ipunwrap),
             attr_query_name="ipAddressAsText")
    def idx_ipAddressAsText(self):
        return self.getIpAddress()
Beispiel #5
0
class DeviceIndexable(object):   # Device inherits from this class

    def _idx_get_ip(self):
        if hasattr(self, 'getManageIp') and self.getManageIp():
            return self.getManageIp().partition('/')[0]
        else:
            return None

    @indexed(IPAddressFieldType(stored=True, index_formatter=ipunwrap, query_formatter=ipunwrap), attr_query_name="text_ipAddress")
    def idx_text_ipAddress(self):
        return self._idx_get_ip()

    @indexed(UntokenizedStringFieldType(indexed=True, stored=False), attr_query_name="deviceClassPath")
    def idx_deviceClassPath(self):
        return self.getDeviceClassPath()

    @indexed(ListOfUntokenizedStringsFieldType(indexed=True, stored=True), attr_query_name="deviceOrganizers")
    def idx_deviceOrganizers(self):
        """
        device organizers the device belongs to as untokenized strings so we can use facets
        to get the device organizer counts in the infrastructure page
        """
        paths = self.idx_path()
        relevant_organizers = { "Devices", "Groups", "Locations", "Systems" }
        organizers = []
        for path in paths:
            sp = path.split("/")
            if len(sp) >= 6 and sp[3] in relevant_organizers and sp[-2] == "devices":
                # remove the devices/device_id from the end
                organizers.append( "/".join(sp[:-2]) )
        return organizers

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="tagNumber")
    def idx_tagNumber(self):
        return self.hw.tag
 
    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="pythonClass")
    def idx_pythonClass(self):
        return self.__class__.__module__

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="priority")
    def idx_priority(self):
        return self.priority

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="collector")
    def idx_collector(self):
        return self.getPerformanceServerName()

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="osModel")
    def idx_osModel(self):
        if self.os.productClass():
            return self.os.productClass().id

        return None

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="osManufacturer")
    def idx_osManufacturer(self):
        if self.os.productClass():
            return self.os.productClass().manufacturer().id

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="hwModel")
    def idx_hwModel(self):
        if self.hw.productClass():
            return self.hw.productClass().id

        return None

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="hwManufacturer")
    def idx_hwManufacturer(self):
        if self.hw.productClass():
            return self.hw.productClass().manufacturer().id

    @indexed(StringFieldType(indexed=True, stored=True), attr_query_name="serialNumber")
    def idx_serialNumber(self):
        return self.hw.serialNumber
Beispiel #6
0
class BaseIndexable(TransactionIndexable):    # ZenModelRM inherits from this class
    '''
    @indexed(StringFieldType(stored=True), attr_query_name="indexable"):
    def idx_base_indexable(self):
        return self.__class__.__name__
    '''

    def idx_uid(self):
        return IIndexableWrapper(self).uid()

    # modelindex requires that every object has an 'index_field_name' and  'attr_query_name'
    # named MODELINDEX_UID. This field is used as unique field in the index.
    # We use the object's primary path. The model catalog data manager adds additional information
    # to this field for mid transaction commits. This way we can have several documents for the same object
    @indexed(UntokenizedStringFieldType(stored=True), index_field_name=MODEL_INDEX_UID_FIELD, attr_query_name=MODEL_INDEX_UID_FIELD)
    def idx_model_index_uid(self):
        return self.idx_uid()

    # uid used within zenoss. it is the object's primary path
    @indexed(UntokenizedStringFieldType(stored=True), index_field_name=OBJECT_UID_FIELD, attr_query_name=OBJECT_UID_FIELD)
    def idx_object_uid(self):
        return self.idx_uid()

    @indexed(UntokenizedStringFieldType(stored=True), attr_query_name="id")
    def idx_id(self):
        return self.id

    @indexed(UntokenizedStringFieldType(stored=True), attr_query_name="uuid")
    def idx_uuid(self):
        """
        Object's uuid.
        """
        return IIndexableWrapper(self).uuid()

    @indexed(UntokenizedStringFieldType(stored=True), attr_query_name="name")
    def idx_name(self):
        """
        The name of the object.
        """
        return IIndexableWrapper(self).name()

    @indexed(UntokenizedStringFieldType(stored=True), attr_query_name="meta_type")
    def idx_meta_type(self):
        """
        Object's meta_type. Mostly used for backwards compatibility.
        """
        return IIndexableWrapper(self).meta_type()

    @indexed(ListOfPathStringsFieldType(stored=True), attr_query_name="path") # Device already has a method called path
    def idx_path(self):
        """
        Paths under which this object may be found.
        """
        return [ '/'.join(p) for p in IIndexableWrapper(self).path() ]

    @indexed(ListOfStringsFieldType(stored=True), attr_query_name="objectImplements")
    def idx_objectImplements(self):
        """
        All interfaces and classes implemented by an object.
        """
        return IIndexableWrapper(self).objectImplements()

    @indexed(ListOfStringsFieldType(stored=True), attr_query_name="allowedRolesAndUsers")
    def idx_allowedRolesAndUsers(self):
        """
        Roles and users with View permission.
        """
        return IIndexableWrapper(self).allowedRolesAndUsers()


    # Fields for Searchables
    @indexed(ListOfUntokenizedStringsFieldType(stored=True), attr_query_name="searchKeywords")
    def idx_searchKeywords(self):
        keywords = IIndexableWrapper(self).searchKeywords()
        if keywords:
            unique_keywords = { keyword for keyword in keywords if keyword }
            return list(unique_keywords)
        else:
            return []

    @indexed(UntokenizedStringFieldType(indexed=False, stored=True), attr_query_name="searchExcerpt")
    def idx_searchExcerpt(self):
        return IIndexableWrapper(self).searchExcerpt()

    @indexed(UntokenizedStringFieldType(indexed=False, stored=True), attr_query_name="searchIcon")
    def idx_searchIcon(self):
        return IIndexableWrapper(self).searchIcon()


    # Fields for components
    @indexed(bool, attr_query_name="monitored")
    def idx_monitored(self):
        return True if IIndexableWrapper(self).monitored() else False

    @indexed(ListOfStringsFieldType(stored=True), attr_query_name="collectors")
    def idx_collectors(self):
        cols = IIndexableWrapper(self).collectors()
        if cols:
            return [ col for col in cols if col ]
        else:
            return []

    # Fields for devices
    @indexed(IntFieldType(stored=True), attr_query_name="productionState")
    def idx_productionState(self):
        return IIndexableWrapper(self).productionState()

    @indexed(DictAsBase64StringsFieldType(indexed=False), attr_query_name="zProperties")
    def idx_zProperties(self):
        return IIndexableWrapper(self).zProperties

    # Fields for Devices and Interfaces
    @indexed(StringFieldType(stored=True, index_formatter=decimal_ipAddress_formatter, query_formatter=decimal_ipAddress_formatter), attr_query_name="decimal_ipAddress") # Ip address as number
    def idx_decimal_ipAddress(self):

        return IIndexableWrapper(self).ipAddress

    @indexed(ListOfStringsFieldType(stored=True), attr_query_name="macAddresses")
    def idx_macAddresses(self):
        return IIndexableWrapper(self).macAddresses()