Rollup Count of Events


/ Published in: Ruby
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.