From 4ded0d93932cb86110af7a8f6f8301c9680a2d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leonard?= Date: Wed, 6 Jun 2018 20:27:18 +0200 Subject: [PATCH] #275 improve summary when there is no record in Greynoise report --- analyzers/GreyNoise/greynoise.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/analyzers/GreyNoise/greynoise.py b/analyzers/GreyNoise/greynoise.py index 6636685c4..cf9e52b1e 100755 --- a/analyzers/GreyNoise/greynoise.py +++ b/analyzers/GreyNoise/greynoise.py @@ -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}