Part 11: Say cheese!

Get your Selenium

Can you take screenshots of your monitored websites with Zabbix? Of course you can! By day, I earn my living by being a monitoring tech lead in a global cyber security company. By night, I monitor my home. Welcome to my weekly blog about how I monitor my home with Zabbix & Grafana and do some weird experiments with them.

A proper full-stack monitoring does cover everything from device physical status to what end-user sees. However, often even with website monitoring we admins only rely on all kinds of run-time data; operating system load, hardware health, service response times and logs. If your site has some rarely occurring technical issue, you might not have any idea how the site looks like when the error happens. Is your site looking really wrong or is maybe just a panel or two misbehaving during some issue?

Zabbix & Selenium to the rescue!

Get your Selenium

No, even if this post is meant to provide some food for thought, I am not speaking about the selenium your metabolism needs. Instead I am speaking about a web-test framework which allows you to automate web browsers by using Java, Python, or several other languages it supports. It's probably most useful for web browser & web site developers so they can be sure that their sites look OK on all major browsers and so forth, but why not to utilise that with your monitoring, too?

Python script

With a really short Python script -- or whatever language -- you can spawn a headless instance of whatever browser you want and ask it to do stuff for you. In the horribly simple example above, script can be called like

selenium_screenshot.py blog.zabbix.com

and it then saves the screenshot under /usr/share/zabbix/assets/webtest-screenshots/ directory which is accessible by my home Zabbix & Grafana.

Now, where did I put that script?

What I actually use this for at home is that whenever some lunch restaurants publish their new menus, my Zabbix grabs a screenshot of the lunch menus and I can then spy the menus without a need to go to sites by myself.

As I do not want to show more exact location of the places I visit, in this example I'll show you how to screenshot blog.zabbix.com site instead.

Hooking the script to Zabbix is easy; just add the script to Zabbix via its Administration --> Scripts, and add it as a script you can call via Actions, and if you so want, also put it as a manual action so you can call the script manually any time you want through Zabbix contextual menus.

Zabbix scripts menu

Then just add a trigger which snaps a screenshot whenever your web test is failing.

Say cheese!

Now that we have our screenshot mechanism in place, this is how it looks through Zabbix URL widget:

Zabbix dashboard

... and this is how it looks when embedded to Grafana with its Text panel, HTML content type and a simple <img> tag:

Grafana dashboard

What's this useful for?

Lots of stuff. From now on, you too can easily embed a screenshot of your monitored website within your monitoring environment. Put some more panels to that dashboard showing the active alerts, graphs, run-time data and logs, and you can a very comprehensive full stack monitoring in place.

Or make your screenshot script more intelligent (I recommend that anyway), and make it save the files with date stamp info in filenames, so you can have a nice little time machine inside Grafana and its time picker.

Selenium can also give you much more other details, such as performance data or the URLs which were called during the page load. I'm sure that's useful, too.

I have been working at Forcepoint since 2014 and never get tired of getting a more clear view of the status of the stuff I monitor.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Buy me a coffee

Like these posts? Support the project and Buy me a coffee