Posted By

beaknit on 02/26/11


Tagged

ruby logs


Versions (?)

Rollup Count of Events


 / Published in: Ruby
 

Digs through the exim log and gives a count for every email address that's generating SMTP errors

  1. if ARGV[0] == nil then
  2. puts "SYNTAX: smtp_errors.rb <logfile>"
  3. exit
  4. end
  5.  
  6. log = ARGV[0]
  7.  
  8. offenders = Hash.new(0)
  9.  
  10. File.open(log,"r").each do |line|
  11. if line =~ /SMTP error/ then
  12. addy = line.split(/ /)[4]
  13. offenders[addy] += 1
  14. end
  15. end
  16.  
  17. offenders.each_pair {|o,k|
  18. puts sprintf("%-50s %d", o, k)
  19. }

Report this snippet  

You need to login to post a comment.