in alerting/src/main/kotlin/org/opensearch/alerting/model/destination/Destination.kt [242:304]
fun publish(
compiledSubject: String?,
compiledMessage: String,
destinationCtx: DestinationContext,
denyHostRanges: List<String>
): String {
val destinationMessage: BaseMessage
val responseContent: String
val responseStatusCode: Int
when (type) {
DestinationType.CHIME -> {
val messageContent = chime?.constructMessageContent(compiledSubject, compiledMessage)
destinationMessage = ChimeMessage.Builder(name)
.withUrl(chime?.url)
.withMessage(messageContent)
.build()
}
DestinationType.SLACK -> {
val messageContent = slack?.constructMessageContent(compiledSubject, compiledMessage)
destinationMessage = SlackMessage.Builder(name)
.withUrl(slack?.url)
.withMessage(messageContent)
.build()
}
DestinationType.CUSTOM_WEBHOOK -> {
destinationMessage = CustomWebhookMessage.Builder(name)
.withUrl(customWebhook?.url)
.withScheme(customWebhook?.scheme)
.withHost(customWebhook?.host)
.withPort(customWebhook?.port)
.withPath(customWebhook?.path)
.withMethod(customWebhook?.method)
.withQueryParams(customWebhook?.queryParams)
.withHeaderParams(customWebhook?.headerParams)
.withMessage(compiledMessage).build()
}
DestinationType.EMAIL -> {
val emailAccount = destinationCtx.emailAccount
destinationMessage = EmailMessage.Builder(name)
.withHost(emailAccount?.host)
.withPort(emailAccount?.port)
.withMethod(emailAccount?.method?.value)
.withUserName(emailAccount?.username)
.withPassword(emailAccount?.password)
.withFrom(emailAccount?.email)
.withRecipients(destinationCtx.recipients)
.withSubject(compiledSubject)
.withMessage(compiledMessage).build()
}
DestinationType.TEST_ACTION -> {
return "test action"
}
}
validateDestinationUri(destinationMessage, denyHostRanges)
val response = Notification.publish(destinationMessage) as org.opensearch.alerting.destination.response.DestinationResponse
responseContent = response.responseContent
responseStatusCode = response.statusCode
logger.info("Message published for action name: $name, messageid: $responseContent, statuscode: $responseStatusCode")
return responseContent
}