Heartbeat: response code in case of error

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/: 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: 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 ?

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.

- 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.

Hi,

I tried:

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

Error:

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:

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

Error:

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,

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.

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

  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:

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.

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:

- 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.

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

Yes, it is working.