update mobile app push notification text + make telegram alert verbage consistent ("Firing" instead of "Alerting") (#1089)
This commit is contained in:
parent
eafdaf5176
commit
802e3964e9
5 changed files with 29 additions and 10 deletions
|
|
@ -25,6 +25,7 @@ x-env-vars: &oncall-env-vars
|
|||
BROKER_TYPE: ${BROKER_TYPE}
|
||||
GRAFANA_API_URL: http://localhost:3000
|
||||
GOOGLE_APPLICATION_CREDENTIALS: /etc/app/gcp_service_account.json
|
||||
FCM_PROJECT_ID: oncall-mobile-dev
|
||||
|
||||
# basically this is needed because the oncall backend containers have been configured to communicate w/ grafana via
|
||||
# http://localhost:3000 (GRAFANA_API_URL). This URL is used in two scenarios:
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class AlertGroupTelegramRenderer(AlertGroupBaseRenderer):
|
|||
elif self.alert_group.silenced:
|
||||
status_emoji = "⚪️" # white circle
|
||||
|
||||
status_verbose = "Alerting"
|
||||
status_verbose = "Firing" # TODO: we should probably de-duplicate this text
|
||||
if self.alert_group.resolved:
|
||||
status_verbose = self.alert_group.get_resolve_text()
|
||||
elif self.alert_group.acknowledged:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from emoji import emojize
|
||||
|
||||
from apps.alerts.incident_appearance.templaters.alert_templater import AlertTemplater
|
||||
from common.utils import str_or_backup
|
||||
|
||||
|
|
@ -10,4 +12,8 @@ class AlertMobileAppTemplater(AlertTemplater):
|
|||
def get_push_notification_message(alert_group):
|
||||
alert = alert_group.alerts.first()
|
||||
templated_alert = AlertMobileAppTemplater(alert).render()
|
||||
return str_or_backup(templated_alert.title, "Alert Group")
|
||||
title = str_or_backup(templated_alert.title, "Alert Group")
|
||||
|
||||
return emojize(
|
||||
f"#{alert_group.inside_organization_number} {title} via {alert_group.channel.short_name}", use_aliases=True
|
||||
)
|
||||
|
|
|
|||
|
|
@ -51,11 +51,26 @@ def notify_user_async(user_pk, alert_group_pk, notification_policy_pk, critical)
|
|||
logger.info(f"Error while sending a mobile push notification: user {user_pk} has no device set up")
|
||||
return
|
||||
|
||||
message = get_push_notification_message(alert_group)
|
||||
thread_id = f"{alert_group.channel.organization.public_primary_key}:{alert_group.public_primary_key}"
|
||||
alert_title = f"Critical page: {message}" if critical else message
|
||||
number_of_alerts = alert_group.alerts.count()
|
||||
|
||||
alert_title = "New Critical Alert" if critical else "New Alert"
|
||||
alert_subtitle = get_push_notification_message(alert_group)
|
||||
|
||||
status_verbose = "Firing" # TODO: we should probably de-duplicate this text
|
||||
if alert_group.resolved:
|
||||
status_verbose = alert_group.get_resolve_text()
|
||||
elif alert_group.acknowledged:
|
||||
status_verbose = alert_group.get_acknowledge_text()
|
||||
|
||||
if number_of_alerts <= 10:
|
||||
alerts_count_str = str(number_of_alerts)
|
||||
else:
|
||||
alert_count_rounded = (number_of_alerts // 10) * 10
|
||||
alerts_count_str = f"{alert_count_rounded}+"
|
||||
|
||||
alert_body = f"Status: {status_verbose}, alerts: {alerts_count_str}"
|
||||
|
||||
# TODO: we should update this to check if FCM_RELAY is set and conditionally make a call here..
|
||||
|
||||
message = Message(
|
||||
|
|
@ -71,6 +86,7 @@ def notify_user_async(user_pk, alert_group_pk, notification_policy_pk, critical)
|
|||
"status": str(alert_group.status),
|
||||
"type": "oncall.critical_message" if critical else "oncall.message",
|
||||
"title": alert_title,
|
||||
"body": f"{alert_subtitle}\n{alert_body}",
|
||||
"thread_id": thread_id,
|
||||
},
|
||||
apns=APNSConfig(
|
||||
|
|
@ -78,11 +94,7 @@ def notify_user_async(user_pk, alert_group_pk, notification_policy_pk, critical)
|
|||
aps=Aps(
|
||||
thread_id=thread_id,
|
||||
badge=number_of_alerts,
|
||||
alert=ApsAlert(
|
||||
title=alert_title,
|
||||
subtitle="yooo this is a subtitle",
|
||||
body="hello this is the body",
|
||||
),
|
||||
alert=ApsAlert(title=alert_title, subtitle=alert_subtitle, body=alert_body),
|
||||
sound=CriticalSound(
|
||||
critical=1 if critical else 0,
|
||||
name="ambulance.aiff" if critical else "bingbong.aiff",
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ def test_alert_group_message(make_organization, make_alert_receive_channel, make
|
|||
text = renderer.render_alert_group_message()
|
||||
assert text == (
|
||||
f"<a href='{organization.web_link_with_uuid}'>‍</a>🔴 #{alert_group.inside_organization_number}, {alert_receive_channel.config.tests['telegram']['title']}\n"
|
||||
"Alerting, alerts: 1\n"
|
||||
"Firing, alerts: 1\n"
|
||||
"Source: Test integration - Grafana\n"
|
||||
f"{alert_group.web_link}\n\n"
|
||||
f"{alert_receive_channel.config.tests['telegram']['message']}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue