Skip to content

Access Fail2Ban Data from Docker Container #187

Description

@Shaun-Harrison

Hello

Been using a modified version of this script for quite some time, finally decided to look at the container as always been running as a service so that I could run bash commands within the script to get some data

Is it possible to be able to get data from the host when using the container? Basically want to know if there are any IPS in the fail2ban jail, which I previously done with (not an software engineer so take my code with a grain of salt :D) ;

def get_fail2ban_sshd_banned():
    print("DEBUG: F2B SSH")
    proc1 = subprocess.run(['fail2ban-client status sshd'], stdout=subprocess.PIPE, shell=True)
    proc2 = subprocess.run(['sed -n 7p'], input=proc1.stdout, stdout=subprocess.PIPE, shell=True)
    proc3 = subprocess.run(['tr -dc "0-9"'], input=proc2.stdout, stdout=subprocess.PIPE, shell=True)
    answer = os.linesep.join([s for s in proc3.stdout.decode().splitlines() if s])
    answer = answer.strip()
    answer = str(answer)
    return answer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions