About Zabbix

Zabbix is a free and open source network monitoring Software tool which is used to monitor and track the availability and performance of your IT infrastracture: servers, network devices and other IT assets.

In this article we are going to demonstrate how to monitor APT package available updates using Zabbix 3.4 on Ubuntu Servers, we are going to use a script to send the number of APT available security and regulare updates to Zabbix Server using a scheduled cron job. You can download the script and the template from our github repository



Check our previous tutorials to learn how to install Zabbix Server:

Environment:

Hostname = zabbix.yallalabs.com

IP Address = 192.168.1.151

OS = CentOS 7 / RHEL 7

Hostname = ylclzbxcl05.yallalabs.com

IP Address = 192.168.1.145

OS = Ubuntu 16.04 LTS

Requirements

– Make sure to install the zabbix-sender package on the server where would you like to monitor the APT package updates using the following command :

# apt-get install zabbix-sender

– Make sure that update-notifier-common Package are installed, on ubuntu is installed by default, if not use the follwoing command :

# apt-get install update-notifier-common

– Download apt-updates.sh script using wget or curl:

# wget https://raw.githubusercontent.com/faudeltn/Zabbix/master/APT%20Updates/apt-updates.sh

# cat apt-updates.sh #!/usr/bin/env bash # Author: Waderni Lotfi # Description: apt updates info # ZBX_HOSTNAME_PRESENT=$(egrep ^HostnameItem /etc/zabbix/zabbix_agentd.conf -c) #echo $ZBX_HOSTNAME_PRESENT if [ "$ZBX_HOSTNAME_PRESENT" -ge "1" ]; then #ZBX_HOSTNAME=$(egrep ^Hostname /etc/zabbix/zabbix_agentd.conf | cut -d = -f 2) ZBX_HOSTNAME=$(hostname) else #ZBX_HOSTNAME=$(hostname) ZBX_HOSTNAME=$(egrep ^Hostname /etc/zabbix/zabbix_agentd.conf | cut -d = -f 2) fi #echo $ZBX_HOSTNAME; UPDATES=$(/usr/lib/update-notifier/apt-check 2>&1||echo "-1,-1") echo -n '"'$ZBX_HOSTNAME'"' 'apt.security ' echo $UPDATES|cut -d';' -f2 echo -n '"'$ZBX_HOSTNAME'"' 'apt.updates ' echo $UPDATES|cut -d';' -f1 echo -n '"'$ZBX_HOSTNAME'"' 'OS.release ' lsb_release -a 2>/dev/null|grep Release|awk '{print $2}'

– Make the script executable using the following command:

# chmod +x apt-updates.sh

– Set up a cron job that pipes the output of the cron job to the Zabbix sender as below:

00 23 * * * ./apt-updates.sh | zabbix_sender -z IP-ZABBIX-SERVER -i - >/dev/null

– Download the APT-Updates.xml Template from this link https://github.com/faudeltn/Zabbix/tree/master/APT%20Updates and import it into Zabbix Frontend

– Link the APT-Updates.xml Template to the moniored host, if you want to check if the script works correctly just run the following command :

# ./apt-updates.sh | zabbix_sender -z IP-ZABBIX-SERVER -i - >/dev/null

– From the latest data menu Tab you should see the number of available regular and security updates as below:

– In the Below you can see an example of triggers:





We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!