@@ -22,6 +22,7 @@ data class Alert(
2222 val version : Long = NO_VERSION ,
2323 val schemaVersion : Int = NO_SCHEMA_VERSION ,
2424 val monitorId : String ,
25+ val workflowId : String ,
2526 val monitorName : String ,
2627 val monitorVersion : Long ,
2728 val monitorUser : User ? ,
@@ -48,6 +49,7 @@ data class Alert(
4849 }
4950 }
5051
52+ // constructor for chained alerts.
5153 constructor (
5254 startTime: Instant ,
5355 lastNotificationTime: Instant ? ,
@@ -63,7 +65,7 @@ data class Alert(
6365 lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = emptyList(),
6466 severity = chainedAlertTrigger.severity, actionExecutionResults = emptyList(), schemaVersion = schemaVersion,
6567 aggregationResultBucket = null , findingIds = emptyList(), relatedDocIds = emptyList(),
66- executionId = executionId
68+ executionId = executionId, workflowId = workflow.id
6769 )
6870
6971 constructor (
@@ -76,14 +78,15 @@ data class Alert(
7678 errorHistory: List <AlertError > = mutableListOf (),
7779 actionExecutionResults: List <ActionExecutionResult > = mutableListOf (),
7880 schemaVersion: Int = NO_SCHEMA_VERSION ,
79- executionId: String? = null
81+ executionId: String? = null ,
82+ workflow: Workflow ? = null ,
8083 ) : this (
8184 monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
8285 triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
8386 lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
8487 severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion,
8588 aggregationResultBucket = null , findingIds = emptyList(), relatedDocIds = emptyList(),
86- executionId = executionId
89+ executionId = executionId, workflowId = workflow?.id ? : " "
8790 )
8891
8992 constructor (
@@ -97,14 +100,15 @@ data class Alert(
97100 actionExecutionResults: List <ActionExecutionResult > = mutableListOf (),
98101 schemaVersion: Int = NO_SCHEMA_VERSION ,
99102 findingIds: List <String > = emptyList(),
100- executionId: String? = null
103+ executionId: String? = null ,
104+ workflow: Workflow ? = null ,
101105 ) : this (
102106 monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
103107 triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
104108 lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
105109 severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion,
106110 aggregationResultBucket = null , findingIds = findingIds, relatedDocIds = emptyList(),
107- executionId = executionId
111+ executionId = executionId, workflowId = workflow?.id ? : " "
108112 )
109113
110114 constructor (
@@ -119,14 +123,15 @@ data class Alert(
119123 schemaVersion: Int = NO_SCHEMA_VERSION ,
120124 aggregationResultBucket: AggregationResultBucket ,
121125 findingIds: List <String > = emptyList(),
122- executionId: String? = null
126+ executionId: String? = null ,
127+ workflow: Workflow ? = null ,
123128 ) : this (
124129 monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
125130 triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
126131 lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
127132 severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion,
128133 aggregationResultBucket = aggregationResultBucket, findingIds = findingIds, relatedDocIds = emptyList(),
129- executionId = executionId
134+ executionId = executionId, workflowId = workflow?.id ? : " "
130135 )
131136
132137 constructor (
@@ -142,14 +147,15 @@ data class Alert(
142147 errorHistory: List <AlertError > = mutableListOf (),
143148 actionExecutionResults: List <ActionExecutionResult > = mutableListOf (),
144149 schemaVersion: Int = NO_SCHEMA_VERSION ,
145- executionId: String? = null
150+ executionId: String? = null ,
151+ workflow: Workflow ? = null ,
146152 ) : this (
147153 id = id, monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
148154 triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
149155 lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
150156 severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion,
151157 aggregationResultBucket = null , findingIds = findingIds, relatedDocIds = relatedDocIds,
152- executionId = executionId
158+ executionId = executionId, workflowId = workflow?.id ? : " "
153159 )
154160
155161 constructor (
@@ -161,13 +167,15 @@ data class Alert(
161167 state: State = State .ERROR ,
162168 errorMessage: String ,
163169 errorHistory: List <AlertError > = mutableListOf (),
164- schemaVersion: Int = NO_SCHEMA_VERSION
170+ schemaVersion: Int = NO_SCHEMA_VERSION ,
171+ workflow: Workflow ? = null ,
165172 ) : this (
166173 id = id, monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
167174 triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
168175 lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
169176 severity = trigger.severity, actionExecutionResults = listOf (), schemaVersion = schemaVersion,
170- aggregationResultBucket = null , findingIds = listOf (), relatedDocIds = listOf ()
177+ aggregationResultBucket = null , findingIds = listOf (), relatedDocIds = listOf (),
178+ workflowId = workflow?.id ? : " "
171179 )
172180
173181 enum class State {
@@ -185,6 +193,7 @@ data class Alert(
185193 version = sin.readLong(),
186194 schemaVersion = sin.readInt(),
187195 monitorId = sin.readString(),
196+ workflowId = sin.readString(),
188197 monitorName = sin.readString(),
189198 monitorVersion = sin.readLong(),
190199 monitorUser = if (sin.readBoolean()) {
@@ -215,6 +224,7 @@ data class Alert(
215224 out .writeLong(version)
216225 out .writeInt(schemaVersion)
217226 out .writeString(monitorId)
227+ out .writeString(workflowId)
218228 out .writeString(monitorName)
219229 out .writeLong(monitorVersion)
220230 out .writeBoolean(monitorUser != null )
@@ -247,6 +257,7 @@ data class Alert(
247257 const val SCHEMA_VERSION_FIELD = " schema_version"
248258 const val ALERT_VERSION_FIELD = " version"
249259 const val MONITOR_ID_FIELD = " monitor_id"
260+ const val WORKFLOW_ID_FIELD = " workflow_id"
250261 const val MONITOR_VERSION_FIELD = " monitor_version"
251262 const val MONITOR_NAME_FIELD = " monitor_name"
252263 const val MONITOR_USER_FIELD = " monitor_user"
@@ -274,6 +285,7 @@ data class Alert(
274285 fun parse (xcp : XContentParser , id : String = NO_ID , version : Long = NO_VERSION ): Alert {
275286
276287 lateinit var monitorId: String
288+ var workflowId = " "
277289 var schemaVersion = NO_SCHEMA_VERSION
278290 lateinit var monitorName: String
279291 var monitorVersion: Long = Versions .NOT_FOUND
@@ -300,6 +312,7 @@ data class Alert(
300312
301313 when (fieldName) {
302314 MONITOR_ID_FIELD -> monitorId = xcp.text()
315+ WORKFLOW_ID_FIELD -> workflowId = xcp.text()
303316 SCHEMA_VERSION_FIELD -> schemaVersion = xcp.intValue()
304317 MONITOR_NAME_FIELD -> monitorName = xcp.text()
305318 MONITOR_VERSION_FIELD -> monitorVersion = xcp.longValue()
@@ -360,7 +373,7 @@ data class Alert(
360373 lastNotificationTime = lastNotificationTime, acknowledgedTime = acknowledgedTime,
361374 errorMessage = errorMessage, errorHistory = errorHistory, severity = severity,
362375 actionExecutionResults = actionExecutionResults, aggregationResultBucket = aggAlertBucket, findingIds = findingIds,
363- relatedDocIds = relatedDocIds, executionId = executionId
376+ relatedDocIds = relatedDocIds, executionId = executionId, workflowId = workflowId
364377 )
365378 }
366379
@@ -383,6 +396,7 @@ data class Alert(
383396 .field(ALERT_ID_FIELD , id)
384397 .field(ALERT_VERSION_FIELD , version)
385398 .field(MONITOR_ID_FIELD , monitorId)
399+ .field(WORKFLOW_ID_FIELD , workflowId)
386400 .field(SCHEMA_VERSION_FIELD , schemaVersion)
387401 .field(MONITOR_VERSION_FIELD , monitorVersion)
388402 .field(MONITOR_NAME_FIELD , monitorName)
0 commit comments