Exemplo n.º 1
0
def tag_alert(id):

    tag_started = tag_timer.start_timer()
    customer = g.get('customer', None)
    try:
        alert = db.get_alert(id=id, customer=customer)
    except Exception as e:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error", message=str(e)), 500

    if not alert:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error",
                       message="not found",
                       total=0,
                       alert=None), 404

    data = request.json

    if data and 'tags' in data:
        try:
            response = db.tag_alert(id, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error",
                       message="must supply 'tags' as list parameter"), 400

    tag_timer.stop_timer(tag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 2
0
def tag_alert(tenant, id):

    # FIXME - should only allow role=user to set status for alerts for that customer
    # Above comment is from original code, can ignore for now

    tag_started = tag_timer.start_timer()

    data = request.json

    tenant = generateDBName(tenant)

    if data and 'tags' in data:
        try:
            response = db.tag_alert(id, tenant, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error", message="must supply 'tags' as list parameter"), 400

    tag_timer.stop_timer(tag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 3
0
def tag_alert(id):

    tag_started = tag_timer.start_timer()
    customer = g.get('customer', None)
    try:
        alert = db.get_alert(id=id, customer=customer)
    except Exception as e:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error", message=str(e)), 500

    if not alert:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error", message="not found", total=0, alert=None), 404

    data = request.json

    if data and 'tags' in data:
        try:
            response = db.tag_alert(id, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error", message="must supply 'tags' as list parameter"), 400

    tag_timer.stop_timer(tag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 4
0
def tag_alert(id):

    data = request.json

    if data and 'tags' in data:
        response = db.tag_alert(id, data['tags'])
    else:
        return jsonify(status="error", message="no data")

    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="failed to tag alert")
Exemplo n.º 5
0
def tag_alert(id):

    tag_started = tag_timer.start_timer()
    data = request.json

    if data and 'tags' in data:
        try:
            response = db.tag_alert(id, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error", message="must supply 'tags' as list parameter"), 400

    tag_timer.stop_timer(tag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 6
0
def tag_alert(id):

    tag_started = tag_timer.start_timer()
    data = request.json

    if data and 'tags' in data:
        try:
            response = db.tag_alert(id, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        tag_timer.stop_timer(tag_started)
        return jsonify(status="error",
                       message="must supply 'tags' as list parameter"), 400

    tag_timer.stop_timer(tag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 7
0
 def tag(self, tags: List[str]) -> bool:
     return db.tag_alert(self.id, tags)
Exemplo n.º 8
0
 def tag(self, tags):
     return db.tag_alert(self.id, tags)
Exemplo n.º 9
0
 def tag(self, tags):
     return db.tag_alert(self.id, tags)
Exemplo n.º 10
0
def pagerduty():

    if not request.json or not 'messages' in request.json:
        abort(400)

    for message in request.json['messages']:

        LOG.debug('%s', json.dumps(message))

        id = message['data']['incident']['incident_key']
        html_url = message['data']['incident']['html_url']
        incident_number = message['data']['incident']['incident_number']
        incident_url = '<a href="%s">#%s</a>' % (html_url, incident_number)

        LOG.info('PagerDuty incident #%s webhook for alert %s', incident_number, id)

        LOG.error('previous status %s', db.get_alert(id=id).status)

        if message['type'] == 'incident.trigger':
            status = status_code.OPEN
            user = message['data']['incident']['assigned_to_user']['name']
            text = 'Incident %s assigned to %s' % (incident_url, user)
        elif message['type'] == 'incident.acknowledge':
            status = status_code.ACK
            user = message['data']['incident']['assigned_to_user']['name']
            text = 'Incident %s acknowledged by %s' % (incident_url, user)
        elif message['type'] == 'incident.unacknowledge':
            status = status_code.OPEN
            text = 'Incident %s unacknowledged due to timeout' % incident_url
        elif message['type'] == 'incident.resolve':
            status = status_code.CLOSED
            if message['data']['incident']['resolved_by_user']:
                user = message['data']['incident']['resolved_by_user']['name']
            else:
                user = '******'
            text = 'Incident %s resolved by %s' % (incident_url, user)
        elif message['type'] == 'incident.assign':
            status = status_code.ASSIGN
            user = message['data']['incident']['assigned_to_user']['name']
            text = 'Incident %s manually assigned to %s' % (incident_url, user)
        elif message['type'] == 'incident.escalate':
            status = status_code.OPEN
            user = message['data']['incident']['assigned_to_user']['name']
            text = 'Incident %s escalated to %s' % (incident_url, user)
        elif message['type'] == 'incident.delegate':
            status = status_code.OPEN
            user = message['data']['incident']['assigned_to_user']['name']
            text = 'Incident %s reassigned due to escalation to %s' % (incident_url, user)
        else:
            status = status_code.UNKNOWN
            text = message['type']
            LOG.warn('Unknown PagerDuty message type: %s', message)

        LOG.info('PagerDuty webhook %s change status to %s', message['type'], status)

        pdAlert = db.update_status(id=id, status=status, text=text)
        db.tag_alert(id=id, tags='incident=#%s' % incident_number)

        LOG.error('returned status %s', pdAlert.status)
        LOG.error('current status %s', db.get_alert(id=id).status)

        # Forward alert to notify topic and logger queue
        if pdAlert:
            pdAlert.origin = 'pagerduty/webhook'
            notify.send(pdAlert)

    return jsonify(status="ok")
Exemplo n.º 11
0
 def tag(self, tags: List[str]) -> bool:
     return db.tag_alert(self.id, tags)