# Ping domain to verify if server is down

**URL:** <https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056>\
**Category:** General\
**Created:** [28 June 2024 17:04 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056 "2024-06-28T17:04:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 17:04 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/1 "2024-06-28T17:04:44Z")

</div>

With this address ...

```auto
https://webservices.ingv.it/fdsnws/event/1/query?starttime=2024-06-28T00%3A00%3A00&endtime=2024-06-28T23%3A59%3A59&minmag=1&maxmag=10&mindepth=-10&maxdepth=1000&minlat=35&maxlat=49&minlon=5&maxlon=20&minversion=100&orderby=time-asc&format=text&limit=10000

```

I have the list (text format) of the earthquakes in Italy.  
How can I do to test if this address is down? (or up of course)  
I send an http request every 60 min and a few days ago the server was down and node (red) was in loop (?)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 June 2024 17:12 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/2 "2024-06-28T17:12:34Z")

</div>

> How can I do to test if this address is down

The problem here is the definition of "down" - is/was the webserver unreachable (as in ping failed) or did the webserver respond with a error.

What does "loop" mean in this context ?

You could ping the server, if successful, perform http request.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 June 2024 17:28 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/3 "2024-06-28T17:28:45Z")

</div>

> [@Giamma](#):
>
> node was in loop (?)

I suspect that the node returned an error that your flow did not expect and that caused the problem.

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 17:54 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/4 "2024-06-28T17:54:57Z")

</div>

> [@bakman2](#):
>
> You could ping the server, if successful, perform http request.

Ok, how ?

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 17:58 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/5 "2024-06-28T17:58:18Z")

</div>

> [@Colin](#):
>
> I suspect that the node returned an error that your flow did not expect and that caused the problem.

I have a catch node for the handling errors but the node don't report error ...

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [28 June 2024 18:26 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/6 "2024-06-28T18:26:46Z")

</div>

> [@Giamma](#):
>
> Ok, how ?

1. Use a `ping` Node to ping the hostname, before the HTTP request  
[node-red-node-ping (node) - Node-RED](https://flows.nodered.org/node/node-red-node-ping)

2. Design your flow to handle web server specific problems (if ping is succesfull)

🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 19:00 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/7 "2024-06-28T19:00:35Z")

</div>

You've tried with the address in my first post?  
Because I can not do it ....

Return false, but it's not correct ....

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 June 2024 19:06 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/8 "2024-06-28T19:06:21Z")

</div>

> [@Giamma](#):
>
> I send an http request every 60 min and a few days ago the server was down and node (red) was in loop (?)

please explain this. Perhaps you could share your flow?

> [@Giamma](#):
>
> You've tried with the address in my first post?

That host name is pingable

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9d70f481495076670b5c96b67dc017c2e814daa.png)

So the suggestion is to install `node-red-node-ping` and ping `webservices.ms.ingv.it` to determine if the host is online. But TBH, its not necessary. Rather, i suspect you have a bug in your flows that doesnt correctly handle a bad response.

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 19:29 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/9 "2024-06-28T19:29:31Z")

</div>

You are right, the hostname is pingable ....  
I cannot share my flow because it's a part of a flow very complex .....  
After the http request node I have this function ....

![err](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d126cadf25f8530e6a236c840ce634819724b73a.png)

and in the flow I have a catch node that never reports an error ...

How can I set a specific handling error for http request node ?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 June 2024 19:33 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/10 "2024-06-28T19:33:22Z")

</div>

> [@Giamma](#):
>
> I have a catch node for the handling errors but the node don't report error ...

It is possible that the serv **er** was up but there was a problem with the ser **vice**. So maybe you got a response, just not a useful one.

So you probably just need to check for some sensible content before moving on with the flow.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 June 2024 19:33 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/11 "2024-06-28T19:33:53Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0db4017f61a0d315d9bea87261dfb9a000096afa.png)

Check `msg.statusCode` in a switch node. If if is `400` or greater then you have an error.

> [@Giamma](#):
>
> and in the flow I have a catch node that never reports an error

As a guess, you have the catch node doing a retry or something? I think you are making a loop. As a test, connect the catch node to a DEBUG ONLY (nothing else). Also, set the DEBUG to "show complete message"

* * *

PS: Please do not send pictures of code - i cannot copy paste and correct easily and pictures are not (easily) searchable!

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 19:39 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/12 "2024-06-28T19:39:21Z")

</div>

Yes, it was just like that ...  
The site was up but not the api service (test with the browser) ....

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 19:48 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/13 "2024-06-28T19:48:35Z")

</div>

For example this happens when one of my cam have bad wifi connection  
I have a msg.statusCode == "EHOSTUNREACH", string, not number ....  
but it's a different case maybe .....(?)

No, I don't have the catch node doing a retry ....

I think to have a loop because after a probelm with http request the cup work increases significantly (4% to 28%) and also the cpu temperature and I'm forced to restart node-red.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 June 2024 20:04 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/14 "2024-06-28T20:04:24Z")

</div>

Status code is ALWAYS a number.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8add32789f01b4aeeca798d632c08355e7718492.png)

your function is NOT matching "EHOSTblahblahblah" ever - so the `else` part of the function is executed (returning in `output[1]`)

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 20:12 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/15 "2024-06-28T20:12:19Z")

</div>

![coderror](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e55ec218ee2a543203c1c0bbd8ef367f323ec79.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 June 2024 20:19 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/16 "2024-06-28T20:19:28Z")

</div>

that is a different issue though. That is when the host is not on line. your issue was:

> [@Giamma](#):
>
> The site was up but not the api service

so you would have gotten a status number code. (at least i think so)

TBH, I forgot about the status code could be a string and its not great IMO (unreliable)

In short, swap the logic in your function to check that it `=== 200` or `=== 201`

```auto

if (msg.statusCode === 200 || msg.statusCode === 201) {
   // all good, send it out of output [1]
} else {
   // no, bad response! send it out of output [0]
}
```

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 20:22 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/17 "2024-06-28T20:22:05Z")

</div>

Ok, thank you very much ....

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 June 2024 20:36 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/18 "2024-06-28T20:36:23Z")

</div>

> [@Steve-Mcl](#):
>
> In short, swap the logic in your function to check that it `=== 200` or `=== 201`

It is, of course, possible to get a 200 and still have a bad output. Depending on the server and the app they use.

Best to also add some logic to also check for some expected fixed text in the return.

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [28 June 2024 20:40 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/19 "2024-06-28T20:40:43Z")

</div>

> [@Steve-Mcl](#):
>
> That is when the host is not line

Is possible when there is msg.statusCode == "EHOSTUNREACH"  
the http request node cause the problem to cpu work and temperature ?

Because this is what happens to me

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 June 2024 20:52 UTC](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056/20 "2024-06-28T20:52:49Z")

</div>

> [@Giamma](#):
>
> Is possible when there is msg.statusCode == "EHOSTUNREACH"  
> the http request node cause the problem to cpu work and temperature ?

msg.statusCode will never be that because it is a string.

It is more likely that something later in your flow is getting stuck because you are feeding it invalid data.

[Next page](https://discourse.nodered.org/t/ping-domain-to-verify-if-server-is-down/89056.md?page=2)
