From ad6ad946cb91ceb443798a426f958c7add3e8d67 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 21 Feb 2024 23:48:38 +0100 Subject: [PATCH] Initial version --- README.md | 26 ++++++++++++++++++++++++++ check_apk | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 README.md create mode 100755 check_apk diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3a30ff --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Check APK + +Nagios/Icinga check plugin to monitor available upgrades on Alpine Linux and its APK packages manager. + +## Installation + +```bash +apk add wget +mkdir -p /usr/lib/nagios/plugins +wget -O /usr/lib/nagios/plugins/check_apk \ + https://gitea.zionetrix.net/bn8/check_apk/raw/branch/master/check_apk +chmod 750 /usr/lib/nagios/plugins/check_apk +``` + +## Copyright + +Copyright (c) 2024 Benjamin Renard + +## License + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + diff --git a/check_apk b/check_apk new file mode 100755 index 0000000..c52af97 --- /dev/null +++ b/check_apk @@ -0,0 +1,27 @@ +#!/bin/bash + +UPDATE=$(apk update 2>&1) +if [ $? -ne 0 ] +then + echo "UNKNOWN - Fail to update packages lists" + echo -e "$UNKNOWN" + exit 3 +fi + +UPGRADES=$(apk -u list 2>&1) +if [ $? -ne 0 ] +then + echo "UNKNOWN - Fail to list available upgrades" + echo -e "$UPGRADES" + exit 3 +fi + +if [ -z "$UPGRADES" ] +then + echo "OK - System is uptodate" + exit 0 +fi + +echo "WARNING - $(echo -e "$UPGRADES"|wc -l) upgrades available" +echo -e "$UPGRADES" +exit 1