Get linux packages from Zabbix Monitoring

· 3 min read

To get Zabbix to send a list of all installed Linux packages along with their versions, you'll need to use custom scripts and user parameters to gather this information and then create an item and a trigger in Zabbix. Here’s a step-by-step guide to achieve this:

Step 1: Create a Script to List Installed Packages

Create a script on your Linux machine that lists all installed packages with their versions. Here’s an example script for both Debian-based and RPM-based distributions:

For Debian-based systems (e.g., Ubuntu):

#!/bin/bash
dpkg-query -W -f='${binary:Package} ${Version}\n'

For RPM-based systems (e.g., CentOS, RHEL):

#!/bin/bash
rpm -qa --qf '%{NAME} %{VERSION}-%{RELEASE}\n'

Save the script as list_packages.sh and make it executable:

chmod +x /path/to/list_packages.sh

Step 2: Configure Zabbix Agent

Edit the Zabbix agent configuration file (/etc/zabbix/zabbix_agentd.conf) to add a user parameter that will call the script. Add the following line:

UserParameter=custom.packages,/path/to/list_packages.sh

Restart the Zabbix agent to apply the changes:

sudo systemctl restart zabbix-agent

Step 3: Create an Item in Zabbix

Log in to the Zabbix frontend.

Navigate to Configuration > Hosts.

Select the host where you want to add the item.

Click on Items and then click on Create item.

Fill in the item details:

  • Name: List of installed packages
  • Type: Zabbix agent
  • Key: custom.packages
  • Type of information: Text
  • Update interval: Set it according to how frequently you want the information to be updated (e.g., daily).
  • History storage period: Set it to a reasonable period (e.g., 7 days).
  • Applications: (Optional) Assign it to an application group like "Packages".

Click Add to save the item.

Step 4: Create a Trigger (Optional)

If you want to trigger an alert based on changes in the installed packages, you can create a trigger.

Go to Configuration > Hosts and select the host.

Click on Triggers and then Create trigger.

Fill in the trigger details:

  • Name: Installed packages changed
  • Expression: {hostname:custom.packages.diff()}=1 (This expression checks if the output of the item has changed.)
  • Severity: Set the appropriate severity level.
  • Dependencies: (Optional) Set dependencies if needed.

Click Add to save the trigger.

Step 5: Create an Action to Send Notifications

Go to Configuration > Actions.

Click on Create action.

Fill in the action details:

  • Name: Notify about package list changes
  • Conditions: Add a condition to trigger based on the item or trigger created earlier.
  • Operations: Define the operation to send an email or other type of notification.

Click Add to save the action.

Step 6: Test the Configuration

Force the Zabbix agent to send the package list:

zabbix_agentd -t custom.packages

Verify the data in the Zabbix frontend.

Trigger the action to ensure notifications are sent correctly.

By following these steps, Zabbix will periodically collect the list of installed packages and their versions from your Linux machines, and you will be notified of any changes based on the configured triggers and actions.

stack8s.ai

Learn more about how stack8s.ai can help you avoid vendor lockin and save $$$. Hybrid and MultiCloud deployments at your figertips. Get in touch to collaborate.

Book - Quick Demo

🚀 Automate Your Linux Package Management with Zabbix! 🖥️

Ever wondered how to get a comprehensive list of all installed Linux packages and their versions using Zabbix? 🤔 With custom scripts and user parameters, it's easier than you think! 📊

Check out this step-by-step guide to set it up:

1️⃣ Create a script to list installed packages.
2️⃣ Configure Zabbix Agent to use this script with user parameters.
3️⃣ Create an item in Zabbix to collect the data.
4️⃣ Set up a trigger to monitor changes.
5️⃣ Send notifications to stay updated! 📩

🔧 With these simple steps, you can ensure your Linux systems are always up-to-date and secure. Don't miss out on this powerful monitoring capability!

#Linux #Zabbix #DevOps #SysAdmin #Automation #TechTips