From 7fce0afd7d7259d40768e37d64e5961e0ccc9675 Mon Sep 17 00:00:00 2001 From: akobor Date: Thu, 20 Aug 2020 20:21:05 +0200 Subject: [PATCH] Add status code to DOWN messages as well --- src/main/kotlin/com/kuvaszuptime/kuvasz/models/Event.kt | 5 ++++- .../kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/models/Event.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/models/Event.kt index b83e4bd..99f6503 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/models/Event.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/models/Event.kt @@ -1,6 +1,8 @@ package com.kuvaszuptime.kuvasz.models import arrow.core.Option +import arrow.core.getOrElse +import arrow.core.toOption import com.kuvaszuptime.kuvasz.enums.UptimeStatus import com.kuvaszuptime.kuvasz.tables.pojos.MonitorPojo import com.kuvaszuptime.kuvasz.tables.pojos.UptimeEventPojo @@ -118,7 +120,8 @@ fun MonitorDownEvent.toPlainMessage(): String = fun MonitorDownEvent.toStructuredMessage() = StructuredDownMessage( - summary = "Your monitor \"${monitor.name}\" (${monitor.url}) is DOWN", + summary = "Your monitor \"${monitor.name}\" (${monitor.url}) is DOWN" + + status.toOption().map { " (" + it.code + ")" }.getOrElse { "" }, error = "Reason: ${error.message}", previousUpTime = getEndedEventDuration().toDurationString().map { "Was up for $it" } ) diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt index 7d1137d..8d7c97d 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt @@ -166,9 +166,9 @@ class SlackEventHandlerTest( val notificationsSent = mutableListOf() verify(exactly = 2) { webhookServiceSpy.sendMessage(capture(notificationsSent)) } - notificationsSent[0].text shouldContain "is DOWN" + notificationsSent[0].text shouldContain "is DOWN (500)" notificationsSent[1].text shouldContain "Latency: 1000ms" - notificationsSent[1].text shouldContain "is UP" + notificationsSent[1].text shouldContain "is UP (200)" } } @@ -197,8 +197,8 @@ class SlackEventHandlerTest( verify(exactly = 2) { webhookServiceSpy.sendMessage(capture(notificationsSent)) } notificationsSent[0].text shouldContain "Latency: 1000ms" - notificationsSent[0].text shouldContain "is UP" - notificationsSent[1].text shouldContain "is DOWN" + notificationsSent[0].text shouldContain "is UP (200)" + notificationsSent[1].text shouldContain "is DOWN (500)" } }