1
2
3
4
5
6
7
8
9
10
11 import re
12 from hashlib import md5
13 import logging
14 from cStringIO import StringIO
15 from zope.interface import implements
16 from Products.ZenModel.DeviceClass import DeviceClass
17 from Products.ZenModel.IpAddress import IpAddress
18 from Products.ZenModel.IpNetwork import IpNetwork
19 from Products.ZenModel.OSProcessOrganizer import OSProcessOrganizer
20 from Products.ZenModel.OSProcessClass import OSProcessClass
21 from Products.Zuul.interfaces import ICatalogTool
22
23 from .interfaces import IInvalidationFilter, FILTER_EXCLUDE, FILTER_CONTINUE
24
25 log = logging.getLogger('zen.InvalidationFilter')
26
27
38
39
41 """
42 Base invalidation filter for organizers. Calculates a checksum for
43 the organizer based on its sorted z/c properties.
44 """
45 implements(IInvalidationFilter)
46
47 weight = 10
48 iszorcustprop = re.compile("^[zc][A-Z]").search
49
52
55
64
72
74
75 for zId, propertyString in self.getZorCProperties(organizer):
76 md5_checksum.update('%s|%s' % (zId, propertyString))
77
82
84
85 if not isinstance(obj, self._types):
86 return FILTER_CONTINUE
87
88
89 current_checksum = self.organizerChecksum(obj)
90 organizer_path = '/'.join(obj.getPrimaryPath())
91
92
93 existing_checksum = self.checksum_map.get(organizer_path)
94 if current_checksum != existing_checksum:
95 log.debug('%r has a new checksum! Including.', obj)
96 self.checksum_map[organizer_path] = current_checksum
97 return FILTER_CONTINUE
98 log.debug('%r checksum unchanged. Skipping.', obj)
99 return FILTER_EXCLUDE
100
101
103 """
104 Subclass of BaseOrganizerFilter with specific logic for
105 Device classes. Uses both z/c properties as well as locally
106 bound RRD templates to create the checksum.
107 """
108
111
114
116 """
117 Generate a checksum representing the state of the device class as it
118 pertains to configuration. This takes into account templates and
119 zProperties, nothing more.
120 """
121 s = StringIO()
122
123 for tpl in organizer.rrdTemplates():
124 s.seek(0)
125 s.truncate()
126
127 tpl.exportXml(s)
128 md5_checksum.update(s.getvalue())
129
130 super(DeviceClassInvalidationFilter, self).generateChecksum(organizer, md5_checksum)
131
132
134 """
135 Invalidation filter for OSProcessOrganizer objects. This filter only
136 looks at z/c properties defined on the organizer.
137 """
138
141
144
145
147 """
148 Invalidation filter for OSProcessClass objects. This filter uses
149 z/c properties as well as local _properties defined on the organizer
150 to create a checksum.
151 """
152
155
158
166