Push script for Uptime Kuma that reports list of outdated packages on an Ubuntu server
Posted on 2023/03/15 by Dirk van der Laarse
I like to use Uptime Kuma to monitor uptime of my side projects. I've also made this quick and dirty script below to remind me to keep apt packages up to date on my ubuntu hosts.
Create script uptime_kuma_spm_reporting.sh and mark executable with chmod +x uptime_kuma_spm_reporting.sh:
#!/bin/bash
# 2023-03-15
# Dirk van der Laarse
# Get number of outdated packages and report to
# Uptime Kuma at mysite.com
# Get count of outdated packages
# https://stackoverflow.com/a/21957287/1904492
outdated_packages=$(apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst)
acceptable="20"
status="down"
msg="More%20than%2020%20packages%20are%20outdated"
if (( $(echo "$outdated_packages < $acceptable" | bc -l) )); then
status="up"
msg="OK"
fi
# Make API Call
echo "Making API call with params status=$status&ping=$outdated_packages&msg=$msg"
curl -k -s "https://mysite.com/api/push/123456789?status=$status&ping=$outdated_packages&msg=$msg"
echo "---"
Crontab example:
server@home-server:~ $ sudo crontab -l
0 0 * * 0 /opt/Scripts/uptime_kuma_spm_reporting.sh >> /var/log/uptime_kuma_spm_reporting.log 2>&1
