Monitor website status with Huginn

Posted by ads on Wednesday, 2020-10-14
Posted in [Huginn][Online]

After setting up Huginn, and implementing the actions on my todo list, I had a look at the available agents and started thinking what else they can be useful for.

One of the ideas I came up with is monitoring if a website is available, or has some trouble. I already have a monitoring system in place, but it’s a nice exercise to learn more about the other agents.

For this scenario I only need two agents:

  • Http Status Agent
  • Email Agent

Http Status Agent

First thing to do is monitor the website in question. Ideally use an URL which normally returns a 200 status code, and no redirect.

Set a name for the agent, and define how often the agent is to monitor the website. The dropdown allows different values between 1 minute and weekly. In my case I picked 10 minutes. Enter the URL, set Disable redirect follow to True, Changes only to True and save everything.

Email Agent

The second step is the Email Agent. Again define a name, and select the Http Status Agent as Event Source. The options can be as follow:

  • expected_receive_period_in_days: how often do you expect the website to go down? I set 365 day here, just to be on the safe side.
  • content_type: text/html

The subject and body can include Liquid formats, remove the headline, and maybe set recipients and from.

Subject:

1
Website: <insert website name here> {% if response_received == false %}is offline{% else %}{% if status == "200" %}is online{% else %}has problems{% endif %}{% endif %}

Body:

1
<br/>The website {% if response_received == false %}is offline{% else %}{% if status == "200" %}is online{% else %}has problems{% endif %}{% endif %}!{% if response_received == true %}<br/><br/>Status code: {{ status }}<br/>{% endif %}

How does it work?

Every time the status of the website changes, Huginn (more exactly: the Http Status Agent) will emit an event. This event is picked up by the Email Agent, Subject and Body are formatted, and everything is send out.

Possible improvements

  • Feel free to update the templates for Subject and Body, and include more information
  • Find a way to implement a threshold: only alert if the status is != 200 for a certain number of events
  • Use the Website Agent to check the actual content of the website

Categories: [Huginn] [Online]

Share: