Skip to content

Commit

Permalink
fixed style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmatias committed Aug 13, 2024
1 parent 7dd9d8f commit 2507040
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions webhooks/falco/alerta_falco.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from flask import current_app

from alerta.app import alarm_model
from alerta.models.alert import Alert
from alerta.webhooks import WebhookBase

from alerta.webhooks import WebhookBase

class FalcoWebhook(WebhookBase):
"""
Expand All @@ -17,27 +16,47 @@ def incoming(self, query_string, payload):

# checking fields
#
expected_fields = ['priority', 'hostname', 'rule', 'output_fields', 'source', 'output']
expected_fields = [
'priority',
'hostname',
'rule',
'output_fields',
'source',
'output'
]
for field in expected_fields:
if not field in payload:
if field not in payload:
raise Exception(f'{field} not found in payload')
expected_fields_in_outputfields = ['environment']
for field in expected_fields_in_outputfields:
if not field in payload['output_fields']:
if field not in payload['output_fields']:
raise Exception(f'{field} not found in payload->output_fields')

# resource+event
#
# these are the fields used for de duplication, so we fill their values here
resource=f"{payload['hostname']}"
# these are the fields used for de duplication,
# so we fill their values here
resource = f"{payload['hostname']}"
event = payload['rule']

# priority
#
# falco priorities: emergency, alert, critical, error, warning, notice, informational, debug
if payload['priority'].lower() in ['emergency', 'alert', 'critical', 'error']:
# falco priorities:
# emergency, alert, critical, error, warning, notice,
# informational, debug
if payload['priority'].lower() in [
'emergency',
'alert',
'critical',
'error'
]:
severity = 'critical'
elif payload['priority'].lower() in ['warning', 'notice', 'informational', 'debug']:
elif payload['priority'].lower() in [
'warning',
'notice',
'informational',
'debug'
]:
severity = 'warning'
else:
severity = alarm_model.DEFAULT_NORMAL_SEVERITY
Expand All @@ -56,7 +75,7 @@ def incoming(self, query_string, payload):

# tags
tags = []
if 'tags' in payload and type(payload['tags']) == list:
if 'tags' in payload and isinstance(payload['tags'], list):
tags = additional_tags.extend(payload['tags'])
else:
tags = additional_tags
Expand All @@ -73,7 +92,7 @@ def incoming(self, query_string, payload):
# service
#
# service is a List
service = [ payload['source'] ]
service = [payload['source']]

# origin
#
Expand Down

0 comments on commit 2507040

Please sign in to comment.