# Sending alert to Opsgenie

**URL:** <https://discuss.elastic.co/t/sending-alert-to-opsgenie/249955>\
**Category:** Elasticsearch\
**Created:** [September 25, 2020, 10:19am UTC](https://discuss.elastic.co/t/sending-alert-to-opsgenie/249955 "2020-09-25T10:19:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mokashi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mokashi/32/76020_2.png) [@mokashi](https://discuss.elastic.co/u/mokashi)\
**Post date:** [September 25, 2020, 10:19am UTC](https://discuss.elastic.co/t/sending-alert-to-opsgenie/249955/1 "2020-09-25T10:19:40Z")

</div>

Hi,

I created a a watcher in Elasticsearch to send alert to Opsgenie, below is the Watcher configuration toward Opsgenie:

> ```
> {
> "trigger": {
> "schedule": {
> "cron": "0 0 7-15 * * ?"
> }
> },
> "input": {
> "search": {
> "request": {
> "search_type": "query_then_fetch",
> "indices": [
> "apps*"
> ],
> "rest_total_hits_as_int": true,
> "body": {
> "size": 0,
> "query": {
> "bool": {
> "must": [
> {
> "range": {
> "@timestamp": {
> "gte": "now-10m/m",
> "lte": "now"
> }
> }
> }
> ],
> "filter": [
> {
> "exists": {
> "field": "rtr.status"
> }
> }
> ],
> "should": [],
> "must_not": [
> {
> "match_phrase": {
> "@cf.app": {
> "query": "managementui"
> }
> }
> },
> {
> "match_phrase": {
> "rtr.path": {
> "query": "/fmd/manual/singlepackmanualentry"
> }
> }
> }
> ]
> }
> },
> "aggs": {
> "Percentile200": {
> "percentile_ranks": {
> "field": "rtr.status",
> "values": [
> 200,
> 400
> ]
> }
> }
> }
> }
> }
> }
> },
> "condition": {
> "script": {
> "source": "ctx.payload.aggregations.Percentile200.values['200.0'] > 1",
> "lang": "painless"
> }
> },
> "actions": {
> "opsgenie": {
> "transform": {
> "script": {
> "source": "\n double a=ctx.payload.aggregations.Percentile200.values['200.0']; \n DecimalFormat df = new DecimalFormat(\"#.#\"); \n String success_rate = df.format(a);\n return ['success_rate':success_rate];\n ",
> "lang": "painless"
> }
> },
> "webhook": {
> "scheme": "https",
> "host": "api.eu.opsgenie.com",
> "port": 443,
> "method": "post",
> "path": "/v1/json/eswatcher",
> "params": {
> "apiKey": "xxxxxxx"
> },
> "headers": {
> "Content-Type": "application/json"
> },
> "body": "{{#toJson}}ctx{{/toJson}}"
> }
> }
> }
> }
> 
> ```

it sends alert successfully, but how can I send severity (priority P1, P2 ,...) and payload or any other message with alert to Opsgenie?

below you may find the data which I receive in Opsgenie alert page:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/f/ff4f91a962e011fdda5b383b3e23c7554d77f5c7.png)

I checked the docs and I need to use ctx variable, but I don't know how?

---

<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:** [October 23, 2020, 10:19am UTC](https://discuss.elastic.co/t/sending-alert-to-opsgenie/249955/2 "2020-10-23T10:19:49Z")

</div>

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