in app/com/gu/contentapi/sanity/support/TestFailureHandlingSupport.scala [56:93]
protected def sendPagerDutyAlert(testName: String, exception: Throwable, tags: Set[String], incidentKey: String) = {
try {
println("Reporting")
val isLowPriorityTest = tags.contains("LowPriorityTest")
val isCODETest = tags.contains("CODETest")
val serviceKey = if (isLowPriorityTest) Config.pagerDutyServiceKeyLowPriority else Config.pagerDutyServiceKey
val environmentInfo = if (isCODETest) "on environment CODE" else ""
val description = testName + " failed" + environmentInfo + ", the error reported was: " + exception.getMessage.take(250) + "..."
val data = Json.obj(
"service_key" -> serviceKey,
"event_type" -> "trigger",
"description" -> description,
"details" -> Json.arr(
Json.obj(
"name" -> testName,
"description" -> exception.getMessage
)
),
"client" -> "Content API Sanity Tests",
"client_url" -> "https://github.com/guardian/content-api-sanity-tests",
"incident_key" -> incidentKey
)
val httpRequest = request("https://events.pagerduty.com/generic/2010-04-15/create_event.json").post(data)
whenReady(httpRequest) { result =>
val pagerDutyResponse: JsValue = Json.parse(result.body)
val responseStatus = (pagerDutyResponse \ "status").asOpt[String]
val responseIncidentKey = (pagerDutyResponse \ "incident_key").asOpt[String]
responseStatus.value should be("success")
responseIncidentKey.value should be(incidentKey)
}
} catch {
case e: Exception => Console.err.println(Console.RED + "PagerDuty reporting failed with exception: " + e.getMessage + Console.RESET)
}
}