def prometheus(): if request.json and 'alerts' in request.json: hook_started = webhook_timer.start_timer() status = request.json['status'] for alert in request.json['alerts']: try: incomingAlert = parse_prometheus(status, alert) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) else: return jsonify( status="error", message="no alerts in Prometheus notification payload"), 400 return jsonify(status="ok"), 200
def prometheus(): if request.json and 'alerts' in request.json: hook_started = webhook_timer.start_timer() status = request.json['status'] for alert in request.json['alerts']: try: incomingAlert = parse_prometheus(status, alert) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') try: process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) else: return jsonify(status="error", message="no alerts in Prometheus notification payload"), 400 return jsonify(status="ok"), 200
def prometheus(): if request.json: hook_started = webhook_timer.start_timer() for notification in request.json: try: incomingAlert = parse_prometheus(notification) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) else: return jsonify(status="error", message="no alerts in Prometheus notification payload"), 400 return jsonify(status="ok"), 200
def pingdom(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_pingdom(request.args.get('message')) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': '%s/%s' % (request.base_url, alert.id) } else: return jsonify(status="error", message="insert or update of pingdom check failed"), 500
def pingdom(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_pingdom(request.args.get('message')) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': '%s/%s' % (request.base_url, alert.id)} else: return jsonify(status="error", message="insert or update of pingdom check failed"), 500
def stackdriver(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_stackdriver(request.get_json(force=True)) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="notification from stackdriver failed"), 500
def newrelic(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_newrelic(request.json) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get("customer", None): incomingAlert.customer = g.get("customer") try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body["href"] = absolute_url("/alert/" + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {"Location": body["href"]} else: return jsonify(status="error", message="insert or update of New Relic alert failed"), 500
def receive_alert(): recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 if request.headers.getlist("X-Forwarded-For"): incomingAlert.attributes.update(ip=request.headers.getlist("X-Forwarded-For")[0]) else: incomingAlert.attributes.update(ip=request.remote_addr) try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except RuntimeWarning as e: receive_timer.stop_timer(recv_started) return jsonify(status="ok", id=incomingAlert.id, message=str(e)), 202 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': '%s/%s' % (request.base_url, alert.id)} else: return jsonify(status="error", message="insert or update of received alert failed"), 500
def prometheus(): alerts = [] if request.json and 'alerts' in request.json: hook_started = webhook_timer.start_timer() for alert in request.json['alerts']: try: incomingAlert = parse_prometheus(alert) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 alerts.append(alert) webhook_timer.stop_timer(hook_started) else: return jsonify(status="error", message="no alerts in Prometheus notification payload"), 400 if len(alerts) == 1: body = alerts[0].get_body() body['href'] = absolute_url('/alert/' + alerts[0].id) return jsonify(status="ok", id=alerts[0].id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="ok", ids=[alert.id for alert in alerts]), 201
def cloudwatch(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_notification(request.data) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body["href"] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {"Location": "%s/%s" % (request.base_url, alert.id)} else: return jsonify(status="error", message="insert or update of cloudwatch alarm failed"), 500
def cloudwatch(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_notification(request.data) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': body['href'] } else: return jsonify( status="error", message="insert or update of cloudwatch alarm failed"), 500
def riemann(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_riemann(request.json) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="insert or update of Riemann alert failed"), 500
def cloudwatch(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_notification(request.data) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="insert or update of cloudwatch alarm failed"), 500
def stackdriver(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_stackdriver(request.json) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="notification from stackdriver failed"), 500
def receive_alert(): if not Switch.get('sender-api-allow').is_on(): return jsonify( status="error", message="API not accepting alerts. Try again later."), 503 recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') if request.headers.getlist("X-Forwarded-For"): incomingAlert.attributes.update( ip=request.headers.getlist("X-Forwarded-For")[0]) else: incomingAlert.attributes.update(ip=request.remote_addr) try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except RuntimeWarning as e: receive_timer.stop_timer(recv_started) return jsonify(status="ok", id=incomingAlert.id, message=str(e)), 202 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': body['href'] } else: return jsonify( status="error", message="insert or update of received alert failed"), 500
def receive_alert(): if not Switch.get('sender-api-allow').is_on(): return jsonify( status="error", message="API not accepting alerts. Try again later."), 503 recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except RateLimit as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", id=incomingAlert.id, message=str(e)), 429 except BlackoutPeriod as e: receive_timer.stop_timer(recv_started) return jsonify(status="ok", id=incomingAlert.id, message=str(e)), 202 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': body['href'] } else: return jsonify( status="error", message="insert or update of received alert failed"), 500
def receive_alert(): recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') if request.headers.getlist("X-Forwarded-For"): incomingAlert.attributes.update( ip=request.headers.getlist("X-Forwarded-For")[0]) else: incomingAlert.attributes.update(ip=request.remote_addr) try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except RuntimeWarning as e: receive_timer.stop_timer(recv_started) return jsonify(status="ok", id=incomingAlert.id, message=str(e)), 202 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': '%s/%s' % (request.base_url, alert.id) } else: return jsonify( status="error", message="insert or update of received alert failed"), 500
def stackdriver(): hook_started = webhook_timer.start_timer() try: state, incomingAlert = parse_stackdriver(request.data) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') if state == 'acknowledged': try: alert = db.set_status(id=incomingAlert.id, status='ack', text='acknowledged via Stackdriver') except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 else: try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': body['href'] } else: return jsonify(status="error", message="notification from stackdriver failed"), 500
def receive_alert(): if not Switch.get('sender-api-allow').is_on(): return jsonify(status="error", message="API not accepting alerts. Try again later."), 503 recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') if request.headers.getlist("X-Forwarded-For"): incomingAlert.attributes.update(ip=request.headers.getlist("X-Forwarded-For")[0]) else: incomingAlert.attributes.update(ip=request.remote_addr) try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except RuntimeWarning as e: receive_timer.stop_timer(recv_started) return jsonify(status="ok", id=incomingAlert.id, message=str(e)), 202 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="insert or update of received alert failed"), 500
def receive_alert(): if not Switch.get('sender-api-allow').is_on(): return jsonify(status="error", message="API not accepting alerts. Try again later."), 503 recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except RateLimit as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", id=incomingAlert.id, message=str(e)), 429 except BlackoutPeriod as e: receive_timer.stop_timer(recv_started) return jsonify(status="ok", id=incomingAlert.id, message=str(e)), 202 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="insert or update of received alert failed"), 500
def prometheus(): alerts = [] if request.json and 'alerts' in request.json: hook_started = webhook_timer.start_timer() for alert in request.json['alerts']: try: incomingAlert = parse_prometheus(alert) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 alerts.append(alert) webhook_timer.stop_timer(hook_started) else: return jsonify(status="error", message="no alerts in Prometheus notification payload"), 400 if len(alerts) == 1: body = alerts[0].get_body() body['href'] = absolute_url('/alert/' + alerts[0].id) return jsonify(status="ok", id=alerts[0].id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="ok", ids=[alert.id for alert in alerts]), 201
def stackdriver(): hook_started = webhook_timer.start_timer() try: state, incomingAlert = parse_stackdriver(request.data) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') if state == 'acknowledged': try: alert = db.set_status(id=incomingAlert.id, status='ack', text='acknowledged via Stackdriver') except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 else: try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = absolute_url('/alert/' + alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="error", message="notification from stackdriver failed"), 500
def grafana(): hook_started = webhook_timer.start_timer() alerts = [] data = request.json if data and data['state'] == 'alerting': for match in data.get('evalMatches', []): try: incomingAlert = parse_grafana(data, match) except ValueError as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 if g.get('customer', None): incomingAlert.customer = g.get('customer') add_remote_ip(request, incomingAlert) try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 alerts.append(alert) webhook_timer.stop_timer(hook_started) elif data and data['state'] == 'ok' and data.get('ruleId', None): try: existingAlerts = db.get_alerts({'attributes.ruleId': data['ruleId'], 'customer': g.get('customer', None)}) except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 for updateAlert in existingAlerts: updateAlert.severity = 'normal' updateAlert.status = 'closed' try: alert = process_alert(updateAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 alerts.append(alert) webhook_timer.stop_timer(hook_started) else: return jsonify(status="error", message="no alerts in Grafana notification payload"), 400 if len(alerts) == 1: body = alerts[0].get_body() body['href'] = absolute_url('/alert/' + alerts[0].id) return jsonify(status="ok", id=alerts[0].id, alert=body), 201, {'Location': body['href']} else: return jsonify(status="ok", ids=[alert.id for alert in alerts]), 201
@app.route('/webhooks/cloudwatch', methods=['OPTIONS', 'POST']) @crossdomain(origin='*', headers=['Origin', 'X-Requested-With', 'Content-Type', 'Accept']) @jsonp def cloudwatch(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_notification(request.data) except ValueError, e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': '%s/%s' % (request.base_url, alert.id) }
@app.route('/alert', methods=['OPTIONS', 'POST']) @crossdomain(origin='*', headers=['Origin', 'X-Requested-With', 'Content-Type', 'Accept', 'Authorization']) @auth_required @jsonp def receive_alert(): recv_started = receive_timer.start_timer() try: incomingAlert = Alert.parse_alert(request.data) except ValueError, e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: receive_timer.stop_timer(recv_started) return jsonify(status="error", message=str(e)), 500 receive_timer.stop_timer(recv_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': '%s/%s' % (request.base_url, alert.id)} else: return jsonify(status="error", message="insert or update of received alert failed"), 500