Archived community.zenoss.org | full text search
Skip navigation
39178 Views 3 Replies Latest reply: Nov 30, 2009 2:59 PM by Shane Scott RSS
Shane Scott ZenossMaster 1,373 posts since
Jul 6, 2009
Currently Being Moderated

Oct 5, 2009 4:12 PM

Copy EventViews

Has anyone figured how to copy event views from user to user or group to group? I'd think it would be possible using the same manner used in copyDash.py and CopyAlert.py. Any idea? Thanks!

 

CopyAlert.py - docs/DOC-2534 {

 

#!/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)

}
  • chitambira Rank: Brown Belt 711 posts since
    Oct 15, 2008
    Currently Being Moderated
    2. Nov 27, 2009 11:08 AM (in response to Shane Scott)
    Re: Copy EventViews

    You can do this in the exact similar way; (just by sed'ing the above code, the ultimate code will look like:)

     

    #!/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> <event_view>" % (
            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)

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

    ev_copy = copy(aq_base(event_view))
    destUser._setObject(ev_copy.id, ev_copy)
    commit()

More Like This

  • Retrieving data ...

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points