Skip to content

Commit

Permalink
fix #1981
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Sep 18, 2024
1 parent 51b12fc commit 7ebe3c9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion otoroshi/app/events/alerts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import otoroshi.env.Env
import otoroshi.models.{QuotasAlmostExceededSettings, _}
import org.joda.time.DateTime
import play.api.Logger
import play.api.libs.json.{Format, JsArray, JsError, JsNull, JsResult, JsString, JsSuccess, JsValue, Json, Writes}
import play.api.libs.json.{Format, JsArray, JsError, JsNull, JsObject, JsResult, JsString, JsSuccess, JsValue, Json, Writes}
import play.api.libs.ws.WSAuthScheme
import play.api.mvc.RequestHeader
import otoroshi.ssl.Cert
Expand All @@ -29,6 +29,33 @@ trait AlertEvent extends AnalyticEvent {
override def `@type`: String = "AlertEvent"
}

object AlertEvent {
def generic(alert: String, `@service`: String = "Otoroshi", `@serviceId`: String = "")(additionalPayload: JsObject)(implicit env: Env): GenericAlert = {
GenericAlert(alert, env, `@service`, `@serviceId`)(additionalPayload)
}
}

case class GenericAlert(alert: String, env: Env, `@service`: String = "Otoroshi", `@serviceId`: String = "")(additionalPayload: JsObject) extends AlertEvent {

val `@id`: String = env.snowflakeGenerator.nextIdStr()
val `@timestamp`: DateTime = DateTime.now()
val fromOrigin: Option[String] = None
val fromUserAgent: Option[String] = None

override def toJson(implicit _env: Env): JsValue = {
Json.obj(
"@id" -> `@id`,
"@timestamp" -> play.api.libs.json.JodaWrites.JodaDateTimeNumberWrites.writes(`@timestamp`),
"@type" -> `@type`,
"@product" -> _env.eventsName,
"@serviceId" -> `@serviceId`,
"@service" -> `@service`,
"@env" -> env.env,
"alert" -> alert,
) ++ additionalPayload
}
}

case class ApiKeySecretWillRotate(
`@id`: String,
`@env`: String,
Expand Down

0 comments on commit 7ebe3c9

Please sign in to comment.