Skip to content

Commit

Permalink
#275 improve summary when there is no record in Greynoise report
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Jun 6, 2018
1 parent 3adc775 commit 4ded0d9
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions analyzers/GreyNoise/greynoise.py
Expand Up @@ -111,20 +111,24 @@ def summary(self, raw):
"""

try:
final_level = None
taxonomy_data = defaultdict(int)
for record in raw.get('records', []):
name = record.get('name', 'unknown')
intention = record.get('intention', 'unknown')
taxonomy_data[name] += 1
final_level = self._get_level(final_level, intention)

taxonomies = []
if len(taxonomy_data) > 1: # Multiple tags have been found
taxonomies.append(self.build_taxonomy(final_level, 'GreyNoise', 'entries', len(taxonomy_data)))
else: # There is only one tag found, possibly multiple times
for name, count in taxonomy_data.iteritems():
taxonomies.append(self.build_taxonomy(final_level, 'GreyNoise', name, count))
if raw.get('records'):
final_level = None
taxonomy_data = defaultdict(int)
for record in raw.get('records', []):
name = record.get('name', 'unknown')
intention = record.get('intention', 'unknown')
taxonomy_data[name] += 1
final_level = self._get_level(final_level, intention)

if len(taxonomy_data) > 1: # Multiple tags have been found
taxonomies.append(self.build_taxonomy(final_level, 'GreyNoise', 'entries', len(taxonomy_data)))
else: # There is only one tag found, possibly multiple times
for name, count in taxonomy_data.iteritems():
taxonomies.append(self.build_taxonomy(final_level, 'GreyNoise', name, count))

else:
taxonomies.append(self.build_taxonomy('info', 'GreyNoise', 'Records', 'None'))

return {"taxonomies": taxonomies}

Expand Down

0 comments on commit 4ded0d9

Please sign in to comment.