| Trees | Indices | Help |
|
|---|
|
|
1 ##############################################################################
2 #
3 # Copyright (C) Zenoss, Inc. 2011, all rights reserved.
4 #
5 # This content is made available according to terms specified in
6 # License.zenoss under the directory where your Zenoss product is installed.
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
51 self._types = types
52
55
57 root = self.getRoot(context)
58 brains = ICatalogTool(root).search(self._types)
59 results = {}
60 for brain in brains:
61 obj = brain.getObject()
62 results[brain.getPath()] = self.organizerChecksum(obj)
63 self.checksum_map = results
64
66 for zId in sorted(organizer.zenPropertyIds(pfilt=self.iszorcustprop)):
67 if organizer.zenPropIsPassword(zId):
68 propertyString = organizer.getProperty(zId, '')
69 else:
70 propertyString = organizer.zenPropertyString(zId)
71 yield zId, propertyString
72
74 # Checksum all zProperties and custom properties
75 for zId, propertyString in self.getZorCProperties(organizer):
76 md5_checksum.update('%s|%s' % (zId, propertyString))
77
82
84 # Move on if it's not one of our types
85 if not isinstance(obj, self._types):
86 return FILTER_CONTINUE
87
88 # Checksum the device class
89 current_checksum = self.organizerChecksum(obj)
90 organizer_path = '/'.join(obj.getPrimaryPath())
91
92 # Get what we have right now and compare
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 # Checksum includes all bound templates
123 for tpl in organizer.rrdTemplates():
124 s.seek(0)
125 s.truncate()
126 # TODO: exportXml is a bit of a hack. Sorted, etc. would be better.
127 tpl.exportXml(s)
128 md5_checksum.update(s.getvalue())
129 # Include z/c properties from base class
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
160 # Include properties of OSProcessClass
161 for prop in organizer._properties:
162 prop_id = prop['id']
163 md5_checksum.update("%s|%s" % (prop_id, getattr(organizer, prop_id, '')))
164 # Include z/c properties from base class
165 super(OSProcessClassFilter, self).generateChecksum(organizer, md5_checksum)
166
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1.1812 on Mon Jul 30 17:11:18 2012 | http://epydoc.sourceforge.net |