add update.motd

This commit is contained in:
root
2024-04-16 11:44:31 +02:00
parent 5828342201
commit 28901424ac
8 changed files with 166 additions and 0 deletions

19
update.motd/50-fail2ban-status Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# fail2ban-client status to get all jails, takes about ~70ms
jails=($(fail2ban-client status | grep "Jail list:" | sed "s/ //g" | awk '{split($2,a,",");for(i in a) print a[i]}'))
out="jail,failed,total,banned,total\n"
for jail in ${jails[@]}; do
# slow because fail2ban-client has to be called for every jail (~70ms per jail)
status=$(fail2ban-client status ${jail})
failed=$(echo "$status" | grep -ioP '(?<=Currently failed:\t)[[:digit:]]+')
totalfailed=$(echo "$status" | grep -ioP '(?<=Total failed:\t)[[:digit:]]+')
banned=$(echo "$status" | grep -ioP '(?<=Currently banned:\t)[[:digit:]]+')
totalbanned=$(echo "$status" | grep -ioP '(?<=Total banned:\t)[[:digit:]]+')
out+="$jail,$failed,$totalfailed,$banned,$totalbanned\n"
done
printf "\nfail2ban status:\n"
printf $out | column -ts $',' | sed -e 's/^/ /'