Cet article est aussi disponible en Français.
This post is coming from a true story where I wanted to immediately alert my daughter when her university registration page is available. The page that needed to be monitored was behind a login/password page.
This year, Santa added a new Toy Order Service.
If log in with your email and the right password, which is santa
in this example, you will see that the service is not ready yet.
But what if you want to be alerted as soon as the service is available. How can you monitor that? You don't even know what the service will be looking like, because you don't own it.
So for this journey, I used Elastic Synthetic Monitoring as that was the easiest thing to do for me as I know it runs nicely on cloud.elastic.co and I won't have to start any VM on internet to do those checks.
What is need to implement that?
- I need to detect that after logged in the service, the text is not anymore "The service is not yet open. It will open on December 1, 2024 at midnight."
- If this text is not the same, or if anything different is happening (like going to another page), I need to alert using an email, but also using Slack as I'd get then a proper notification on my phone.
Setup the monitor
Let's first create a monitor. It's just going to check that the web page is available. Note that I can check that the service is also available from multiple locations on earth. Here I just chose the UK location to run my tests from. Elastic cloud comes with plenty of locations out of the box.
But then, we don't test the user journey: login, check the text. So we need to edit our monitor:
The monitoring of a service comes with a default Playwright script which just open a page:
You can manually edit this, or you can use the Synthetics Recorder which is going to reproduce the user behaviour as a script.
Synthetics Recorder
Open the Synthetics Recorder.
Then click Start
. This opens a browser. Just click and navigate within the website, click on the login button, enter your email and your password and then validate.
Click on the text you want to check. And stop the recorder.
We just want to edit the last action (the text selection) so we can add an assertion on the inner text. We just select the heading and check that the value is what you are seeing at the moment: "The service is not yet open. It will open on December 1, 2024 at midnight."
.
We can just import the script into Synthetics Monitoring:
Start monitoring
Just enable the monitor and change the frequency if needed. As I wanted to be super reactive, I set the frequency to 1 minute.
After some runs, you will see that everything is ok as the text on the website does not change.
Slack alerting
To add a slack connector, you need first to create an app on Slack.
Then activate the webhook.
And define in which channel, the application will be sending messages.
That adds a webhook. Copy the value.
Paste it in the connector on Kibana.
You can now create edit the alert for the Monitor status rule.
And add the Santa Slack connector (and the e-mail connector if you wish)
Wait for the webpage to be updated
Once it's running, it won't produce any alert until the page change. That will make the Playwright script failing.
This will trigger the notification we are expecting.
With all the default details provided by the alert. I just hidden on this screen capture the exact URL of the Kibana cluster.
Order your toys!
With this simple technique, you will be probably the first person to know that Santa has really opened the service, even though it's before what was written on the website. So you can just go there and order the toys you are dreaming of.
Merry Christmas Elky!