Ping domain to verify if server is down

With this address ...

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 (?)

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.

1 Like

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

Ok, how ?

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

  1. Use a ping Node to ping the hostname, before the HTTP request
    node-red-node-ping (node) - Node-RED

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

:man_shrugging:

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

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

please explain this. Perhaps you could share your flow?

That host name is pingable

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.

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

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 ?

It is possible that the server was up but there was a problem with the service. 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.

Check msg.statusCode in a switch node. If if is 400 or greater then you have 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!

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

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.

Status code is ALWAYS a number.

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

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

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


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]
}

Ok, thank you very much ....

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.

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

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.