Archived community.zenoss.org | full text search
Skip navigation
Currently Being Moderated

copyAlertingRule.py

VERSION 2  Click to view document history
Created on: Sep 14, 2009 11:21 AM by Noel Brockett - Last Modified:  Sep 14, 2009 11:21 AM by Zenoss API

Allows copying of an alerting rule from one user(group) to another.

 

File attached

 

File contents

#!/usr/bin/env python
import sys
import Globals
from transaction import commit
from Acquisition import aq_base
from copy import copy

from Products.ZenUtils.ZenScriptBase import ZenScriptBase
dmd = ZenScriptBase(connect=True).dmd

if len(sys.argv) < 4:
    print "Usage: %s <source_user> <destination_user> <alerting_rule>" % (
        sys.argv[0],)
    sys.exit(1)

sourceUser = getattr(dmd.ZenUsers, sys.argv[1], None)
if not sourceUser:
    print "%s is not a valid user." % (sys.argv[1],)
    sys.exit(2)

destUser = getattr(dmd.ZenUsers, sys.argv[2], None)
if not destUser:
    print "%s is not a valid user." % (sys.argv[2],)
    sys.exit(3)

alert_rule = getattr(sourceUser, sys.argv[3], None)
if not alert_rule:
    print "%s is not a valid alerting rule." % (sys.argv[3])
    sys.exit(4)

ar_copy = copy(aq_base(alert_rule))
destUser._setObject(ar_copy.id, ar_copy)
Attachments:
Note: binary attachments ending in .zip will need to be unzipped before use.
Comments (0)