Skip to content

Commit

Permalink
Add status code to DOWN messages as well
Browse files Browse the repository at this point in the history
  • Loading branch information
akobor committed Aug 20, 2020
1 parent 2eb1444 commit 7fce0af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/main/kotlin/com/kuvaszuptime/kuvasz/models/Event.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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" }
)
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ class SlackEventHandlerTest(
val notificationsSent = mutableListOf<SlackWebhookMessage>()

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)"
}
}

Expand Down Expand Up @@ -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)"
}
}

Expand Down

0 comments on commit 7fce0af

Please sign in to comment.