Difference between warning and critical messages while checking the services

We need to know more clear explanation for warning can critical status while checking the services.

checks = consul.Consul().agent.checks(), As per our understanding it will check by requesting api /agent/check

documentation link here
Check - Agent - HTTP API | Consul | HashiCorp Developer. Our main query is when warning comes for a service and when critical comes for a services

It depends on the type of check being used.

For script checks, healthy, warning, or critical states are determined by the program’s exit code.

Script check exit codes

The following exit codes returned by the script check determine the health check status:

  • Exit code 0 - Check is passing
  • Exit code 1 - Check is warning
  • Any other code - Check is failing

The author of the script check determines what exit code they want to return for specific health check scenarios.

For HTTP checks, the following response codes correspond to different health check states.

HTTP check response codes

Responses larger than 4KB are truncated. The HTTP response determines the status of the service:

  • A 200-299 response code is healthy.
  • A 429 response code indicating too many requests is a warning.
  • All other response codes indicate a failure.

Refer to https://developer.hashicorp.com/consul/docs/services/usage/checks#tcp-checks for more information on the supported health checks and the conditions when they will return a specific warning state.

Thank you blake for your reply. Our check is configured to check the ping for a particular ip

like given below

  • check:
    interval: 5s
    - /bin/bash
    - ‘-c’
    - ping -6 -c 3 $ip_address >> /dev/null , we would like to know when we can critical status .

Under normal circumstances, I don’t think that ping will return the right exit code to allow the service to be marked as critical.

If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. This makes it possible to use the exit code to see if a host is alive or not.

source: https://linux.die.net/man/8/ping

ping would need to exit with code 2 in order to be marked critical by Consul.