# Using Watcher to check if Web service API is up

**URL:** https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549
**Category:** Elasticsearch
**Created:** [July 14, 2016, 5:43pm UTC](https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549 "2016-07-14T17:43:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vinayakravi](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@vinayakravi](https://discuss.elastic.co/u/vinayakravi)
#### Post date: [July 14, 2016, 5:43pm UTC](https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549/1 "2016-07-14T17:43:37Z")

</div>

Hi,

My application has a ping url that returns a HTTP status of 200 if the application is working correctly. I'd like to add a watcher action using`http input` that monitors this url and alerts me via email if anything other than 200 is returned. Is this possible with `http input`?

I tried to check if the `ctx.payload` is empty when the application is down but it looks like when the http url is unavailable, any condition defined on the watch is not executed? I set a repsonse and read timeout value of 5s. Also is there a way to look at the HTTP response code through the Watcher execution context? I wasn't able to find a way listed in the documentation.

I'm using X-Pack 5.0.0 alpha4 release  
Thanks,  
Vinayak

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [July 14, 2016, 9:50pm UTC](https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549/2 "2016-07-14T21:50:00Z")

</div>

Can you provide the watch that you currently have?

---

<div class="post-metadata">

### Author: ![vinayakravi](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@vinayakravi](https://discuss.elastic.co/u/vinayakravi)
#### Post date: [July 19, 2016, 2:00pm UTC](https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549/3 "2016-07-19T14:00:05Z")

</div>

Hi Mark,

Sorry for the late reply. I tried a couple of different watch conditions with different painless scripts including the one below. Even if I just had a painless script of "return true", the email action wasn't executed when the server I was trying to ping was shut down. The "return true" worked when the server I was pinging was online:

```
PUT _xpack/watcher/watch/watch_system_availibility
{
  "trigger": {
    "schedule": {
      "interval": "10s"
    }
  },
  "input": {
    "http" : {
    "request" : {
      "host" : "x.x.x.x",
      "port" : 8080,
      "path" : "/<contextpath>/ping"
    }
  }
  },
  "condition": {
    "script": {
          "lang": "painless",
          "inline": " if(ctx.payload===null) return true; else return false;"
        }
  },
  "actions": {
    "send_email": {
      "email": {
        "from": "'xxx <xx@example.com>'",
        "to": "'abcd<vxxx.xxxxx@xxxxxxxxxxxxx.com>'",
        "subject": "<subject>",
        "body": "Server is not responding and appears to be stopped"
        
      }
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [July 21, 2016, 12:15pm UTC](https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549/4 "2016-07-21T12:15:31Z")

</div>

Hey,

indeed you cant check for the HTTP response code right now, but I think that is a good feature to add. We could just add it to the payload as well, as we did with the headers in 5.0.

Do you have any header that only occurs if the request is valid, which you could use as a workaround?

--Alex

---

<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: [July 6, 2017, 1:40pm UTC](https://discuss.elastic.co/t/using-watcher-to-check-if-web-service-api-is-up/55549/5 "2017-07-06T13:40:42Z")

</div>


