mirror of https://github.com/zulip/zulip.git
webhooks/librato: Use proper punctuation.
This commit is contained in:
parent
d733cc500c
commit
c012362fde
|
@ -16,17 +16,17 @@ class LibratoHookTests(WebhookTestCase):
|
|||
|
||||
def test_alert_message_with_default_topic(self) -> None:
|
||||
expected_topic = 'Alert alert.name'
|
||||
expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl)\n>Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 09:11:42 UTC\n>Metric `librato.swap.swap.cached`, average was absent by 300s, recorded at 2016-03-31 09:11:42 UTC\n>Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 09:11:42 UTC"
|
||||
expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl):\n * Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 09:11:42 UTC.\n * Metric `librato.swap.swap.cached`, average was absent by 300s, recorded at 2016-03-31 09:11:42 UTC.\n * Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 09:11:42 UTC."
|
||||
self.send_and_test_stream_message('alert', expected_topic, expected_message, content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def test_alert_message_with_custom_topic(self) -> None:
|
||||
custom_topic = 'custom_name'
|
||||
self.url = self.build_webhook_url(topic=custom_topic)
|
||||
expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl)\n>Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 09:11:42 UTC\n>Metric `librato.swap.swap.cached`, average was absent by 300s, recorded at 2016-03-31 09:11:42 UTC\n>Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 09:11:42 UTC"
|
||||
expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl):\n * Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 09:11:42 UTC.\n * Metric `librato.swap.swap.cached`, average was absent by 300s, recorded at 2016-03-31 09:11:42 UTC.\n * Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 09:11:42 UTC."
|
||||
self.send_and_test_stream_message('alert', custom_topic, expected_message, content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def test_three_conditions_alert_message(self) -> None:
|
||||
expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.use.water.pl)\n>Metric `collectd.interface.eth0.if_octets.tx`, absolute_value was above 4 by 300s, recorded at 2016-04-11 20:40:14 UTC\n>Metric `collectd.load.load.longterm`, max was above 99, recorded at 2016-04-11 20:40:14 UTC\n>Metric `librato.swap.swap.cached`, average was absent by 60s, recorded at 2016-04-11 20:40:14 UTC"
|
||||
expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.use.water.pl):\n * Metric `collectd.interface.eth0.if_octets.tx`, absolute_value was above 4 by 300s, recorded at 2016-04-11 20:40:14 UTC.\n * Metric `collectd.load.load.longterm`, max was above 99, recorded at 2016-04-11 20:40:14 UTC.\n * Metric `librato.swap.swap.cached`, average was absent by 60s, recorded at 2016-04-11 20:40:14 UTC."
|
||||
expected_topic = 'Alert ToHighTemeprature'
|
||||
self.send_and_test_stream_message('three_conditions_alert', expected_topic, expected_message, content_type="application/x-www-form-urlencoded")
|
||||
|
||||
|
@ -38,6 +38,6 @@ class LibratoHookTests(WebhookTestCase):
|
|||
def test_snapshot(self) -> None:
|
||||
self.IS_ATTACHMENT = True
|
||||
expected_topic = 'Snapshots'
|
||||
expected_message = "**Hamlet** sent a [snapshot](http://snapshots.librato.com/chart/nr5l3n0c-82162.png) of [metric](https://metrics.librato.com/s/spaces/167315/explore/1731491?duration=72039&end_time=1460569409)"
|
||||
expected_message = "**Hamlet** sent a [snapshot](http://snapshots.librato.com/chart/nr5l3n0c-82162.png) of [metric](https://metrics.librato.com/s/spaces/167315/explore/1731491?duration=72039&end_time=1460569409)."
|
||||
self.send_and_test_stream_message('snapshot', expected_topic, expected_message, content_type="application/x-www-form-urlencoded")
|
||||
self.IS_ATTACHMENT = False
|
||||
|
|
|
@ -104,7 +104,7 @@ class LibratoWebhookHandler(LibratoWebhookParser):
|
|||
return content
|
||||
|
||||
def handle_snapshot(self, snapshot: Dict[str, Any]) -> str:
|
||||
snapshot_template = u"**{author_name}** sent a [snapshot]({image_url}) of [metric]({title})"
|
||||
snapshot_template = u"**{author_name}** sent a [snapshot]({image_url}) of [metric]({title})."
|
||||
author_name, image_url, title = self.parse_snapshot(snapshot)
|
||||
content = snapshot_template.format(author_name=author_name, image_url=image_url, title=title)
|
||||
return content
|
||||
|
@ -114,7 +114,7 @@ class LibratoWebhookHandler(LibratoWebhookParser):
|
|||
alert_id, alert_name, alert_url, alert_runbook_url = self.parse_alert()
|
||||
content = alert_violation_template.format(alert_name=alert_name, alert_url=alert_url)
|
||||
if alert_runbook_url:
|
||||
alert_runbook_template = u"[Reaction steps]({alert_runbook_url})"
|
||||
alert_runbook_template = u"[Reaction steps]({alert_runbook_url}):"
|
||||
content += alert_runbook_template.format(alert_runbook_url=alert_runbook_url)
|
||||
content += self.generate_conditions_and_violations()
|
||||
return content
|
||||
|
@ -131,14 +131,14 @@ class LibratoWebhookHandler(LibratoWebhookParser):
|
|||
condition: Dict[str, Any]) -> str:
|
||||
summary_function, threshold, condition_type, duration = self.parse_condition(condition)
|
||||
metric_name, recorded_at = self.parse_violation(violation)
|
||||
metric_condition_template = (u"\n>Metric `{metric_name}`, {summary_function} "
|
||||
metric_condition_template = (u"\n * Metric `{metric_name}`, {summary_function} "
|
||||
"was {condition_type} {threshold}")
|
||||
content = metric_condition_template.format(
|
||||
metric_name=metric_name, summary_function=summary_function, condition_type=condition_type,
|
||||
threshold=threshold)
|
||||
if duration:
|
||||
content += u" by {duration}s".format(duration=duration)
|
||||
content += u", recorded at {recorded_at} UTC".format(recorded_at=recorded_at)
|
||||
content += u", recorded at {recorded_at} UTC.".format(recorded_at=recorded_at)
|
||||
return content
|
||||
|
||||
@api_key_only_webhook_view('Librato')
|
||||
|
|
Loading…
Reference in New Issue