Sending alert to Opsgenie

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:

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

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