Skip to content

Commit 521dd50

Browse files
sapirshukerwolyslager
authored andcommitted
XSUP-27717/FortiSIEM (demisto#29458)
* add tests * add RN,fix,logs * Update 2_0_21.md * add period * add a name to incident * fixes CR * update docker image * delete logs * CR fixes * Update 2_0_21.md * Update FortiSIEMV2.py
1 parent cc34e3d commit 521dd50

File tree

6 files changed

+113
-5
lines changed

6 files changed

+113
-5
lines changed

Packs/FortiSIEM/Integrations/FortiSIEMV2/FortiSIEMV2.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def fetch_incidents_request(self, status: List[int], time_from: int, time_to: in
177177
"""
178178
data = {"descending": False, "filters": {"status": status},
179179
"orderBy": "incidentFirstSeen", "size": size, "start": start, "timeFrom": time_from, "timeTo": time_to}
180+
demisto.debug(f'Fetch incident request: {str(data)}')
180181
response = self._http_request('POST', 'pub/incident', json_data=data)
181182
return response
182183

@@ -1014,6 +1015,21 @@ def watchlist_entry_delete_command(client: FortiSIEMClient, args: dict[str, Any]
10141015
return command_results_list
10151016

10161017

1018+
def get_incident_name(incident: dict) -> str:
1019+
"""
1020+
Gets the incident name.
1021+
Args:
1022+
incident (dict): FortiSIEM incident.
1023+
Returns:
1024+
str: The incident name.
1025+
"""
1026+
if incident_title := incident.get('incidentTitle'):
1027+
return incident_title
1028+
elif incident_id := incident.get('incidentId'):
1029+
return f"FortiSIEM incident: {incident_id}"
1030+
return "FortiSIEM incident"
1031+
1032+
10171033
def fetch_incidents(client: FortiSIEMClient, max_fetch: int, first_fetch: str, status_list: List[str],
10181034
fetch_with_events: bool, max_events_fetch: int, last_run: dict[str, Any]) -> tuple:
10191035
"""
@@ -1047,12 +1063,14 @@ def fetch_incidents(client: FortiSIEMClient, max_fetch: int, first_fetch: str, s
10471063
else:
10481064
events = []
10491065
incident['events'] = events
1066+
10501067
incidents.append({
1051-
'name': incident['incidentTitle'],
1068+
'name': get_incident_name(incident),
10521069
'occurred': timestamp_to_datestring(incident['incidentFirstSeen']),
10531070
'rawJSON': json.dumps(incident)})
10541071
if incidents:
10551072
last_run = update_last_run_obj(last_run, formatted_incidents)
1073+
demisto.debug(f'Update last run to: {str(last_run)}.')
10561074
return incidents, last_run
10571075

10581076

@@ -1528,6 +1546,7 @@ def fetch_relevant_incidents(client: FortiSIEMClient,
15281546
Returns:
15291547
List[dict]: Relevant incidents.
15301548
"""
1549+
demisto.debug(f'Fetch incident from: {str(time_from)} to {str(time_to)}')
15311550
filtered_incidents = []
15321551
start_index = last_run.get('start_index') or 0
15331552
last_incident_create_time = last_run.get('create_time') or time_from
@@ -1537,7 +1556,7 @@ def fetch_relevant_incidents(client: FortiSIEMClient,
15371556
response = client.fetch_incidents_request(status, time_from, time_to, page_size, start_index)
15381557
incidents = response.get('data')
15391558
total = response.get('total')
1540-
1559+
demisto.debug(f'Got: {total} total incidents.')
15411560
# filtering & pagination
15421561
while len(filtered_incidents) < max_fetch and start_index < total:
15431562
for incident in incidents:
@@ -1551,6 +1570,7 @@ def fetch_relevant_incidents(client: FortiSIEMClient,
15511570
start_index += page_size
15521571
response = client.fetch_incidents_request(status, time_from, time_to, page_size, start_index)
15531572
incidents = response.get('data')
1573+
demisto.debug(f'Got: {len(filtered_incidents)} incidents after filtering.')
15541574
return filtered_incidents
15551575

15561576

Packs/FortiSIEM/Integrations/FortiSIEMV2/FortiSIEMV2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ script:
129129
name: user
130130
- description: Destination MAC address. Filtering argument.
131131
name: destMACAddr
132-
- description: Source MAC address
132+
- description: Source MAC address.
133133
name: srcMACAddr
134134
description: Initiate search process on events. The events are retrieved according to a constraint determined either by the query argument or by the filtering arguments. When using filtering arguments, an 'AND' operator is used between them. If the query argument is filled, it overrides the values in the filtering arguments.
135135
polling: true
@@ -701,7 +701,7 @@ script:
701701
- contextPath: FortiSIEM.WatchlistEntry.ageOut
702702
description: Expiration date of the entry.
703703
type: String
704-
dockerimage: demisto/python3:3.10.13.72123
704+
dockerimage: demisto/python3:3.10.13.73190
705705
isfetch: true
706706
runonce: false
707707
script: '-'

Packs/FortiSIEM/Integrations/FortiSIEMV2/FortiSIEMV2_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,54 @@ def test_get_related_events_for_fetch_command(events_mock_response, expected_res
700700
requests_mock.get(f'{client._base_url}pub/incident/triggeringEvents', json=events_mock_response)
701701

702702
assert len(get_related_events_for_fetch_command('123456', 20, client)) == expected_result
703+
704+
705+
@pytest.mark.commands
706+
@freeze_time(time.ctime(1646205070))
707+
def test_fetch_incidents_without_incident_title(requests_mock):
708+
"""
709+
Fetching incidents.
710+
Given:
711+
- 'fetch-incidents' arguments.
712+
Scenarios:
713+
- Last run do not exist.
714+
- Last run exists
715+
- No incidents to fetch.
716+
- Incidents to fetch with events.
717+
- New incidents came in the same time like prev last incidents.
718+
Then:
719+
- Validate incidents & updated last run obj.
720+
"""
721+
722+
incidents_file = "fetch_incidents_without_incidentTitle.json"
723+
expected_output = {
724+
'incidents_number': 1,
725+
'events_number': 0,
726+
'last_run': {
727+
'create_time': 1646092830000,
728+
'last_incidents': [1],
729+
'start_index': 0
730+
}
731+
}
732+
from FortiSIEMV2 import FortiSIEMClient, fetch_incidents
733+
client: FortiSIEMClient = mock_client()
734+
status_list = ['Active']
735+
max_fetch = 1
736+
max_events_fetch = 5
737+
first_fetch = "1 week"
738+
739+
mock_response = load_json_mock_response(incidents_file)
740+
requests_mock.post(f'{client._base_url}pub/incident', json=mock_response)
741+
incidents, updated_last_run = fetch_incidents(client, max_fetch, first_fetch, status_list, False,
742+
max_events_fetch, {})
743+
744+
expected_incidents_number = expected_output.get('incidents_number')
745+
expected_events_number = expected_output.get('events_number')
746+
expected_last_run = expected_output.get('last_run')
747+
incident_raw_json = json.loads(incidents[0]['rawJSON']) if incidents else {}
748+
events = incident_raw_json.get('events')
749+
events_number = len(events) if events else 0
750+
assert len(incidents) == expected_incidents_number
751+
assert updated_last_run == expected_last_run
752+
assert incidents[0].get("name") == 'FortiSIEM incident: 1'
753+
assert events_number == expected_events_number
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"total": 1,
3+
"size": 1,
4+
"data": [
5+
{
6+
"eventSeverity": 7,
7+
"incidentFirstSeen": 1646092830000,
8+
"incidentReso": 1,
9+
"incidentRptIp": "incidentRptIp",
10+
"incidentLastSeen": 1646147610000,
11+
"incidentSrc": "incidentSrc",
12+
"count": 40322,
13+
"attackTechnique": "attackTechnique",
14+
"eventType": "PH_RULE_EXCESS_DNS_QUERY",
15+
"phIncidentCategory": 4,
16+
"incidentClearedTime": 0,
17+
"incidentTarget": "",
18+
"attackTactic": "attackTactic",
19+
"phSubIncidentCategory": "phSubIncidentCategory",
20+
"eventSeverityCat": "MEDIUM",
21+
"incidentDetail": "incidentDetail",
22+
"incidentRptDevName": "incidentRptDevName",
23+
"eventName": "eventName",
24+
"incidentId": 1,
25+
"incidentStatus": 0,
26+
"customer": "Super"
27+
}
28+
],
29+
"start": 0
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#### Integrations
3+
4+
##### FortiSIEM v2
5+
6+
- Fixed an issue where the ***fetch-incidents*** command failed when fetching an incident without a title.
7+
- Updated the Docker image to: *demisto/python3:3.10.13.73190*.

Packs/FortiSIEM/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "FortiSIEM",
33
"description": "Search and update events of FortiSIEM and manage resource lists.",
44
"support": "xsoar",
5-
"currentVersion": "2.0.20",
5+
"currentVersion": "2.0.21",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)