Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 64d7265

Browse files
dbbaugheVinoo Vasudevan
authored andcommitted
Adds more alert properties to templateArgs for context variable
1 parent 2c6882d commit 64d7265

File tree

2 files changed

+19
-12
lines changed
  • alerting/src
    • main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model
    • test/kotlin/com/amazon/opendistroforelasticsearch/alerting/model

2 files changed

+19
-12
lines changed

alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Alert.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ data class Alert(
7171

7272
companion object {
7373

74+
const val ALERT_ID_FIELD = "id"
75+
const val ALERT_VERSION_FIELD = "version"
7476
const val MONITOR_ID_FIELD = "monitor_id"
7577
const val MONITOR_VERSION_FIELD = "monitor_version"
7678
const val MONITOR_NAME_FIELD = "monitor_name"
@@ -169,9 +171,14 @@ data class Alert(
169171
}
170172

171173
fun asTemplateArg(): Map<String, Any?> {
172-
return mapOf(STATE_FIELD to state.toString(),
174+
return mapOf(ACKNOWLEDGED_TIME_FIELD to acknowledgedTime?.toEpochMilli(),
175+
ALERT_ID_FIELD to id,
176+
ALERT_VERSION_FIELD to version,
177+
END_TIME_FIELD to endTime?.toEpochMilli(),
173178
ERROR_MESSAGE_FIELD to errorMessage,
174-
ACKNOWLEDGED_TIME_FIELD to acknowledgedTime?.toEpochMilli(),
175-
LAST_NOTIFICATION_TIME_FIELD to lastNotificationTime?.toEpochMilli())
179+
LAST_NOTIFICATION_TIME_FIELD to lastNotificationTime?.toEpochMilli(),
180+
SEVERITY_FIELD to severity,
181+
START_TIME_FIELD to startTime.toEpochMilli(),
182+
STATE_FIELD to state.toString())
176183
}
177184
}

alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/AlertTests.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class AlertTests : ESTestCase() {
2424

2525
val templateArgs = alert.asTemplateArg()
2626

27-
assertEquals("Template args state does not match", templateArgs["state"], alert.state.toString())
28-
assertEquals("Template args error message does not match", templateArgs["error_message"], alert.errorMessage)
29-
assertEquals(
30-
"Template args acknowledged time does not match",
31-
templateArgs["acknowledged_time"],
32-
alert.acknowledgedTime?.toEpochMilli())
33-
assertEquals("Template args last notification time does not match",
34-
templateArgs["last_notification_time"],
35-
alert.lastNotificationTime?.toEpochMilli())
27+
assertEquals("Template args id does not match", templateArgs[Alert.ALERT_ID_FIELD], alert.id)
28+
assertEquals("Template args version does not match", templateArgs[Alert.ALERT_VERSION_FIELD], alert.version)
29+
assertEquals("Template args state does not match", templateArgs[Alert.STATE_FIELD], alert.state.toString())
30+
assertEquals("Template args error message does not match", templateArgs[Alert.ERROR_MESSAGE_FIELD], alert.errorMessage)
31+
assertEquals("Template args acknowledged time does not match", templateArgs[Alert.ACKNOWLEDGED_TIME_FIELD], null)
32+
assertEquals("Template args end time does not", templateArgs[Alert.END_TIME_FIELD], alert.endTime?.toEpochMilli())
33+
assertEquals("Template args start time does not", templateArgs[Alert.START_TIME_FIELD], alert.startTime.toEpochMilli())
34+
assertEquals("Template args last notification time does not match", templateArgs[Alert.LAST_NOTIFICATION_TIME_FIELD], null)
35+
assertEquals("Template args severity does not match", templateArgs[Alert.SEVERITY_FIELD], alert.severity)
3636
}
3737

3838
fun `test alert acknowledged`() {

0 commit comments

Comments
 (0)