Exemplo n.º 1
0
def sanitize_event(event):
    """
    Sanitize event by removing all items except the ones in autoscale schema.

    :param dict event: Event to sanitize as given by Twisted

    :return: (dict, bool, str, str) tuple where dict -> sanitized event,
        bool -> is it error event?, str -> ISO8601 formatted UTC time of event,
        str -> tenant ID
    """
    cf_event = {}
    error = False

    # Get message
    cf_event["message"] = event["message"][0]

    # map keys in event to CF keys
    for log_key, cf_key in log_cf_mapping.iteritems():
        if log_key in event and log_key != "message":
            cf_event[cf_key] = event[log_key]

    if event["level"] == LogLevel.ERROR:
        error = True
        if "traceback" in cf_event["message"] or "exception" in cf_event["message"]:
            raise UnsuitableMessage(cf_event["message"])

    if "tenant_id" not in event or "cloud_feed_id" not in event:
        raise UnsuitableMessage(cf_event["message"])

    return (cf_event, error, epoch_to_utctimestr(event["time"]), event["tenant_id"], event["cloud_feed_id"])
Exemplo n.º 2
0
def sanitize_event(event):
    """
    Sanitize event by removing all items except the ones in autoscale schema.

    :param dict event: Event to sanitize as given by Twisted

    :return: (dict, bool, str, str) tuple where dict -> sanitized event,
        bool -> is it error event?, str -> ISO8601 formatted UTC time of event,
        str -> tenant ID
    """
    cf_event = {}
    error = False

    # Get message
    cf_event["message"] = event["message"][0]

    # map keys in event to CF keys
    for log_key, cf_key in log_cf_mapping.iteritems():
        if log_key in event and log_key != 'message':
            cf_event[cf_key] = event[log_key]

    if event["level"] == LogLevel.ERROR:
        error = True
        if ('traceback' in cf_event['message'] or
           'exception' in cf_event['message']):
            raise UnsuitableMessage(cf_event['message'])

    if 'tenant_id' not in event or 'cloud_feed_id' not in event:
        raise UnsuitableMessage(cf_event['message'])

    return (cf_event,
            error,
            epoch_to_utctimestr(event["time"]),
            event['tenant_id'],
            event['cloud_feed_id'])
Exemplo n.º 3
0
 def test_epoch_to_utctimestr(self):
     """
     ``epoch_to_utctimestr`` generates correct ISO formatted string
     """
     self.assertEqual(
         timestamp.epoch_to_utctimestr(0), '1970-01-01T00:00:00Z')