Grouping Exceptions

If you paid close attention to the previous sections discussing exception grouping, you may have noticed that exceptions are not grouped based on a group field.

If the exception is not categorized in the configuration file, it would have been grouped based on its MD5 hash value; however in that case the group name and exception ID would have one-to-one mapping anyway, because the group name is generated from the hash value:

if m.hexdigest() in self.exceptions:

self.exceptions[m.hexdigest()] = {

count' log_line' header' body' f_name' desc ' group'

'NOT IDENTIFIED', 'unrecognised_'+m.hexdigest(), }

However, if the exception has been "caught" using one of the filters from the configuration file, it would have been categorized based on the filter MD5 hash value and not the ' group' string:

if f['ll_re'].search(log_l) and f['hl_re'].search(hd_l) and f['bl_re'].search(bd_l): if f['id'] in self.exceptions:

This approach allows you to find out how many times each individual filter has been hit and also group the counters based on the ' group' field. So first of all I need to go through the list of all logged exceptions and create distinct categories. The categories dictionary is only going to store the group name and the total count of exceptions in that group. I also use the option key -v (for verbose) to tell whether or not to print the exception details. Listing 7-14 shows the code.

Listing 7-14. Grouping exception IDs into categories def print_status(self): categories = {} for e in self.exceptions:

if self.exceptions[e]['group'] in categories:

categories[self.exceptions[e]['group']] += self.exceptions[e]['count'] else:

categories[self.exceptions[e]['group']] = self.exceptions[e]['count' ]

if OPTIONS.verbose: print '-' * 80 print "Filter ID print "Exception description print "Exception group print "Exception count print "First file print "First occurrence log line print "Stack trace headline print "Stack trace print self.exceptions[e]['body']

self.exceptions[e] self.exceptions[e] self.exceptions[e] self.exceptions[e] self.exceptions[e] self.exceptions[e]

' desc' ] 'group'] 'count'] 'f_name'] 'log_line'] 'header']

Was this article helpful?

0 0

Post a comment