HEX
Server: Apache
System: Linux dinesh8189 5.15.98-grsec-sharedvalley-2.lc.el8.x86_64 #1 SMP Thu Mar 9 09:07:30 -03 2023 x86_64
User: cgmgerenciamento1 (814285)
PHP: 8.1.26
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //proc/thread-self/root/etc/zabbix/monitoring/check_fail2ban_banned.py
#!/usr/bin/env python3

import subprocess
import sys

def get_total_banned_ips(jail_name):
    try:
        command = f"sudo fail2ban-client status {jail_name}"
        result = subprocess.run(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True
        )

        for line in result.stdout.split('\n'):
            if "Total banned" in line:
                return line.split(':')[1].strip()
        return "0"
    except Exception as e:
        return "0"

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: check_fail2ban_banned.py <jail_name>")
        sys.exit(1)

    jail_name = sys.argv[1]
    print(get_total_banned_ips(jail_name))