# Include name of downed monitor in XPack alert

**URL:** https://discuss.elastic.co/t/include-name-of-downed-monitor-in-xpack-alert/204573
**Category:** Beats
**Tags:** heartbeat
**Created:** [October 22, 2019, 2:10am UTC](https://discuss.elastic.co/t/include-name-of-downed-monitor-in-xpack-alert/204573 "2019-10-22T02:10:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jmadkins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmadkins/32/56300_2.png) [@jmadkins](https://discuss.elastic.co/u/jmadkins)
#### Post date: [October 22, 2019, 2:10am UTC](https://discuss.elastic.co/t/include-name-of-downed-monitor-in-xpack-alert/204573/1 "2019-10-22T02:10:48Z")

</div>

Following [this guide](https://docs.opsgenie.com/docs/es-watcher-integration), I have a work alert to OpsGenie when a monitor goes down. However, the alert the is generated is so unhelpful and requires logging into Kibana.

Is there a way to customize the title of the alert that is sent to OpsGenie so that I can include the name of the monitors that triggered the alert?

```
{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "heartbeat-*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "query": {
            "bool": {
              "must": [
                {
                  "term": {
                    "monitor.status": {
                      "value": "down"
                    }
                  }
                }
              ],
              "filter": [
                {
                  "range": {
                    "@timestamp": {
                      "from": "now-1m"
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gt": 0
      }
    }
  },
  "actions": {
    "opsgenie": {
      "webhook": {
        "scheme": "https",
        "host": "api.opsgenie.com",
        "port": 443,
        "method": "post",
        "path": "/v1/json/eswatcher",
        "params": {
          "apiKey": "value"
        },
        "headers": {
          "Content-Type": "application/html"
        },
        "body": "{{#toJson}}ctx{{/toJson}}"
      }
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![Andrew\_Cholakian1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_cholakian1/32/3612_2.png) [@Andrew\_Cholakian1](https://discuss.elastic.co/u/Andrew_Cholakian1)
#### Post date: [October 24, 2019, 8:37pm UTC](https://discuss.elastic.co/t/include-name-of-downed-monitor-in-xpack-alert/204573/2 "2019-10-24T20:37:59Z")

</div>

So, with watch `ctx.payload` is just a regular elasticsearch response. To get a monitor ID from the first matched doc you'd use:

`{{ctx.payload.hits.hits.0._source.monitor.id}}`

You might also want to read the [watcher docs](https://www.elastic.co/guide/en/kibana/current/watcher-ui.html#watcher-create-threshold-alert).

You probably also want to create a watch per monitor, since this will only report the first matched monitor. Alternatively you can use aggregations to make a single monitor that watches everything, but that's tricky. If you have a lot of monitors you may want to script that.

As a heads up we're working on a new alerting solution that should be much easier to use (and graphically based), but that won't be available in the near term.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 21, 2019, 8:38pm UTC](https://discuss.elastic.co/t/include-name-of-downed-monitor-in-xpack-alert/204573/3 "2019-11-21T20:38:07Z")

</div>

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