# Heartbeat: response code in case of error

**URL:** https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493
**Category:** Beats
**Tags:** heartbeat
**Created:** [May 11, 2022, 5:10pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493 "2022-05-11T17:10:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![aviral\_srivastava](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviral_srivastava/32/98018_2.png) [@aviral\_srivastava](https://discuss.elastic.co/u/aviral_srivastava)
#### Post date: [May 11, 2022, 5:10pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/1 "2022-05-11T17:10:35Z")

</div>

Hi,

I am using heartbeat 6.4.0. I can see that in case of successful connection, unauthorized access, not found it returns http.response.status\_code as 200, 401, 404 respectively.

But, in case of errors like below there is response code returned

Get [http://xx.xx.xxx.xxx:5000/:](http://xx.xx.xxx.xxx:5000/:) dial tcp xx.xx.xxx.xxx:5000: connectex: No connection could be made because the target machine actively refused it.  
or  
Get [http://myurl:90](http://myurl:90): dial tcp xx.xx.xxx.xx:90: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I have written a service that check the status code to see if the url is up or not. I have not taken into consideration the field monitor.status, because it returns `down` in case of 401 response code.

How to check the status of a url if there is no status code returned? Is there a way to put a condition that can handle the situations where there are no response code returned ?

---

<div class="post-metadata">

### Author: ![abdulz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdulz/32/97601_2.png) [@abdulz](https://discuss.elastic.co/u/abdulz)
#### Post date: [May 12, 2022, 12:48pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/2 "2022-05-12T12:48:25Z")

</div>

Hi @aviral_srivastava,

Assuming you only want the monitor to report `Down` only in cases of network failures when there's no status code returned (i.e. response headers never reach the request initiator) , you can put multiple acceptable status codes e.g.

```auto
- type: http
  id: <id>
  name: <name>
  schedule: '@every 1m'
  hosts: ["<host>"]
  timeout: 16s
  check.response.status: [200, 401, 404, 500]

```

The above monitor will report `Up` even if host returns **401** , **404** , **500**. Whereas in case of network failure, the request will timeout and monitor will show `Down`. You can configure the timeout using the `timeout` property. Hope that helps.

---

<div class="post-metadata">

### Author: ![aviral\_srivastava](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviral_srivastava/32/98018_2.png) [@aviral\_srivastava](https://discuss.elastic.co/u/aviral_srivastava)
#### Post date: [May 12, 2022, 3:34pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/3 "2022-05-12T15:34:45Z")

</div>

Hi,

I tried:

```auto
check.response.status: [200, 302, 401]

```

Error:

```auto
failed to load monitor tasks: can not convert 'object' into 'uint' accessing 'check.response.status' (source:'C:\Program Files\heartbeat-6.4.0-windows-x86_64\heartbeat.yml') when initializing monitor http(0)

```

I also tried:

```auto
check.response:
  status: [200, 302, 401]

```

Error:

```auto
failed to load monitor tasks: can not convert 'object' into 'uint' accessing 'check.response.status' (source:'C:\Program Files\heartbeat-6.4.0-windows-x86_64\heartbeat.yml') when initializing monitor http(0)

```

Also,

```auto
check.response:
  status: 200
  status: 302
  status: 401

```

In this case, heartbeat ignores codes 200 and 302. And only checks for 401. if the code returned is 200, it reports monitor.status as down.

---

<div class="post-metadata">

### Author: ![abdulz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdulz/32/97601_2.png) [@abdulz](https://discuss.elastic.co/u/abdulz)
#### Post date: [May 12, 2022, 3:59pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/4 "2022-05-12T15:59:38Z")

</div>

That error tells the array syntax for `status` is not supported in `v6.4.0`. The support starts from `v7.7`.

If upgrading is not option, you can try something like

```auto
  check.response:
    status: 0
    body:
      - hello
      - world

```

To provide all the acceptable strings or regex patterns under `check.reponse.body` that shall put the monitor in an `Up` state. Caveat would be that **404** cannot be covered as up state in this case. _Definitely it's not a scalable solution so upgrade is recommended._

Quoting [documentation](https://www.elastic.co/guide/en/beats/heartbeat/6.4/configuration-heartbeat-options.html):

> **`status`**  
> The expected status code. If this setting is not configured or it’s set to 0, any status code other than 404 is accepted.  
> ...  
> **`body`**  
> A list of regular expressions to match the the body output. Only a single expression needs to match.

---

<div class="post-metadata">

### Author: ![aviral\_srivastava](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviral_srivastava/32/98018_2.png) [@aviral\_srivastava](https://discuss.elastic.co/u/aviral_srivastava)
#### Post date: [May 15, 2022, 12:56pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/5 "2022-05-15T12:56:48Z")

</div>

Thanks for the response.

I have upgraded my heartbeat to 7.7.0 from 6.4.0  
In 7.7.0, I am able to handle multiple response codes. Below is an example of one url:

```auto
- type: http
  urls:
    - https://myurl.company.com
  schedule: '@every 5m'
  name: DevOps-Prod
  check.response.status: [200, 302, 401]

```

I have checked with multiple urls using the same configuration as above. When the http.response.status\_code is any one of 200 or 302 or 401. I am getting monitor.status as up otherwise monitor.status is down.

---

<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: [May 18, 2022, 8:59pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/6 "2022-05-18T20:59:17Z")

</div>

@aviral_srivastava it sounds like everything is working then, is that correct?

---

<div class="post-metadata">

### Author: ![aviral\_srivastava](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviral_srivastava/32/98018_2.png) [@aviral\_srivastava](https://discuss.elastic.co/u/aviral_srivastava)
#### Post date: [May 20, 2022, 1:14pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/7 "2022-05-20T13:14:08Z")

</div>

Yes, it is working.

---

<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: [June 17, 2022, 3:14pm UTC](https://discuss.elastic.co/t/heartbeat-response-code-in-case-of-error/304493/8 "2022-06-17T15:14:45Z")

</div>

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