Many years ago, maybe around 2017 or 2018, one of my ex-colleagues (Hi, Kevin!) said that I would probably even use Zabbix to come up with the winning lotto numbers. Just to strike back, I did exactly that with a small “easter egg” in Zabbix containing the lotto numbers – a quick bash script feeding the Zabbix item.
Let’s return to that topic, but use a Zabbix Script item type instead. Also, let’s take a look at few other details that help with monitoring.
Let’s create a host and a new template
To begin with, I created a new template and a new host. Here’s the host, nothing more needed than a name and my fancy template:
The template has only one item:
For the script, here’s what ChatGPT came up with. JavaScript is not my strongest skill, so for a fun little experiment this AI vibe coding should be good enough.
// Generate an array of numbers from 1 to 40 var numbers = []; for (var i = 1; i <= 40; i++) { numbers.push(i); } // Shuffle the array using the Fisher-Yates algorithm for (var i = numbers.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } // Select the first 7 numbers from the shuffled array var lotto = numbers.slice(0, 7); // Optionally sort the selected numbers lotto.sort(function(a, b) { return a - b; }); // Return the lottery numbers as a space-separated string return lotto.join(" ");
So, that’s it! Well, almost – to stop Zabbix from coming up with new numbers all the time, here’s a very nice feature of Zabbix.
Custom intervals
If you set your Update interval to 0, you can use Custom intervals. This way, the new numbers will only be generated once per week every Monday at 8:00 to kick off your work week (assuming that your country has the lotto only once per week, of course).
Naturally, in the actual business world, this kind of exact scheduled monitoring can be extremely helpful as well. If you have something you don’t need to check all the time but only during business days and hours, or only on weekends, or only once per day, this is a handy way of doing it.
Does it work?
You know the answer — of course it does! Now when I search for “lotto”, click on “Latest data” and force the check to happen immediately by clicking on “Execute now”, this happens.
Time to dashboard it
I could peek at the values from Latest data, but that would be boring. With a dashboard, it’s a bit more entertaining…
I hope this post gave you some new ideas or maybe even introduced you to Script item type. If you win some major money with this trick, don’t forget to buy me a coffee!