Advertisement
Krapace

Stat Fail2ban Perl

Apr 15th, 2017
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.00 KB | None | 0 0
  1. #!/usr/bin/perl
  2. ####Script de parsing du log de Fail2ban
  3.  
  4. use strict;
  5. use warnings;
  6. use MIME::Lite;
  7.  
  8. ####Met les IP dans un tableau pour les compter et les classer
  9. my %addrs = ( );
  10. my $mail_ban = () ;
  11. my @ban = split( /\n/,  `egrep \$(date +%m"-"+%d) /var/log/fail2ban.log |  grep Ban | cut -d" " -f7` );
  12.  
  13. for (@ban) {
  14.     chomp $_;
  15.     $addrs{$_} += 1;
  16. }
  17. unlink '/home/krapace/script/perl/body_mail\.txt';
  18. my $body = ();
  19. open(   $body , '+>' , "/home/krapace/script/perl/body_mail\.txt" ) or die "Fichier inexistant ou inaccessible '$body' '$!'";
  20. for my $key ( sort {$addrs{$b} <=> $addrs{$a}} keys %addrs ) {
  21.    
  22.      print( $body  $addrs{$key}."\t$key\n" );
  23. }
  24. close($body);
  25. my $mail_corps = `cat /home/krapace/script/perl/body_mail\.txt`;
  26.  $mail_ban = MIME::Lite->new(
  27.              From     => 'expediteur@domain.com',
  28.              To       => 'destinataire@domain.com',
  29.              Subject  => "Objet du mail",
  30.              Data     =>  $mail_corps ,
  31.              );
  32.     $mail_ban->send;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement