From e3b59c08c8e341d3dc890286beba4e12a61807de Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Sun, 3 Oct 2021 15:30:02 -0500
Subject: [PATCH] Add check_apt_pending

---
 check_apt_pending | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100755 check_apt_pending

diff --git a/check_apt_pending b/check_apt_pending
new file mode 100755
index 0000000..8531055
--- /dev/null
+++ b/check_apt_pending
@@ -0,0 +1,33 @@
+#! /bin/bash
+#
+# Gets the number of pending APT package updates and returns differently
+# depending on how many have yet to be applied
+#
+
+threshold_warn=10
+threshold_crit=20
+
+# https://askubuntu.com/questions/269606/apt-get-count-the-number-of-updates-available
+pending="$(apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | \
+	/bin/grep  ^Inst | \
+	wc -l)"
+
+if [ -n "$pending" ]; then
+	if (( pending >= threshold_crit )); then
+		echo "CRITICAL - $pending package updates pending"
+		exit 2
+	elif (( pending >= thresold_warn )); then
+		echo "WARNING - $pending package updates pending"
+		exit 1
+	elif (( pending > 0 )); then
+		echo "OK - $pending package updates pending"
+		exit 0
+	else
+		echo "OK - No updates available"
+		exit 0
+	fi
+else
+	echo "UNKNOWN - Unable to get pending updates"
+	exit 3
+fi
+