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  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     5  #
     6  # This content is made available according to terms specified in
     7  # License.zenoss under the directory where your Zenoss product is installed.
     8  #
     9  ##############################################################################
    10
    11
    12  import Globals
    13  from Products.ZenUtils.ZenScriptBase import ZenScriptBase
    14  from Products.Zuul.facades import getFacade
    15  import logging
    16  import sys
    17
    18  log = logging.getLogger(name='zen.ackevents')
    19
    20 -class zenackevents(ZenScriptBase):
    21
    22 -    def buildOptions(self):
    23          """basic options setup sub classes can add more options here"""
    24          ZenScriptBase.buildOptions(self)
    25          self.parser.add_option('--userid',
    26                      dest="userid",default="",
    27                      help="name of user who is acking the event")
    28
    29          self.parser.add_option('--evid',
    30                      dest="evids", action="append",
    31                      help="event id that is acked")
    32
    33          self.parser.add_option('--state', type='int',
    34                      dest="state", default=1,
    35                      help="event id that is acked [default: ack]")
    36
    37 -    def ack(self):
    38          if not self.options.evids:
    39              self.parser.error("Require one or more event ids to be acknowledged.")
    40          if not self.options.userid:
    41              self.parser.error("Require username who is acknowledging the event.")
    42          if not self.options.state in (0,1):
    43              self.parser.error("Invalid state: %d" % self.options.state)
    44
    45          zep = getFacade('zep', self.dmd)
    46          event_filter = zep.createEventFilter(uuid=self.options.evids)
    47          try:
    48              # Old event states = 0=New, 1=Acknowledge
    49              if self.options.state == 0:
    50                  zep.reopenEventSummaries(eventFilter=event_filter, userName=self.options.userid)
    51              elif self.options.state == 1:
    52                  zep.acknowledgeEventSummaries(eventFilter=event_filter, userName=self.options.userid)
    53          except Exception as e:
    54              if log.isEnabledFor(logging.DEBUG):
    55                  log.exception("Failed to acknowledge events")
    56              print >>sys.stderr, e.message
    57              sys.exit(1)
    58
    59  if __name__ == '__main__':
    60      zae = zenackevents(connect=True)
    61      zae.ack()
    62