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:
- How To Install Zabbix 3.4 Monitoring Server On Ubuntu 16.04 LTS
- How To Install Zabbix 3.4 Server On CentOS 7 / RHEL 7
- How to install Zabbix Agent on Ubuntu 16.04 LTS
- How to install Zabbix Agent on CentOS 7 / RHEL 7
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!
PS. If you like this post please share it with your friends on the social networks using the buttons below.Thanks.
10 comments
Awesome tuto ! Thanks
Hi Lotfi,
Great tutorial!
I’ve got an issue when executing the command to test it:
command: ./apt-updates.sh | zabbix_sender -z 192.168.0.55 -i –
message: info from server: “processed: 0; failed: 3; total: 3; seconds spent: 0.000065”
Despite the fact I added the template on the desired sever, I cannot see the APT menu in the latest data menu.
Could you help me, please?
Hi,
try to run this command manually
/usr/lib/update-notifier/apt-check 2>&1||echo "-1,-1"
and check the output if it’s correctI’ve been looking for something like this in my homelab. This is very useful. Thank you 🙂
Works perfectly, many thanks
I wanted to ask, is there a way to do this on RedHat/CentOS?
Hi James,
you can found the code here : Check Yun update
I got it to work. Thank you :))
I wanted to ask, when I open PSK function. It won’t sent information, and when I turn off PSK function it works.
If there have any solution to do this with PSK
Tanks a lot , Works perefctly