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

# Source Code for Module Products.ZenEvents.SendEvent

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  import logging
    12  import socket
    13  import xmlrpclib
    14
    15  from Products.ZenUtils.Utils import  basicAuthUrl
    16
    17 -class SendEvent(object):
    18
    19 -    def __init__(self, agent, username, password, url):
    20          self.agent = agent
    21          self.url = basicAuthUrl(username, password, url)
    22          self.server = xmlrpclib.Server(self.url)
    23          severities = self.server.getSeverities()
    24          for name, value in severities:
    25              setattr(self, name, value)
    26
    27
    28 -    def sendEvent(self, deviceName, evclass, msg, severity, **kwargs):
    29          """
    30          Send a ZenEvent to the event manager.  Events must have:
    31          deviceName - which is the FQDN of the device
    32          evclass - the event class of the event
    33          msg - the event message
    34          severity - the severity of the event
    35
    36          agent - is the management collection system that the event came through
    37
    38          Other potential fields are:
    39
    40          """
    41          event = {}
    42          event['Node'] = deviceName
    43          event['Class'] = evclass
    44          event['Summary'] = msg
    45          event['Severity'] = severity
    46          event['Agent'] = self.agent
    47          event['Manager'] = socket.getfqdn()
    48          event.update(kwargs)
    49          try:
    50              self.server.sendEvent(event)
    51          except SystemExit: raise
    52          except:
    53              raise
    54              logging.exception("Event notification failed url %s", self.url)
    55