Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZEN-29068: For upgrades, a separate log file needs to be generated fo… #543

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions ZenPacks/zenoss/ZenPackLib/lib/base/ZenPack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
'/Heartbeat', '/Unknown', '/Change', 'Processes',
'Services', 'WinService', 'IpService'])

DIFF_DIR = '/home/zenoss/diff/'

for x in dir(ZenEventClasses):
y = getattr(ZenEventClasses, x)
if isinstance(y, str):
Expand Down Expand Up @@ -68,7 +70,16 @@ def install(self, app):
self.LOG.info('Adding {} relationships to existing devices'.format(self.id))
self._buildDeviceRelations(app)

# load monitoring templates
# Create zp diff folder or clear it from old diff files
self.zp_diff_dir = '{}{}/'.format(DIFF_DIR, self.id)
if os.path.isdir(self.zp_diff_dir):
old_diffs = os.listdir(self.zp_diff_dir)
for f in old_diffs:
os.remove('{}/{}'.format(self.zp_diff_dir, f))
else:
os.makedirs(self.zp_diff_dir)

# Load monitoring templates
for dcname, dcspec in self.device_classes.iteritems():
dcspecparam = self._v_specparams.device_classes.get(dcname)
deviceclass = dcspec.get_organizer(app.zport.dmd)
Expand All @@ -77,6 +88,10 @@ def install(self, app):
mtspecparam = dcspecparam.templates.get(mtname)
self.update_object(app, deviceclass, 'rrdTemplates', mtname, mtspec, mtspecparam)

# Remove zp diff folder if it's empty
if not os.listdir(self.zp_diff_dir):
os.rmdir(self.zp_diff_dir)

# Load event classes
for ecname, ecspec in self.event_classes.iteritems():
ec_org = ecspec.create_organizer(app.zport.dmd)
Expand Down Expand Up @@ -199,12 +214,16 @@ def check_diff(self, app, parent, relname, object, spec, specparam):
time_str = time.strftime("%Y%m%d%H%M", time.localtime())
preupgrade_id = "{}-preupgrade-{}".format(object.id, time_str)
self.move_object(parent, relname, object.id, preupgrade_id)
diff_file = '{}{}.diff'.format(self.zp_diff_dir, preupgrade_id)
LOG.info("Existing object {}/{} differs from "
"the newer version included with the {} ZenPack. "
"The existing object will be "
"backed up to '{}'. Please review and reconcile any "
"local changes before deleting the backup: \n{}".format(
parent.getDmdKey(), spec.name, self.id, preupgrade_id, diff))
"backed up to '{}'. Please review and reconcile any "
"local changes before deleting the backup".format(
parent.getDmdKey(), spec.name, self.id, os.path.abspath(diff_file)))
f = open(diff_file, 'w')
f.write(diff)
f.close()
return True

def get_object(self, parent, relname, object_id):
Expand Down