def parse_stackdriver(notification):

    notification = json.loads(notification)
    incident = notification['incident']
    state = incident['state']

    if state == 'acknowledged':
        try:
            alert = db.get_alerts(query={'attributes.incidentId': incident['incident_id']}, limit=1)[0]
        except __HOLE__:
            raise ValueError('unknown Stackdriver Incident ID: %s' % incident['incident_id'])
        return state, alert

    else:
        if state == 'open':
            severity = 'critical'
            create_time = datetime.datetime.fromtimestamp(incident['started_at'])
        elif state == 'closed':
            severity = 'ok'
            create_time = datetime.datetime.fromtimestamp(incident['ended_at'])
        else:
            severity = 'indeterminate'
            create_time = None

        return state, Alert(
            resource=incident['resource_name'],
            event=incident['condition_name'],
            environment='Production',
            severity=severity,
            service=[incident['policy_name']],
            group='Cloud',
            text=incident['summary'],
            attributes={
                'incidentId': incident['incident_id'],
                'resourceId': incident['resource_id'],
                'moreInfo': '<a href="%s" target="_blank">Stackdriver Console</a>' % incident['url']
            },
            origin='Stackdriver',
            event_type='stackdriverAlert',
            create_time=create_time,
            raw_data=notification
        )
dataset/ETHPy150Open guardian/alerta/alerta/app/webhooks/views.py/parse_stackdriver