本文整理汇总了Python中alerta.models.alert.Alert.attributes方法的典型用法代码示例。如果您正苦于以下问题:Python Alert.attributes方法的具体用法?Python Alert.attributes怎么用?Python Alert.attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alerta.models.alert.Alert
的用法示例。
在下文中一共展示了Alert.attributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_action
# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import attributes [as 别名]
def process_action(alert: Alert, action: str, text: str) -> Tuple[Alert, str, str]:
wanted_plugins, wanted_config = plugins.routing(alert)
updated = None
for plugin in wanted_plugins:
if alert.is_suppressed:
break
try:
updated = plugin.take_action(alert, action, text, config=wanted_config)
except NotImplementedError:
pass # plugin does not support action() method
except RejectException:
raise
except Exception as e:
if current_app.config['PLUGINS_RAISE_ON_ERROR']:
raise ApiError("Error while running action plugin '{}': {}".format(plugin.name, str(e)))
else:
logging.error("Error while running action plugin '{}': {}".format(plugin.name, str(e)))
if updated:
try:
alert, action, text = updated
except Exception:
alert = updated
# remove keys from attributes with None values
new_attrs = {k: v for k, v in alert.attributes.items() if v is not None}
alert.attributes = new_attrs
return alert, action, text
示例2: process_status
# 需要导入模块: from alerta.models.alert import Alert [as 别名]
# 或者: from alerta.models.alert.Alert import attributes [as 别名]
def process_status(alert: Alert, status: str, text: str) -> Tuple[Alert, str, str]:
wanted_plugins, wanted_config = plugins.routing(alert)
updated = None
for plugin in wanted_plugins:
if alert.is_suppressed:
break
try:
updated = plugin.status_change(alert, status, text, config=wanted_config)
except TypeError:
updated = plugin.status_change(alert, status, text) # for backward compatibility
except RejectException:
raise
except Exception as e:
if current_app.config['PLUGINS_RAISE_ON_ERROR']:
raise ApiError("Error while running status plugin '{}': {}".format(plugin.name, str(e)))
else:
logging.error("Error while running status plugin '{}': {}".format(plugin.name, str(e)))
if updated:
try:
alert, status, text = updated
except Exception:
alert = updated
# remove keys from attributes with None values
new_attrs = {k: v for k, v in alert.attributes.items() if v is not None}
alert.attributes = new_attrs
return alert, status, text