mahafyi1

want to write better raku

May 4th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. --------------------------------------------------------------
  2. Contents of data.txt provides a sample line from a syslog file
  3. --------------------------------------------------------------
  4. [May 4 11:48:37] SECURITY[31715] res_security_log.c: SecurityEvent="ChallengeSent",EventTV="2020-05-04T11:48:37.805-0400",Severity="Informational",Service="SIP",EventVersion="1",AccountID="sip:8103@my.ipv4.addr.here",SessionID="0x7fbf5c0070d8",LocalAddress="IPV4/UDP/my.ipv4.addr.here/5060",RemoteAddress="IPV4/UDP/198.46.135.250/63113",Challenge="558e30b4"
  5.  
  6. Raku script to get the line
  7. ___________________________
  8. use v6;
  9. my $line = slurp "data.txt" ;
  10. my $line1 = $line.split(".c:") ;
  11. my $logprefix = $line1[0]~".c" ;
  12. my $line4hash = $line1[1].subst("\"", "", :global) ;
  13. my %linehash = LogPrefix => "$logprefix" ;
  14. my $lineseq = $line4hash.split(",") ;
  15. loop (my $i = 0; $i < 10; $i++) {
  16. say $lineseq[$i] ;
  17. my $mykv = $lineseq[$i].subst(" ", "", :g).split("=") ;
  18. %linehash.push: ($mykv[0] => "$mykv[1]") ;
  19. }
  20. say %linehash.keys ;
  21. say %linehash.values ;
  22.  
  23. ------
  24. Output
  25. ------
  26. SecurityEvent=ChallengeSent
  27. EventTV=2020-05-04T11:48:37.805-0400
  28. Severity=Informational
  29. Service=SIP
  30. EventVersion=1
  31. AccountID=sip:8103@my.ipv4.addr.here
  32. SessionID=0x7fbf5c0070d8
  33. LocalAddress=IPV4/UDP/my.ipv4.addr.here/5060
  34. RemoteAddress=IPV4/UDP/198.46.135.250/63113
  35. Challenge=558e30b4
  36.  
  37. (EventVersion LocalAddress SessionID Severity Challenge LogPrefix RemoteAddress SecurityEvent AccountID EventTV Service)
  38. (1 IPV4/UDP/my.ipv4.addr.here/5060 0x7fbf5c0070d8 Informational 558e30b4
  39. [May 4 11:48:37] SECURITY[31715] res_security_log.c IPV4/UDP/198.46.135.250/63113 ChallengeSent sip:8103@my.ipv4.addr.here 2020-05-04T11:48:37.805-0400 SIP)
Add Comment
Please, Sign In to add comment