Node-Red is my new universal tool for all kinds of automation problems and tasks. So why not use it to implement monitoring for the web server and your own website, which informs you via Telegram and email in case of an error, i.e. website down or without content?
Apart from the Telegram nodes, which you have to install additionally, my flow relies on the standard nodes of the basic installation of Node-Red.
⚠ [affiliate] Keine Produkte mit Cache für home-assistant.
Bitte affiliate-sync --lang en ausführen.

Regularly knocking on the server’s door
It starts with an Injection Node, which triggers the check at a 5-minute interval. A completely sufficient period for my requirements.

This triggers an HTTP Request Node, in which the desired URL is entered and called up via a GET command. A UTF-8 string is then returned.

From here, the flow splits into two branches. The first branch checks the Response Code of the page. If the website returns Response Code 200, everything is okay: page and server are online.

The Switch Node triggers when the response code is not equal to 200.

A response doesn’t yet mean content
However, this doesn’t yet guarantee that there is actually something to see on the page. If you have, for example, an Nginx server as a reverse proxy in use, it can return 200 as a response, but the page can still be empty because the server behind the proxy isn’t delivering any data. Therefore, I check in a second branch whether a certain content is contained on the page.

An HTML Node searches for an element on the website. I use the word Markus for this, which is found in the copyright footer of fricklr.com. This tells me that the page was completely rendered. The word is contained in the HTML element div.copyright-bar, which you can simply find with the “Inspect” function of Chrome.

If the text is found in the HTML element, its entire text content is returned as Payload. The subsequent Switch Node checks with a regular expression, which can be extremely simple here, whether Markus is also contained in the text.

Since the notification should only trigger if the searched word is NOT contained, you add a second output to the node with otherwise, which then triggers the subsequent nodes.
Notifying, but not annoying
Now you could attach a corresponding action, notification, etc. to each branch. However, in case of an error, this action or message would be sent every 5 minutes, since the Injection Node at the beginning executes the flow every 5 minutes. Therefore, I have inserted a Delay Node in each branch.

With the Rate Limit action, you can set how often a message should be forwarded. In case of an error, I want to get another reminder every 30 minutes. All messages in between are simply discarded:

The notification nodes are the same in both branches, apart from the message.
Alarm via Telegram and email

A notification is sent via Telegram. For this, a Telegram Bot must be set up and the ID of the recipient(s) must be specified. How to do this is described in the description of the Telegram Node .

Additionally, I send an email via the SMTP server of Gmail. For this, the subject and the content of the email must first be defined with the Function Node:

|
|
The email content is in the Payload, the subject in the Topic. This Function Node is also the same in both branches, only the message differs of course.
The variable msg.responseURL is practical if you want to monitor several URLs at once, because the monitored URL is automatically included in the message.
Both Function Nodes now end at the Email Node. The full Gmail address is entered as the Userid.

Sending is done via the SMTP server of Gmail. For this, “Access for less secure apps” must be activated in the settings of Gmail under Security, otherwise you cannot use SMTP for external applications.

This completes the flow for website and web server monitoring. The easiest way to test the flow is to set the status code in the corresponding Switch Node to a different value or to enter a text in the text branch that doesn’t exist in the defined element. You should now receive an email and Telegram message with the alarm.
Conclusion
At this point, you can now also trigger various other functions. For example, you could also pass the alarm via MQTT MQTTLightweight publish/subscribe messaging protocol. Used in smart homes to exchange sensor data and control commands between devices to an ESPHome ESPHomeFramework for configuring ESP32/ESP8266 microcontrollers that automatically integrate into Home Assistant. Ideal for DIY sensors and actuators or ESPeasy, which then makes an LED blink or a speaker beep. Passing it on to the smart home is also practical.
In any case, it’s great how you can build a highly practical and free solution for monitoring the website and the web server with just a few nodes.
And here is the complete flow for import into Node-Red:
|
|
What do you think? Leave a comment!
Share your thoughts, questions or experiences with the community.