@@ -99,6 +99,50 @@ class DocumentMonitorRunnerIT : AlertingRestTestCase() {
99
99
assertTrue(" Incorrect search result" , matchingDocsToQuery.contains(" 5|$testIndex " ))
100
100
}
101
101
102
+ fun `test execute monitor yields results in alert action context` () {
103
+
104
+ val testTime = DateTimeFormatter .ISO_OFFSET_DATE_TIME .format(ZonedDateTime .now().truncatedTo(MILLIS ))
105
+ val testDoc = """ {
106
+ "message" : "This is an error from IAD region",
107
+ "test_strict_date_time" : "$testTime ",
108
+ "test_field" : "us-west-2"
109
+ }"""
110
+
111
+ val index = createTestIndex()
112
+
113
+ val docQuery = DocLevelQuery (query = " test_field:\" us-west-2\" " , name = " 3" )
114
+ val docLevelInput = DocLevelMonitorInput (" description" , listOf (index), listOf (docQuery))
115
+
116
+ val action = randomAction(template = randomTemplateScript(" {{ctx.results.0}}" ), destinationId = createDestination().id)
117
+ val monitor = randomDocumentLevelMonitor(
118
+ inputs = listOf (docLevelInput),
119
+ triggers = listOf (randomDocumentLevelTrigger(condition = ALWAYS_RUN , actions = listOf (action)))
120
+ )
121
+
122
+ indexDoc(index, " 1" , testDoc)
123
+
124
+ val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
125
+
126
+ val output = entityAsMap(response)
127
+ assertEquals(monitor.name, output[" monitor_name" ])
128
+
129
+ assertEquals(1 , output.objectMap(" trigger_results" ).values.size)
130
+
131
+ for (triggerResult in output.objectMap(" trigger_results" ).values) {
132
+ assertEquals(1 , triggerResult.objectMap(" action_results" ).values.size)
133
+ for (alertActionResult in triggerResult.objectMap(" action_results" ).values) {
134
+ for (actionResult in alertActionResult.values) {
135
+ @Suppress(" UNCHECKED_CAST" ) val actionOutput = (actionResult as Map <String , Map <String , String >>)[" output" ]
136
+ as Map <String , String >
137
+ assertTrue(actionOutput[" subject" ].toString().contains(docQuery.id))
138
+ assertTrue(actionOutput[" subject" ].toString().contains(docQuery.id))
139
+ }
140
+ }
141
+ }
142
+ val alerts = searchAlerts(monitor)
143
+ assertEquals(" Alert saved for test monitor" , 0 , alerts.size)
144
+ }
145
+
102
146
fun `test execute monitor generates alerts and findings` () {
103
147
val testIndex = createTestIndex()
104
148
val testTime = DateTimeFormatter .ISO_OFFSET_DATE_TIME .format(ZonedDateTime .now().truncatedTo(MILLIS ))
0 commit comments