@app.route('/webhooks/pagerduty', methods=['OPTIONS', 'POST'])
@cross_origin()
@auth_required
def pagerduty():

    hook_started = webhook_timer.start_timer()
    data = request.json

    if data and 'messages' in data:
        for message in data['messages']:
            try:
                id, status, text = parse_pagerduty(message)
            except __HOLE__ as e:
                webhook_timer.stop_timer(hook_started)
                return jsonify(status="error", message=str(e)), 400

            try:
                alert = db.set_status(id=id, status=status, text=text)
            except Exception as e:
                webhook_timer.stop_timer(hook_started)
                return jsonify(status="error", message=str(e)), 500
    else:
        webhook_timer.stop_timer(hook_started)
        return jsonify(status="error", message="no messages in PagerDuty data payload"), 400

    webhook_timer.stop_timer(hook_started)

    if alert:
        return jsonify(status="ok"), 200
    else:
        return jsonify(status="error", message="update PagerDuty incident status failed"), 500
dataset/ETHPy150Open guardian/alerta/alerta/app/webhooks/views.py/pagerduty