Package Products :: Package ZenEvents :: Module zenackevents |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenEvents.zenackevents

     1  #!/usr/bin/env python
     2  ###########################################################################
     3  #
     4  # This program is part of Zenoss Core, an open source monitoring platform.
     5  # Copyright (C) 2007, Zenoss Inc.
     6  #
     7  # This program is free software; you can redistribute it and/or modify it
     8  # under the terms of the GNU General Public License version 2 or (at your
     9  # option) any later version as published by the Free Software Foundation.
    10  #
    11  # For complete information please visit: http://www.zenoss.com/oss/
    12  #
    13  ###########################################################################
    14  import Globals
    15  from Products.ZenUtils.ZenScriptBase import ZenScriptBase
    16  from Products.Zuul.facades import getFacade
    17  import logging
    18  import sys
    19
    20  log = logging.getLogger(name='zen.ackevents')
    21
    22 -class zenackevents(ZenScriptBase):
    23
    24 -    def buildOptions(self):
    25          """basic options setup sub classes can add more options here"""
    26          ZenScriptBase.buildOptions(self)
    27          self.parser.add_option('--userid',
    28                      dest="userid",default="",
    29                      help="name of user who is acking the event")
    30
    31          self.parser.add_option('--evid',
    32                      dest="evids", action="append",
    33                      help="event id that is acked")
    34
    35          self.parser.add_option('--state', type='int',
    36                      dest="state", default=1,
    37                      help="event id that is acked [default: ack]")
    38
    39 -    def ack(self):
    40          if not self.options.evids:
    41              self.parser.error("Require one or more event ids to be acknowledged.")
    42          if not self.options.userid:
    43              self.parser.error("Require username who is acknowledging the event.")
    44          if not self.options.state in (0,1):
    45              self.parser.error("Invalid state: %d" % self.options.state)
    46
    47          zep = getFacade('zep', self.dmd)
    48          event_filter = zep.createEventFilter(uuid=self.options.evids)
    49          try:
    50              # Old event states = 0=New, 1=Acknowledge
    51              if self.options.state == 0:
    52                  zep.reopenEventSummaries(eventFilter=event_filter, userName=self.options.userid)
    53              elif self.options.state == 1:
    54                  zep.acknowledgeEventSummaries(eventFilter=event_filter, userName=self.options.userid)
    55          except Exception as e:
    56              if log.isEnabledFor(logging.DEBUG):
    57                  log.exception("Failed to acknowledge events")
    58              print >>sys.stderr, e.message
    59              sys.exit(1)
    60
    61  if __name__ == '__main__':
    62      zae = zenackevents(connect=True)
    63      zae.ack()
    64