Skip to header Skip to main navigation Skip to main content Skip to footer

Search form

Site branding

Home
What's up, home?

Main navigation

  • Home
  • Story mode
  • About
  • Features
  • Hardware list
  • Videos
  • GitHub (opens in new tab)
  • Daily AI generated stories (opens in new tab)

Part 101: Zabbix plays rock-paper-scissors

Breadcrumbs

Breadcrumb

  • Home
  • Part 101: Zabbix plays rock-paper-scissors

Main page content

By whatsuphome | 10:48 PM EEST, Mon October 14, 2024

TL;DR

Zabbix 7.0's new Selenium-based Browser item type opens up fun possibilities, so I made Zabbix play rock-paper-scissors against a PHP script on my blog. Both Zabbix and the PHP endpoint pick a random move, and the Browser item compares the results to
What's up, home? part 101 cover image

Zabbix 7.0 is so fast that in a small environment such as What's up, home? it gets bored. Very bored.

What does Zabbix do when it gets bored? It uses its new Selenium-based Browser item type and plays some Rock-Paper-Scissors against this blog site.

Rock-paper-scissors latest data

But how does that work?

The idea is simple. My website hosts a very simple PHP script which returns back a random value of "Rock", "Paper" or "Scissors". Likewise, my Zabbix Selenium test picks up a random word out of those. Then, the Selenium test checks both answers and gets back the result.

So, in all seriousness, this blog post demonstrates you how the new Browser item type can react to different responses.

Backend code

Here's the PHP script in all its g(l)ory: 

<html>

<head>

       <title>Whatsuphome.fi :: rock-paper-scissors</title>

</head>

<body>

<p>

<?php

$choices = ["Rock", "Scissors", "Paper"];

$random_choice = $choices[array_rand($choices)];

echo $random_choice;

?>

</p>

</body>

</html>

Nothing to call home about in that script: array with three choices, pick a random choice, print the result, done.

Zabbix side

I created a new Browser type item like this:

Browser item

 

... and here's the script part I just hammered in, so there might or might not be bugs. I really did not test this very thoroughly. 

var browser = new Browser(Browser.chromeOptions());

const moves = ["Rock", "Scissors", "Paper"];

const zabbixMove = moves[Math.floor(Math.random() * moves.length)];

try {

   browser.navigate("https://whatsuphome.fi/rps.php");

   var opponentMove = browser.findElement("xpath", "//p").getText();

   if (zabbixMove === opponentMove) {

       var winner = "Draw";

   }

   else if (

      (zabbixMove === "Rock" && opponentMove === "Scissors") || 

      (zabbixMove === "Scissors" && opponentMove === "Paper") ||

      (zabbixMove === "Paper" && opponentMove === "Rock")

   ) { 

       var winner="Zabbix";

   }

   else {

      var winner="Opponent";

   }

}

finally {

    return ("Winner is " + winner + ". Zabbix move was " + zabbixMove + " and opponent move was " + opponentMove);

}

That's it! From now on my Zabbix will play the game once per hour, although for this blog post I did manually click the Execute now button few times. Again, here's the same screenshot that was also in the beginning of this blog post.

Rock-paper-scissors latest data

Happy gaming! 

whatsuphome
zabbix
selenium
rps
  • 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.
Zabbix 7.0's new Selenium-based Browser item type opens up fun possibilities, so I made Zabbix play rock-paper-scissors against a PHP script on my blog. Both Zabbix and the PHP endpoint pick a random move, and the Browser item compares the results to

Search

Who am I?

  • Janne Pikkarainen from Finland 🇫🇮
  • Began with computers in 1986 with C64
  • Doing IT for living since 1999
  • Principal Site Reliability Engineer at Forcepoint
  • A Zabbix Summit speaker every year since 2022
  • Walking, talking Zabbix commercial

Support my project

Buy me a coffee 

Footer menu

  • Contact

What's up, home? | Janne Pikkarainen | contact(at)whatsuphome.fi | 2022 - 2026

Developed and Designed by Janne Pikkarainen