Skip to content

Commit

Permalink
Adding no-write flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitcoder committed Jan 31, 2024
1 parent 74f8572 commit 2e883ad
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions hawk_scanner/internals/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import os, cv2
import tarfile

# Create a TinyDB instance for storing previous alert hashes
db = TinyDB('previous_alerts.json')

data_sources = ['s3', 'mysql', 'redis', 'firebase', 'gcs', 'fs', 'postgresql', 'mongodb', 'slack', 'couchdb', 'gdrive', 'gdrive_workspace', 'text']
data_sources_option = ['all'] + data_sources

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

args = parser.parse_args()

# Create a TinyDB instance for storing previous alert hashes
db = None

if not args.no_write:
db = TinyDB('previous_alerts.json')

if args.quiet:
args.shutup = True

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

if suppress_duplicates:
if suppress_duplicates and not args.no_write:
# Calculate the hash of the message
msg_hash = calculate_msg_hash(msg)

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

if suppress_duplicates:
if suppress_duplicates and not args.no_write:
# Store the message hash in the previous alerts database
db.insert({'msg_hash': msg_hash})
except Exception as e:
Expand Down

0 comments on commit 2e883ad

Please sign in to comment.