From 39210211f8a36060b4d58eff2ca88439653a3f4f Mon Sep 17 00:00:00 2001 From: techie2000 Date: Fri, 9 Aug 2024 10:30:17 +0100 Subject: [PATCH] recognise the world is moving to journalctl --- 36-diskstatus-journalctl | 66 +++++++++++++++++++++++++++ 36-diskstatus => 36-diskstatus-syslog | 0 README.md | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 36-diskstatus-journalctl rename 36-diskstatus => 36-diskstatus-syslog (100%) diff --git a/36-diskstatus-journalctl b/36-diskstatus-journalctl new file mode 100755 index 0000000..fc8d323 --- /dev/null +++ b/36-diskstatus-journalctl @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# config +MAX_TEMP=40 +# set column width +COLUMNS=2 +# colors +white="\e[39m" +green="\e[1;32m" +red="\e[1;31m" +dim="\e[2m" +undim="\e[0m" + +# disks to check +disks=(sda sdb sdc sdd sde sdf sdg sdi) +disknames=(sda sdb sdc sdd sde sdf sdg sdi) + +# hddtemp +hddtemp_host=localhost +hddtemp_port=7634 + +# get all lines with smartd entries from journalctl +lines=$(journalctl -u smartd --no-pager | grep -hiP 'smartd\[[[:digit:]]+\]:' | grep -iP "previous self-test") +# use nc to query temps from hddtemp daemon +hddtemp=$(timeout 0.01 nc $hddtemp_host $hddtemp_port | sed 's/|//m' | sed 's/||/ \n/g') + +out="" +for i in "${!disks[@]}"; do + disk=${disks[$i]} + # use disknames if given + diskname=${disknames[$i]} + if [ -z "${diskname}" ]; then + diskname=$disk + fi + uuid=$(blkid -s UUID -o value "/dev/${disk}") + status=$( (grep "${uuid}" <<< "${lines}") | grep -m 1 -oP "previous self-test.*" | awk '{ print $4 " " $5 }') + temp=$( (grep "${disk}" <<< "${hddtemp}") | awk -F'|' '{ print $3 }') + + # color green if temp <= MAX_TEMP, else red + if [[ "${temp}" -gt "${MAX_TEMP}" ]]; then + color=$red + else + color=$green + fi + # add "C" if temp is numeric + if [[ "$temp" =~ ^[0-9]+$ ]]; then + temp="${temp}C" + fi + # color green if status is "without error", else red + if [[ "${status}" == "without error" ]]; then + status_color=$green + else + status_color=$red + fi + + # print temp & smartd error + out+="${diskname}:,${color}${temp}${undim} | ${status_color}${status}${undim}," + # insert \n every $COLUMNS column + if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then + out+="\n" + fi +done +out+="\n" + +printf "\ndisk status:\n" +printf "$out" | column -ts $',' | sed -e 's/^/ /' \ No newline at end of file diff --git a/36-diskstatus b/36-diskstatus-syslog similarity index 100% rename from 36-diskstatus rename to 36-diskstatus-syslog diff --git a/README.md b/README.md index 5d34a9e..2894163 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ option set to `yes` in your sshd config. The duplicate files are different versions of the same, use either one of them. E.g. `30-zpool-simple` will not print usage bars. -The script `36-smartd` greps syslog for smartd entries to read temperature and last self-test result. +The script `36-smartd` greps syslog/journctl for smartd entries to read temperature and last self-test result. You have to enable smartd monitoring & run regular self-tests for it to display anything. If you use `50-fail2ban` you should comment out the `compress` option in `/etc/logrotate.d/fail2ban`,