405 error when calling /_cluster/health?level=indices from a watcher

I'm trying to setup a watcher to display indices health using the endpoint mentioned but keep getting a 405 error.

This error goes away when I just use the following /_cluster/health dropping the params ?level=indices, I'm not sure what I'm doing wrong as the endpoint is a GET endpoint.

Incorrect HTTP method for uri [/_cluster/health%3Flevel=indices] and method [GET], allowed: [POST]

PUT _xpack/watcher/watch/cluster_healthcheck_not_green
{
  "trigger" : {
    "schedule" : { "interval" : "10s" }
  },
  "input" : {
    "http" : {
      "request" : {
       "scheme": "https",
       "host" : "....eu-west-1.aws.found.io",
       "port" : 9243,
       "path" : "/_cluster/health?level=indices",
       "auth": {
          "basic": {
            "username": "...",
            "password": "..."
          }
        }
      }
    }
  },
  "condition" : {
    "compare" : {
      "ctx.payload.status" : { "not_eq" : "green" }
    }
  },
  "actions": {
    "notify-slack": {
      "throttle_period" : "5m",
      "slack" : {
        "message" : {
          "to" : [ "#elasticsearch-alerts-test" ],
          "text" : "Cluster health should be \"green\""
        }
      }
    }
  }
}

It's not a great error message, but the problem is that you need to do GET /_cluster/health?level=indices and you are doing GET /_cluster/health%3Flevel=indices which are not the same thing at all. The ?level=indices bit isn't part of the path, it goes in the params field instead. See https://www.elastic.co/guide/en/elasticsearch/reference/current/input-http.html#_calling_elasticsearch_apis for more details.

Thank you, worked perfectly :+1:

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