# Per Document Monitoring, get the Monitoring ID & Alert ID sent with message

**URL:** https://forum.opensearch.org/t/per-document-monitoring-get-the-monitoring-id-alert-id-sent-with-message/21426
**Category:** Alerting
**Created:** [September 12, 2024, 12:53pm UTC](https://forum.opensearch.org/t/per-document-monitoring-get-the-monitoring-id-alert-id-sent-with-message/21426 "2024-09-12T12:53:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![HarryPottar](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@HarryPottar](https://forum.opensearch.org/u/HarryPottar)
#### Post date: [September 12, 2024, 12:53pm UTC](https://forum.opensearch.org/t/per-document-monitoring-get-the-monitoring-id-alert-id-sent-with-message/21426/1 "2024-09-12T12:53:07Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
v.2.16.0

**Describe the issue** :  
I want to thank everyone for helping me with a newbie.

I have most things working as expected. My last challenge is getting the Monitoring ID and the Alert ID sent with the alert message so I can acknowledge them.

I’m getting the correct alerts based on my search and processing them on our backend server.

However, the alerts need to be acknowledged; I have a call to the API using the monitor name to get the monitor id and another call to search for active alerts. Finally, a third call sends the acknowledgment to the API.

Ideally, I would like to get them both dynamically in the alert message so I can acknowledge as part of my process.

I have hard-coded the monitor ID for now, as that should not change.

Looking at this document [Triggers - OpenSearch Documentation](https://opensearch.org/docs/latest/observing-your-data/alerting/triggers/)

I see that there is a ctx.alert.id, but that is only for query-level monitors.

There is ctx.alerts for document-level monitors, that shows ctx.alerts.0.finding\_ids and ctx.alerts.0.related\_doc\_ids. I don’t see an ctx.alerts.0.id

My message so far

```auto
{
	"alerts": {
		"triggerId": "{{ctx.trigger.id}}",
   		"triggerName": "{{ctx.trigger. name}}", 
   		"lastUpdate": "{{ctx.last_update_time}}", 
   		"periodStart": "{{ctx.periodStart}}", 
   		"periodEnd": "{{ctx.periodEnd}}", 
        "monitorID":"nncKxJxxxxxxxPomred",
        "targetMountPoint": "/dev",
        "documents": [
                {{#ctx.alerts}}
		{{#sample_documents}}
		{
			"index": "{{_index}}",
			"documentId": "{{_id}}",
			"timestamp": "{{_source.@timestamp}}",
			"operation": {
				"action": "{{_source.action}}",
				"path": "{{_source.path}}",
				"fId": "{{_source..fId}}"
			},
			"device": {
				"host": "{{_source.host}}"
			},
			"user": {
				"email": "{{_source.email}}"
			},
                       "target": {
				"destination": "{{_source.target.destination}}",
				"process": "{{_source.target.process}}",
				"lastupdate": "{{_source.target.lastupdate}}"
			},
		}{{^-last}}, {{/-last}}
		{{/sample_documents}}
		{{/ctx.alerts}}
	]}
}

```

Thanks  
Harry

**Configuration** :

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

### Author: ![ssablan](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@ssablan](https://forum.opensearch.org/u/ssablan)
#### Post date: [October 8, 2024, 7:16pm UTC](https://forum.opensearch.org/t/per-document-monitoring-get-the-monitoring-id-alert-id-sent-with-message/21426/2 "2024-10-08T19:16:52Z")

</div>

Are you using a query, bucket or document monitor?

---

<div class="post-metadata">

### Author: ![HarryPottar](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@HarryPottar](https://forum.opensearch.org/u/HarryPottar)
#### Post date: [October 8, 2024, 8:20pm UTC](https://forum.opensearch.org/t/per-document-monitoring-get-the-monitoring-id-alert-id-sent-with-message/21426/3 "2024-10-08T20:20:50Z")

</div>

Thank you for your reply. I used per-document monitoring, but due to this issue and some others, I moved over to per-query monitoring, which solved my problems.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)
#### Post date: [December 7, 2024, 8:21pm UTC](https://forum.opensearch.org/t/per-document-monitoring-get-the-monitoring-id-alert-id-sent-with-message/21426/4 "2024-12-07T20:21:21Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
