mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
44 lines
1.0 KiB
Perl
44 lines
1.0 KiB
Perl
#!/usr/local/bin/perl
|
|
|
|
# Add this to your snmpd.conf as below.
|
|
# extend fail2ban /etc/snmp/fail2ban
|
|
|
|
#make sure this path is correct
|
|
my $f2bc="/usr/local/bin/fail2ban-client";
|
|
|
|
##
|
|
## you should not have to touch anything below this
|
|
##
|
|
use strict;
|
|
use warnings;
|
|
|
|
#gets a list of jails
|
|
my $jailsOutput=`$f2bc status`;
|
|
my @jailsOutputA=split(/\n/, $jailsOutput);
|
|
my ( $jailsS )=grep( /Jail\ list/, @jailsOutputA );
|
|
$jailsS=~s/.*\://;
|
|
$jailsS=~s/\s//g;
|
|
my @jails=split(/\,/, $jailsS);
|
|
|
|
#process jail
|
|
my $int=0;
|
|
my $total=0;
|
|
my $toReturn='';
|
|
while(defined($jails[$int])){
|
|
|
|
#get the total for this jail
|
|
my $jailStatusOutput=`fail2ban-client status $jails[$int]`;
|
|
my @jailStatusOutputA=split(/\n/, $jailStatusOutput);
|
|
my ( $jailTotal )=grep(/Currently\ banned\:/, @jailStatusOutputA);
|
|
$jailTotal=~s/.*\://;
|
|
$jailTotal=~s/\s//g;
|
|
|
|
#tally the total and add this jail to the list
|
|
$total=$total+$jailTotal;
|
|
$toReturn=$toReturn.$jails[$int].' '.$jailTotal."\n";
|
|
|
|
$int++;
|
|
}
|
|
|
|
print $total."\n".$toReturn;
|