From affd0964f4448fdd2c918212f06bef3be9b7b410 Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Fri, 22 May 2026 19:29:32 +0200 Subject: [PATCH] add check_apt_update --- files/nrpe/check_apt_update | 26 ++++++++++++++++++++++++++ templates/nrpe.j2 | 1 + templates/nrpe.sudoers.j2 | 1 + 3 files changed, 28 insertions(+) create mode 100644 files/nrpe/check_apt_update diff --git a/files/nrpe/check_apt_update b/files/nrpe/check_apt_update new file mode 100644 index 0000000..9873735 --- /dev/null +++ b/files/nrpe/check_apt_update @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Usage: /usr/lib/nagios/plugins/check_apt_update + +# Nagios Exit Codes +OK=0 +WARNING=1 +CRITICAL=2 +UNKNOWN=3 + +OUTPUT=$(sudo apt -o APT::Update::Error-On-NoReleaseUrls=true -q -y update 2>&1) +EXIT_CODE=$? + +if [ $EXIT_CODE -eq 0 ] && [[ ! "$OUTPUT" =~ "W:" ]]; then + echo "OK - apt update completed successfully." + exit $OK +else + CLEAN_OUTPUT=$(echo "$OUTPUT" | grep -E "(E:|W:)" | head -n 1) + + if [ -z "$CLEAN_OUTPUT" ]; then + CLEAN_OUTPUT=$(echo "$OUTPUT" | head -n 2 | tr '\n' ' ') + fi + + echo "WARNING - Issue during apt update | ${CLEAN_OUTPUT}" + exit $WARNING +fi \ No newline at end of file diff --git a/templates/nrpe.j2 b/templates/nrpe.j2 index 37e67ad..32cf893 100644 --- a/templates/nrpe.j2 +++ b/templates/nrpe.j2 @@ -22,6 +22,7 @@ command[check_systemd_failed]=/usr/lib/nagios/plugins/check_systemd_failed command[check_needrestart]=/usr/lib/nagios/plugins/check_needrestart command[check_reboot_required]=/usr/lib/nagios/plugins/check_reboot_required command[check_ntp_time]=/usr/lib/nagios/plugins/check_ntp_time -H {{ nrpe_ntp_host }} -w {{ nrpe_ntp_warning }} -c {{ nrpe_ntp_critical }} +command[check_apt_update]=/usr/lib/nagios/plugins/check_apt_update # disk # -w <%>: Warning threshold for block usage. diff --git a/templates/nrpe.sudoers.j2 b/templates/nrpe.sudoers.j2 index b879a9f..01223d5 100644 --- a/templates/nrpe.sudoers.j2 +++ b/templates/nrpe.sudoers.j2 @@ -2,6 +2,7 @@ nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/check_postfix_mailqueue -w {{ nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/check_exim_mailqueue -w {{ nrpe_mailq_warning }} -c {{ nrpe_mailq_critical }} nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/check_raid nagios ALL=(ALL) NOPASSWD: /usr/sbin/needrestart -b -l +nagios ALL=(ALL) NOPASSWD: /usr/bin/apt -o APT\:\:Update\:\:Error-On-NoReleaseUrls=true -q -y update {% if nrpe_kubernetes_controlplane is defined %} nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/check_cilium_health