check-npm.sh aktualisiert
custom ssl
This commit is contained in:
+41
-12
@@ -1,10 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Checkmk Local Check: Alle NPM-SSL-Zertifikate prüfen mit Domainnamen
|
# Checkmk Local Check: Alle SSL-Zertifikate prüfen mit Domainnamen
|
||||||
# Speicherort: /usr/lib/check_mk_agent/local/npm_cert_check.sh
|
# Speicherort: /usr/lib/check_mk_agent/local/npm_cert_check.sh
|
||||||
|
|
||||||
CERT_BASE="/etc/letsencrypt/live"
|
BASE_DIRS=(
|
||||||
WARN_DAYS=30
|
"/etc/letsencrypt/live"
|
||||||
CRIT_DAYS=10
|
"/data/custom_ssl"
|
||||||
|
)
|
||||||
|
|
||||||
|
WARN_DAYS=14
|
||||||
|
CRIT_DAYS=5
|
||||||
|
|
||||||
check_cert() {
|
check_cert() {
|
||||||
local cert_file="$1"
|
local cert_file="$1"
|
||||||
@@ -37,20 +41,45 @@ check_cert() {
|
|||||||
STATUS=0
|
STATUS=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# SAN-Einträge (Alternative Namen) auslesen
|
# SAN-Einträge auslesen
|
||||||
SAN=$(openssl x509 -noout -text -in "$cert_file" 2>/dev/null | grep -A1 "Subject Alternative Name" | tail -n1 | sed 's/DNS://g; s/,//g')
|
SAN=$(openssl x509 -noout -text -in "$cert_file" 2>/dev/null \
|
||||||
|
| grep -A1 "Subject Alternative Name" | tail -n1 \
|
||||||
|
| sed 's/DNS://g; s/,//g')
|
||||||
|
|
||||||
echo "$STATUS cert_${CN} days_left=$DAYS_LEFT;${WARN_DAYS};${CRIT_DAYS};0; Zertifikat '$CN' läuft in $DAYS_LEFT Tagen ab (SAN: $SAN)"
|
echo "$STATUS cert_${CN} days_left=$DAYS_LEFT;${WARN_DAYS};${CRIT_DAYS};0; Zertifikat '$CN' läuft in $DAYS_LEFT Tagen ab (SAN: $SAN)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Alle Zertifikate unter /etc/letsencrypt/live/npm-* prüfen
|
# Zertifikate in allen Base Directories prüfen
|
||||||
if [ -d "$CERT_BASE" ]; then
|
for CERT_BASE in "${BASE_DIRS[@]}"; do
|
||||||
find "$CERT_BASE" -mindepth 1 -maxdepth 1 -type d -name "npm-*" | while read -r dir; do
|
LABEL=$(basename "$CERT_BASE" | tr '/ ' '_')
|
||||||
|
|
||||||
|
if [ -d "$CERT_BASE" ]; then
|
||||||
|
FOUND_CERT=0
|
||||||
|
|
||||||
|
# falls du wieder nur bestimmte Ordner willst, z.B. npm-*:
|
||||||
|
# find "$CERT_BASE" -mindepth 1 -maxdepth 1 -type d -name "npm-*"
|
||||||
|
find "$CERT_BASE" -mindepth 1 -maxdepth 1 -type d | while read -r dir; do
|
||||||
cert_file="$dir/fullchain.pem"
|
cert_file="$dir/fullchain.pem"
|
||||||
if [ -f "$cert_file" ]; then
|
if [ -f "$cert_file" ]; then
|
||||||
|
FOUND_CERT=1
|
||||||
check_cert "$cert_file"
|
check_cert "$cert_file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
|
||||||
echo "2 cert_check - Zertifikatspfad $CERT_BASE nicht gefunden"
|
# WICHTIG: FOUND_CERT aus der while-Schleife korrekt benutzen
|
||||||
fi
|
# -> deshalb die Auswertung mit Subshelleinsatz umgehen:
|
||||||
|
if ! find "$CERT_BASE" -mindepth 1 -maxdepth 1 -type d -print -quit | grep -q .; then
|
||||||
|
# gar keine Unterverzeichnisse
|
||||||
|
echo "0 cert_info_${LABEL} - Keine Zertifikatsverzeichnisse in ${CERT_BASE} gefunden"
|
||||||
|
else
|
||||||
|
# es gibt Unterverzeichnisse, aber evtl. keine fullchain.pem
|
||||||
|
ANY_CERT=$(find "$CERT_BASE" -mindepth 2 -maxdepth 2 -type f -name "fullchain.pem" -print -quit)
|
||||||
|
if [ -z "$ANY_CERT" ]; then
|
||||||
|
echo "0 cert_info_${LABEL} - Keine Zertifikate (fullchain.pem) in ${CERT_BASE} gefunden"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Verzeichnis existiert nicht -> OK mit Info
|
||||||
|
echo "0 cert_info_${LABEL} - Verzeichnis ${CERT_BASE} nicht vorhanden, keine Zertifikate geprüft"
|
||||||
|
fi
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user