Guest User

Parsing a logline in a react block

a guest
May 3rd, 2020
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use v6 ;
  2. use IO::TailFile;
  3. my $line ;
  4. my $i = 0;
  5. react {
  6. whenever IO::TailFile.watch("/var/log/asterisk/security", :chomp) -> $line {
  7. if $line ~~ m/ "InvalidPassword" / {
  8. my $lineseq = $line.split(/","/) ;
  9. $lineseq.WHAT ;
  10. my $RAseq = $lineseq[8].split(/"/"/) ;
  11. say "IP to be banned is: \t $RAseq[2]" ;
  12. say "\n \n $line \n That is the original security log line" ;
  13. $i++ ;
  14. if $i > 0 { exit ; }
  15. }
  16. } ;
  17. } ;
  18.  
  19. Outputs
  20. IP to be banned is: 54.36.131.232
  21. # see the RemoteAddress below:
  22.  
  23. [Apr 30 12:47:52] SECURITY[16463] res_security_log.c: SecurityEvent="InvalidPassword",EventTV="2020-04-30T12:47:52.197-0400",Severity="Error",Service="SIP",EventVersion="2",AccountID="0046633915842",SessionID="0x7f644006d7d8",LocalAddress="IPV4/UDP/my-server-ip-addr/5060",RemoteAddress="IPV4/UDP/54.36.131.232/60807",Challenge="7ae8567a",ReceivedChallenge="7ae8567a",ReceivedHash="8a7a2223ae49538447fb4f80037f5e94"
  24. That is the original security log line
RAW Paste Data Copied