
Many years ago, maybe around 2017 or 2018, one of my ex-colleagues (Hi, Kevin!) said that I probably would use Zabbix even to come up with the lottery numbers. Back then, just to strike back, I did exactly that, with a small easter egg in work Zabbix containing the lotto numbers. That was a quick bash script feeding the Zabbix item.
Now, let's return to that topic, but use Zabbix Script item type instead. Also, let's take a look at few other details that help in 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 else needed than a name and my fancy template:

And then 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! Almost. To not make Zabbix to come up with the new numbers all the time, here's one of very nice features of Zabbix.
Custom intervals

If you set Update interval to 0, you can use Custom intervals. This way, the new numbers will only be generated once per week every Monday 8am to kick off your work week. (I am assuming your country has the lotto only once per week).
Of course, in actual business world monitoring this kind of exact scheduled monitoring can be extremely helpful, too. 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 handy way of doing it.
Does it work?
You know the answer -- of course it does. Now when I search for lotto and click on Latest data and to force the check to happen immediately, click on Execute now, this happens.

Time to dashboard it
I could peek the values from Latest data, but that would be boring. With a dashboards, it's a bit more entertaining..

I hope this gave you new ideas or maybe even introduced you to Script item type. And, if you win some major money with this trick, don't forget to buy me a coffee.
Add new comment