当前位置: 首页>>代码示例>>Python>>正文


Python Alert.find_by_id方法代码示例

本文整理汇总了Python中alerta.models.alert.Alert.find_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Alert.find_by_id方法的具体用法?Python Alert.find_by_id怎么用?Python Alert.find_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alerta.models.alert.Alert的用法示例。


在下文中一共展示了Alert.find_by_id方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: telegram

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def telegram():

    data = request.json
    if 'callback_query' in data:
        author = data['callback_query']['from']
        user = "{} {}".format(author.get('first_name'), author.get('last_name'))
        command, alert_id = data['callback_query']['data'].split(' ', 1)

        alert = Alert.find_by_id(alert_id)
        if not alert:
            jsonify(status="error", message="alert not found for Telegram message")

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

        send_message_reply(alert, action, user, data)
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="no callback_query in Telegram message"), 400
开发者ID:3IWOH,项目名称:alerta,代码行数:28,代码来源:telegram.py

示例2: pagerduty

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def pagerduty():

    data = request.json

    updated = False
    if data and 'messages' in data:
        for message in data['messages']:
            try:
                incident_key, status, text = parse_pagerduty(message)
            except ValueError as e:
                raise ApiError(str(e), 400)

            if not incident_key:
                raise ApiError('no incident key in PagerDuty data payload', 400)

            customer = g.get('customer', None)
            try:
                alert = Alert.find_by_id(id=incident_key, customer=customer)
            except Exception as e:
                raise ApiError(str(e), 500)

            if not alert:
                raise ApiError("not found", 404)

            try:
                updated = alert.set_status(status, text)
            except Exception as e:
                raise ApiError(str(e), 500)
    else:
        raise ApiError("no messages in PagerDuty data payload", 400)

    if updated:
        return jsonify(status="ok"), 200
    else:
        raise ApiError("update PagerDuty incident status failed", 500)
开发者ID:3IWOH,项目名称:alerta,代码行数:37,代码来源:pagerduty.py

示例3: action_alerts

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def action_alerts(alerts: List[str], action: str, text: str, timeout: int) -> None:
    updated = []
    errors = []
    for alert_id in alerts:
        alert = Alert.find_by_id(alert_id)

        try:
            previous_status = alert.status
            alert, action, text = process_action(alert, action, text)
            alert = alert.from_action(action, text, timeout)
        except RejectException as e:
            errors.append(str(e))
            continue
        except InvalidAction as e:
            errors.append(str(e))
            continue
        except Exception as e:
            errors.append(str(e))
            continue

        if previous_status != alert.status:
            try:
                alert, status, text = process_status(alert, alert.status, text)
                alert = alert.from_status(status, text, timeout)
            except RejectException as e:
                errors.append(str(e))
                continue
            except Exception as e:
                errors.append(str(e))
                continue

        updated.append(alert.id)
开发者ID:guardian,项目名称:alerta,代码行数:34,代码来源:tasks.py

示例4: incoming

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
    def incoming(self, query_string, payload):

        if 'callback_query' in payload:
            author = payload['callback_query']['from']
            user = '{} {}'.format(author.get('first_name'), author.get('last_name'))
            command, alert_id = payload['callback_query']['data'].split(' ', 1)

            customers = g.get('customers', None)
            alert = Alert.find_by_id(alert_id, customers=customers)
            if not alert:
                jsonify(status='error', message='alert not found for Telegram message')

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

            send_message_reply(alert, action, user, payload)

            text = 'alert updated via telegram webhook'
            write_audit_trail.send(current_app._get_current_object(), event='webhook-updated', message=text,
                                   user=g.login, customers=g.customers, scopes=g.scopes, resource_id=alert.id,
                                   type='alert', request=request)

            return jsonify(status='ok')
        else:
            return jsonify(status='ok', message='no callback_query in Telegram message')
开发者ID:guardian,项目名称:alerta,代码行数:34,代码来源:telegram.py

示例5: incoming

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
    def incoming(self, query_string, payload):

        updated = False
        if payload and 'messages' in payload:
            for message in payload['messages']:
                try:
                    incident_key, status, text = parse_pagerduty(message)
                except ValueError as e:
                    raise ApiError(str(e), 400)

                if not incident_key:
                    raise ApiError('no incident key in PagerDuty data payload', 400)

                customers = g.get('customers', None)
                try:
                    alert = Alert.find_by_id(id=incident_key, customers=customers)
                except Exception as e:
                    raise ApiError(str(e), 500)

                if not alert:
                    raise ApiError('not found', 404)

                try:
                    updated = alert.set_status(status, text)
                except Exception as e:
                    raise ApiError(str(e), 500)

            if updated:
                return jsonify(status='ok')
            else:
                raise ApiError('update PagerDuty incident status failed', 500)

        else:
            raise ApiError('no messages in PagerDuty data payload', 400)
开发者ID:guardian,项目名称:alerta,代码行数:36,代码来源:pagerduty.py

示例6: get_alert

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def get_alert(alert_id):
    customer = g.get('customer', None)
    alert = Alert.find_by_id(alert_id, customer)

    if alert:
        return jsonify(status="ok", total=1, alert=alert.serialize)
    else:
        raise ApiError("not found", 404)
开发者ID:kattunga,项目名称:alerta,代码行数:10,代码来源:alerts.py

示例7: delete_alert

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def delete_alert(alert_id):
    customer = g.get('customer', None)
    alert = Alert.find_by_id(alert_id, customer)

    if not alert:
        raise ApiError("not found", 404)

    if alert.delete():
        return jsonify(status="ok")
    else:
        raise ApiError("failed to delete alert", 500)
开发者ID:kattunga,项目名称:alerta,代码行数:13,代码来源:alerts.py

示例8: update_attributes

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def update_attributes(alert_id):
    if not request.json.get('attributes', None):
        raise ApiError("must supply 'attributes' as json data", 400)

    customer = g.get('customer', None)
    alert = Alert.find_by_id(alert_id, customer)

    if not alert:
        raise ApiError("not found", 404)

    if alert.update_attributes(request.json['attributes']):
        return jsonify(status="ok")
    else:
        raise ApiError("failed to update attributes", 500)
开发者ID:kattunga,项目名称:alerta,代码行数:16,代码来源:alerts.py

示例9: untag_alert

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def untag_alert(alert_id):
    if not request.json.get('tags', None):
        raise ApiError("must supply 'tags' as json list")

    customer = g.get('customer', None)
    alert = Alert.find_by_id(alert_id, customer)

    if not alert:
        raise ApiError("not found", 404)

    if alert.untag(tags=request.json['tags']):
        return jsonify(status="ok")
    else:
        raise ApiError("failed to untag alert", 500)
开发者ID:kattunga,项目名称:alerta,代码行数:16,代码来源:alerts.py

示例10: slack

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def slack():
    alert_id, user, action = parse_slack(request.form)

    alert = Alert.find_by_id(alert_id)
    if not alert:
        jsonify(status="error", message="alert not found for #slack message")

    if action in ['open', 'ack', 'close']:
        alert.set_status(status=action, text="status change via #slack by {}".format(user))
    elif action in ['watch', 'unwatch']:
        alert.untag(alert.id, ["{}:{}".format(action, user)])
    else:
        raise ApiError('Unsupported #slack action', 400)

    response = build_slack_response(alert, action, user, request.form)
    return jsonify(**response), 201
开发者ID:3IWOH,项目名称:alerta,代码行数:18,代码来源:slack.py

示例11: incoming

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
    def incoming(self, query_string, payload):

        alert_id, user, action = parse_slack(payload)

        customers = g.get('customers', None)
        alert = Alert.find_by_id(alert_id, customers=customers)
        if not alert:
            jsonify(status='error', message='alert not found for #slack message')

        if action in ['open', 'ack', 'close']:
            alert.set_status(status=action, text='status change via #slack by {}'.format(user))
        elif action in ['watch', 'unwatch']:
            alert.untag(tags=['{}:{}'.format(action, user)])
        else:
            raise ApiError('Unsupported #slack action', 400)

        text = 'alert updated via slack webhook'
        write_audit_trail.send(current_app._get_current_object(), event='webhook-updated', message=text,
                               user=g.login, customers=g.customers, scopes=g.scopes, resource_id=alert.id,
                               type='alert', request=request)

        response = build_slack_response(alert, action, user, payload)
        return jsonify(**response), 201
开发者ID:guardian,项目名称:alerta,代码行数:25,代码来源:slack.py

示例12: set_status

# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import find_by_id [as 别名]
def set_status(alert_id):
    status = request.json.get('status', None)
    text = request.json.get('text', '')

    if not status:
        raise ApiError("must supply 'status' as json data")

    customer = g.get('customer', None)
    alert = Alert.find_by_id(alert_id, customer)

    if not alert:
        raise ApiError("not found", 404)

    try:
        alert, status, text = process_status(alert, status, text)
    except RejectException as e:
        raise ApiError(str(e), 403)
    except Exception as e:
        raise ApiError(str(e), 500)

    if alert.set_status(status, text):
        return jsonify(status="ok")
    else:
        raise ApiError("failed to set alert status", 500)
开发者ID:kattunga,项目名称:alerta,代码行数:26,代码来源:alerts.py


注:本文中的alerta.models.alert.Alert.find_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。