Skip to content

Commit 2e883ad

Browse files
committed
Adding no-write flag
1 parent 74f8572 commit 2e883ad

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

hawk_scanner/internals/system.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
import os, cv2
1414
import tarfile
1515

16-
# Create a TinyDB instance for storing previous alert hashes
17-
db = TinyDB('previous_alerts.json')
18-
1916
data_sources = ['s3', 'mysql', 'redis', 'firebase', 'gcs', 'fs', 'postgresql', 'mongodb', 'slack', 'couchdb', 'gdrive', 'gdrive_workspace', 'text']
2017
data_sources_option = ['all'] + data_sources
2118

@@ -27,10 +24,17 @@
2724
parser.add_argument('--stdout', action='store_true', help='Print output to stdout')
2825
parser.add_argument('--quiet', action='store_true', help='Print only the results')
2926
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
27+
parser.add_argument('--no-write', action='store_true', help='Do not write previous alerts to file, this may flood you with duplicate alerts')
3028
parser.add_argument('--shutup', action='store_true', help='Suppress the Hawk Eye banner 🫣', default=False)
3129

3230
args = parser.parse_args()
3331

32+
# Create a TinyDB instance for storing previous alert hashes
33+
db = None
34+
35+
if not args.no_write:
36+
db = TinyDB('previous_alerts.json')
37+
3438
if args.quiet:
3539
args.shutup = True
3640

@@ -393,7 +397,7 @@ def SlackNotify(msg):
393397
# Check if suppress_duplicates is set to True
394398
suppress_duplicates = notify_config.get('suppress_duplicates', False)
395399

396-
if suppress_duplicates:
400+
if suppress_duplicates and not args.no_write:
397401
# Calculate the hash of the message
398402
msg_hash = calculate_msg_hash(msg)
399403

@@ -413,7 +417,7 @@ def SlackNotify(msg):
413417
headers = {'Content-Type': 'application/json'}
414418
requests.post(webhook_url, data=json.dumps(payload), headers=headers)
415419

416-
if suppress_duplicates:
420+
if suppress_duplicates and not args.no_write:
417421
# Store the message hash in the previous alerts database
418422
db.insert({'msg_hash': msg_hash})
419423
except Exception as e:

0 commit comments

Comments
 (0)