Exemplo n.º 1
0
    def run(self):
        sender = self.destination.get_sender()

        if self.is_error:
            level = AlertLevels.ERROR
            message_context = Source.error_context(self.event.context)
        else:
            level = None    # set via options or Sender
            message_context = Source.message_context(self.event.context,
                                                     self.event.trigger_result)

        message = self.destination.get_message(message_context)
        options = self.destination.options
        if options:
            level = AlertLevels.find(options.get('level', None))

        alert = Alert(event=self.event,
                      level=level or sender.level,
                      sender=self.destination.sender,
                      message=message,
                      options=options)
        # need to save to get datetime assigned
        alert.save()
        logger.debug('Sending Alert %s via Destination %s' %
                     (alert, self.destination))
        try:
            sender.send(alert)
        except:
            logger.exception("An error occurred while sending alert %s"
                             " via Destination %s" % (alert, self.destination))
Exemplo n.º 2
0
    def run(self):
        sender = self.destination.get_sender()

        if self.is_error:
            level = AlertLevels.ERROR
            message_context = Source.error_context(self.event.context)
        else:
            level = None    # set via options or Sender
            message_context = Source.message_context(self.event.context,
                                                     self.event.trigger_result)

        message = self.destination.get_message(message_context)
        options = self.destination.options
        if options:
            level = AlertLevels.find(options.get('level', None))

        alert = Alert(event=self.event,
                      level=level or sender.level,
                      sender=self.destination.sender,
                      message=message,
                      options=options)
        # need to save to get datetime assigned
        alert.save()
        logger.debug('Sending Alert %s via Destination %s' %
                     (alert, self.destination))
        try:
            sender.send(alert)
        except:
            logger.exception("An error occurred while sending alert %s"
                             " via Destination %s" % (alert, self.destination))
Exemplo n.º 3
0
    def create(cls, source, trigger_func, params=None, **kwargs):
        """Create trigger against given source table.

        :param table source: Table object reference
        :param function trigger_func: function object to run for trigger
        :param dict params: optional additional parameters to pass to
            trigger_func
        """
        tfunc = Function(trigger_func, params=params)
        t = Trigger(name=kwargs.pop('name', Source.name(source)),
                    source=Source.encode(source),
                    trigger_func=tfunc,
                    **kwargs)
        t.save()
        return t
Exemplo n.º 4
0
def process_data(sender, **kwargs):
    data = kwargs.pop('data')
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received post_data_save signal from %s context %s' %
                 (sender, context))

    triggers = TriggerCache.filter(Source.encode(source))
    if triggers:
        logger.debug('Found %d triggers.' % len(triggers))
        if callable(data):
            data = data()
        for t in triggers:
            TriggerThread(t, data, context).start()
Exemplo n.º 5
0
    def create(cls, source, trigger_func, params=None, **kwargs):
        """Create trigger against given source table.

        :param table source: Table object reference
        :param function trigger_func: function object to run for trigger
        :param dict params: optional additional parameters to pass to
            trigger_func
        """
        tfunc = Function(trigger_func, params=params)
        t = Trigger(name=kwargs.pop('name', Source.name(source)),
                    source=Source.encode(source),
                    trigger_func=tfunc,
                    **kwargs)
        t.save()
        return t
Exemplo n.º 6
0
def process_data(sender, **kwargs):
    data = kwargs.pop('data')
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received post_data_save signal from %s context %s' %
                 (sender, context))

    triggers = TriggerCache.filter(Source.encode(source))
    if triggers:
        logger.debug('Found %d triggers.' % len(triggers))
        if callable(data):
            data = data()
        for t in triggers:
            TriggerThread(t, data, context).start()
Exemplo n.º 7
0
 def filter(cls, value):
     cls.debug('filtering on %s' % value)
     if cls._lookup is None:
         cls._get()
     if not isinstance(value, frozenset):
         value = Source.encode(value)
     return cls._lookup[value]
Exemplo n.º 8
0
 def filter(cls, value):
     cls.debug('filtering on %s' % value)
     if cls._lookup is None:
         cls._get()
     if not isinstance(value, frozenset):
         value = Source.encode(value)
     return cls._lookup[value]
Exemplo n.º 9
0
def process_error(sender, **kwargs):
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received error_signal from %s with context %s' %
                 (sender, context))

    handlers = ErrorHandlerCache.filter(Source.encode(source))
    logger.debug('Found %d handlers.' % len(handlers))
    event = Event(severity=ERROR_SEVERITY, context=context,
                  trigger_result=None)
    event.save()
    logger.debug('New Event created: %s' % event)
    for h in handlers:
        DestinationThread(h.destination, event, is_error=True).start()

    system_settings = SystemSettings.get_system_settings()
    if system_settings.global_error_handler:
        if not handlers or any([h.allow_global for h in handlers]):
            for d in GlobalErrorHandlerCache.data():
                DestinationThread(d, event, is_error=True).start()
Exemplo n.º 10
0
def process_error(sender, **kwargs):
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received error_signal from %s with context %s' %
                 (sender, context))

    handlers = ErrorHandlerCache.filter(Source.encode(source))
    logger.debug('Found %d handlers.' % len(handlers))
    event = Event(severity=ERROR_SEVERITY, context=context,
                  trigger_result=None)
    event.save()
    logger.debug('New Event created: %s' % event)
    for h in handlers:
        DestinationThread(h.destination, event, is_error=True).start()

    system_settings = SystemSettings.get_system_settings()
    if system_settings.global_error_handler:
        if not handlers or any([h.allow_global for h in handlers]):
            for d in GlobalErrorHandlerCache.data():
                DestinationThread(d, event, is_error=True).start()
Exemplo n.º 11
0
    def create(cls, name, source, sender, options=None,
               template=None, template_func=None, allow_global=False):
        """Create new ErrorHandler and its associated Destination."""
        destination = Destination.create(sender, options,
                                         template, template_func)

        # when called via Trigger classmethod source has already been encoded
        if not isinstance(source, frozenset):
            source = Source.encode(source)

        e = ErrorHandler(name=name, source=source, destination=destination,
                         allow_global=allow_global)
        e.save()
        return e
Exemplo n.º 12
0
    def create(cls, name, source, sender, options=None,
               template=None, template_func=None, allow_global=False):
        """Create new ErrorHandler and its associated Destination."""
        destination = Destination.create(sender, options,
                                         template, template_func)

        # when called via Trigger classmethod source has already been encoded
        if not isinstance(source, frozenset):
            source = Source.encode(source)

        e = ErrorHandler(name=name, source=source, destination=destination,
                         allow_global=allow_global)
        e.save()
        return e
Exemplo n.º 13
0
    def run(self):
        sender = self.destination.get_sender()
        logger.debug('XXX here - event/sender: %s/%s' % (self.event, sender))

        if self.is_error:
            level = AlertLevels.ERROR
            message_context = Source.error_context(self.event.context)
        else:
            level = None    # set via options or Sender
            message_context = Source.message_context(self.event.context,
                                                     self.event.trigger_result)

        message = self.destination.get_message(message_context)
        options = self.destination.options
        logger.debug('XXX here - message/options: %s/%s' % (message, options))
        if options:
            level = AlertLevels.find(options.get('level', None))

        try:
            alert = Alert(event=self.event,
                          level=level or sender.level,
                          sender=self.destination.sender,
                          message=message,
                          options=options)
            # need to save to get datetime assigned
            alert.save()
            logger.debug('Sending Alert %s via Destination %s' %
                         (alert, self.destination))
        except Exception as e:
            logger.error('Error saving Alert: %s' % e)

        try:
            # even if we had an error saving, may be able to still send alert
            sender.send(alert)
        except:
            logger.exception("An error occurred while sending alert %s"
                             " via Destination %s" % (alert, self.destination))
Exemplo n.º 14
0
    def run(self):
        sender = self.destination.get_sender()
        logger.debug('XXX here - event/sender: %s/%s' % (self.event, sender))

        if self.is_error:
            level = AlertLevels.ERROR
            message_context = Source.error_context(self.event.context)
        else:
            level = None  # set via options or Sender
            message_context = Source.message_context(self.event.context,
                                                     self.event.trigger_result)

        message = self.destination.get_message(message_context)
        options = self.destination.options
        logger.debug('XXX here - message/options: %s/%s' % (message, options))
        if options:
            level = AlertLevels.find(options.get('level', None))

        try:
            alert = Alert(event=self.event,
                          level=level or sender.level,
                          sender=self.destination.sender,
                          message=message,
                          options=options)
            # need to save to get datetime assigned
            alert.save()
            logger.debug('Sending Alert %s via Destination %s' %
                         (alert, self.destination))
        except Exception as e:
            logger.error('Error saving Alert: %s' % e)

        try:
            # even if we had an error saving, may be able to still send alert
            sender.send(alert)
        except:
            logger.exception("An error occurred while sending alert %s"
                             " via Destination %s" % (alert, self.destination))