Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown option added in graph security connector #1489

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stix_shifter_modules/azure_sentinel/configuration/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"alertV2": {
"type": "boolean",
"default": false
},
"alert_resources": {
"type": "dropdown",
"default": "alerts",
"options": ["alerts", "alerts_v2" ]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
"alertV2": {
"label": "Alert",
"description": "Latest Generation of alerts in the Microsoft Graph security API"
},
"alert_resources": {
"label": "Alert resources",
"optionLabels": {
"alerts": "Legacy alert",
"alerts_v2": "Alert V2"
},
"description": "Select an alert resource version for the Microsoft Graph security API"
}
}
},
Expand Down
32 changes: 23 additions & 9 deletions stix_shifter_modules/azure_sentinel/stix_transmission/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Connector(BaseJsonSyncConnector):
api_client = None
max_limit = 1000
DEFAULT_API_VERSION = 'v1.0'
LEGACY_ALERT = 'security/alerts'
ALERT_V2 = 'security/alerts_v2'
LEGACY_ALERT = 'alerts'
ALERT_V2 = 'alerts_v2'

def __init__(self, connection, configuration):
"""Initialization.
Expand All @@ -23,17 +23,31 @@ def __init__(self, connection, configuration):
self.configuration = configuration
self.api_client = APIClient(self.connection, self.configuration)

self.legacy_alert = connection['options'].get('alert')
self.alert_v2 = connection['options'].get('alertV2')

if self.legacy_alert:
# self.legacy_alert = connection['options'].get('alert')
# self.alert_v2 = connection['options'].get('alertV2')
self.alert_resource = connection['options'].get('alert_resources')

if self.alert_resource == self.LEGACY_ALERT:
self.query_alert_type = 'alert'
self.endpoint = '{api_version}/{api_resource}'.format(api_version=self.DEFAULT_API_VERSION, api_resource=self.LEGACY_ALERT)
elif self.alert_v2:
self.endpoint = '{api_version}/security/{api_resource}'.format(api_version=self.DEFAULT_API_VERSION, api_resource=self.LEGACY_ALERT)
elif self.alert_resource == self.ALERT_V2:
self.query_alert_type = 'alertV2'
self.endpoint = '{api_version}/{api_resource}'.format(api_version=self.DEFAULT_API_VERSION, api_resource=self.ALERT_V2)
self.endpoint = '{api_version}/security/{api_resource}'.format(api_version=self.DEFAULT_API_VERSION, api_resource=self.ALERT_V2)
else:
raise Exception('Invalid alert resource type. At least one alert type must be selected.')

#remove below block before creating PR
# if self.legacy_alert:
# self.query_alert_type = 'alert'
# self.endpoint = '{api_version}/{api_resource}'.format(api_version=self.DEFAULT_API_VERSION, api_resource=self.LEGACY_ALERT)
# elif self.alert_v2:
# self.query_alert_type = 'alertV2'
# self.endpoint = '{api_version}/{api_resource}'.format(api_version=self.DEFAULT_API_VERSION, api_resource=self.ALERT_V2)
# else:
# raise Exception('Invalid alert resource type. At least one alert type must be selected.')


self.logger.warning('Alert Resource selected::: {}'.format(self.alert_resource))

async def ping_connection(self):
"""Ping the endpoint."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def connection(self):
return {
"port": 443,
"options": {
"alert": True
"alert_resources": "alerts"
}
}

Expand Down