Update monitoring by Zabbix

Update monitoring by Zabbix

Can you use Zabbix to monitor Linux updates? Yes you can! I am going to show you how to set this up!

1. Create a Bash Script:

Start by creating a Bash script on your Linux server that checks for outstanding updates. You can name it something like `check_updates.sh`:‌

#!/bin/bash
updates=$(sudo apt-get -s dist-upgrade | grep "upgraded" | awk '{print $1}')
echo $updates

This script uses `apt-get` to simulate a dist-upgrade and then extracts the number of upgraded packages.

2. Make the Script Executable:

Make sure the script is executable by running:‌

   chmod +x check_updates.sh

3. Configure Sudo Access:

Ensure that the Zabbix user has the necessary permissions to execute the script with sudo without requiring a password. You can do this by modifying the sudoers file (`/etc/sudoers`) using `visudo` and adding the following at the bottom of the file:‌

zabbix ALL=(ALL) NOPASSWD: /path/to/check_updates.sh

Replace `/path/to/check_updates.sh` with the actual path to your script.

4. Create a Zabbix User Parameter:‌

UserParameter=custom.linux_updates[*],sudo /path/to/check_updates.sh

Replace `/path/to/check_updates.sh` with the actual path to your script

5. Restart Zabbix Agent:

Restart the Zabbix agent to apply the changes:‌

sudo service zabbix-agent restart

6. Create an Item and Trigger in Zabbix:

In the Zabbix web interface, create a new item using the `custom.linux_updates` key, and specify the target host where this script should run. Then, create a trigger that alerts you when the item value is greater than zero.

Now, Zabbix will periodically execute the script to check for outstanding Linux updates on the specified host, and you can set up alerting or monitoring based on the trigger you've defined.