50-fail2ban-status 858 B

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