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

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

    if not alert:
        untag_timer.stop_timer(untag_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.untag_alert(id, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        untag_timer.stop_timer(untag_started)
        return jsonify(status="error",
                       message="must supply 'tags' as list parameter"), 400

    untag_timer.stop_timer(untag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 2
0
def untag_alert(id):

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

    if not alert:
        untag_timer.stop_timer(untag_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.untag_alert(id, data['tags'])
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        untag_timer.stop_timer(untag_started)
        return jsonify(status="error", message="must supply 'tags' as list parameter"), 400

    untag_timer.stop_timer(untag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 3
0
def slack():
    hook_started = webhook_timer.start_timer()
    try:
        alert, user, action = parse_slack(request.form)
    except ValueError as e:
        webhook_timer.stop_timer(hook_started)
        return jsonify(stats="error", message="not found"), 404
    except Exception as e:
        webhook_timer.stop_timer(hook_started)
        return jsonify(status="error", message=str(e)), 500

    if action in ['open', 'ack', 'close']:
        try:
            alert = db.set_status(
                alert.id, action,
                u"status change via Slack by {}".format(user))
        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

    elif action in ['watch', 'unwatch']:
        db.untag_alert(alert.id, [
            "{}:{}".format(action, user),
        ])

    else:
        webhook_timer.stop_timer(hook_started)
        return jsonify(status="error", message=u'Unsuported action'), 403

    response = build_slack_response(alert, action, user, request.form)

    webhook_timer.stop_timer(hook_started)
    return jsonify(**response), 201
Exemplo n.º 4
0
def telegram():
    data = request.json
    if 'callback_query' in data:
        author = data['callback_query']['from']
        command, alert = data['callback_query']['data'].split(' ', 1)
        user = "******".format(author.get('first_name'),
                              author.get('last_name'))

        action = command.lstrip('/')
        if action in ['open', 'ack', 'close']:
            db.set_status(alert, action, 'status change via Telegram')
        elif action in ['watch', 'unwatch']:
            db.untag_alert(alert, [
                "{}:{}".format(action, user),
            ])
        elif action == 'blackout':
            environment, resource, event = alert.split('|', 2)
            db.create_blackout(environment, resource=resource, event=event)

        send_message_reply(alert, action, user, data)
        return jsonify(status="ok")
    else:
        return jsonify(status="error",
                       message="no callback_query in Telegram message"), 400
Exemplo n.º 5
0
def untag_alert(id):

    untag_started = untag_timer.start_timer()
    data = request.json

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

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

    untag_started = untag_timer.start_timer()
    data = request.json

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

    untag_timer.stop_timer(untag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 7
0
def untag_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

    untag_started = untag_timer.start_timer()
    data = request.json

    tenant = generateDBName(tenant)

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

    untag_timer.stop_timer(untag_started)
    if response:
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="not found"), 404
Exemplo n.º 8
0
 def untag(self, tags: List[str]) -> bool:
     return db.untag_alert(self.id, tags)
Exemplo n.º 9
0
 def untag(self, tags):
     return db.untag_alert(self.id, tags)
Exemplo n.º 10
0
 def untag(self, tags):
     return db.untag_alert(self.id, tags)
Exemplo n.º 11
0
 def untag(self, tags: List[str]) -> bool:
     return db.untag_alert(self.id, tags)