Skip to content

Commit 3e252af

Browse files
content-botBigEasyJjohnnywilkesShirleyDenkberg
authored
[ASM] - UVEM-790 - RankServiceOwners Update (#38091) (#38164)
* Update RankSO Script and Release Notes * Update alertsource to ownerrelatedfield * Refactor output logic to write_output_to_context_key function * Refactor variables and update ReadMe * add error for wrong tenant * predefined/stringify * Apply suggestions from code review * changed wording --------- Co-authored-by: John <[email protected]> Co-authored-by: johnnywilkes <[email protected]> Co-authored-by: jwilkes <[email protected]> Co-authored-by: ShirleyDenkberg <[email protected]>
1 parent 3dfa91f commit 3e252af

File tree

5 files changed

+53
-25
lines changed

5 files changed

+53
-25
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#### Scripts
2+
3+
##### RankServiceOwners
4+
5+
Updated the script to accept an argument that determines the outputs depending on the source that generated an alert or issue.

Packs/CortexAttackSurfaceManagement/Scripts/RankServiceOwners/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Recommend most likely service owners from those surfaced by Cortex ASM Enrichmen
1717
| --- | --- |
1818
| owners | List of potential service owners |
1919
| asmsystemids | System IDs or names associated with the compute instance |
20+
| owners | List of potential service owners. |
21+
| ownerrelatedfield | The field of the alert or issue that owners should be stored. |
22+
| tenantcommand | False will use !setAlert, True will use !setIssue. |
2023

2124
## Outputs
2225

Packs/CortexAttackSurfaceManagement/Scripts/RankServiceOwners/RankServiceOwners.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1+
from collections.abc import Iterable, Callable
2+
from typing import Any
3+
import google.cloud.storage
4+
import numpy as np
5+
import posixpath
6+
import dill as pickle
7+
import os
8+
import itertools
9+
import string
10+
import re
11+
import math
12+
from itertools import groupby
13+
import traceback
114
import demistomock as demisto # noqa: F401
215
from CommonServerPython import * # noqa: F401
16+
demisto.debug('pack name = Cortex Attack Surface Management, pack version = 1.7.65')
17+
18+
319
"""Script for identifying and recommending the most likely owners of a discovered service
420
from those surfaced by Cortex ASM Enrichment.
521
"""
622

7-
import traceback
8-
from itertools import groupby
9-
import math
10-
11-
import re
12-
import string
13-
import itertools
14-
import os
15-
import dill as pickle
16-
import posixpath
17-
import numpy as np
18-
import google.cloud.storage
19-
20-
21-
from typing import Any
22-
from collections.abc import Iterable, Callable
23-
2423

2524
STRING_DELIMITER = ' | ' # delimiter used for joining source fields and any additional fields of type string
2625

@@ -614,24 +613,34 @@ def featurize(self, service_identifiers: Iterable[str], owners: list[dict[str, A
614613
return X
615614

616615

616+
def write_output_to_context_key(final_owners: list[dict[str, str]], owner_related_field: str, platform_tenant: str):
617+
stringify_platform_tenant = str(platform_tenant)
618+
set_alert_issue_map = {"True": "setIssue", "False": "setAlert"}
619+
if final_owners and owner_related_field:
620+
res = demisto.executeCommand(set_alert_issue_map[stringify_platform_tenant], {owner_related_field: final_owners})
621+
if isError(res):
622+
raise ValueError('Unable to update field')
623+
return_results(CommandResults(readable_output=f"Owners ranked and written to {owner_related_field}"))
624+
else:
625+
return_results(CommandResults(readable_output='No owners found'))
626+
627+
617628
def main():
618629
try:
619630
# parse inputs
620631
unranked = demisto.args().get("owners", [])
621632
if isinstance(unranked, dict):
622633
unranked = [unranked]
623634
asm_system_ids = demisto.args().get("asmsystemids", [])
624-
635+
owner_related_field = demisto.args().get("ownerrelatedfield", "asmserviceowner")
636+
platform_tenant_usage = demisto.args().get("tenantcommand", "False")
625637
# deduplicate/normalize, score, and rank owners
626638
normalized = aggregate(canonicalize(unranked))
627639
final_owners = justify(rank(score(owners=normalized, asm_system_ids=asm_system_ids)))
628640

629-
# write output to context
630-
if final_owners:
631-
demisto.executeCommand("setAlert", {"asmserviceowner": final_owners})
632-
return_results(CommandResults(readable_output='Service owners ranked and written to asmserviceowner'))
633-
else:
634-
return_results(CommandResults(readable_output='No service owners found'))
641+
write_output_to_context_key(final_owners=final_owners,
642+
owner_related_field=owner_related_field,
643+
platform_tenant=platform_tenant_usage)
635644

636645
except Exception as ex:
637646
demisto.error(traceback.format_exc()) # print the traceback

Packs/CortexAttackSurfaceManagement/Scripts/RankServiceOwners/RankServiceOwners.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ args:
55
- description: System IDs or names associated with the compute instance.
66
isArray: true
77
name: asmsystemids
8+
- defaultValue: asmserviceowner
9+
description: The field of the alert or issue in which the owners should be stored.
10+
name: ownerrelatedfield
11+
- defaultValue: "False"
12+
description: False will use !setAlert, True will use !setIssue.
13+
name: tenantcommand
14+
auto: PREDEFINED
15+
predefined:
16+
- "True"
17+
- "False"
818
comment: Recommend most likely service owners from those surfaced by Cortex ASM Enrichment.
919
commonfields:
1020
id: RankServiceOwners
@@ -22,3 +32,4 @@ fromversion: 6.5.0
2232
tests:
2333
- No tests (auto formatted)
2434
runonce: false
35+
engineinfo: {}

Packs/CortexAttackSurfaceManagement/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Cortex Attack Surface Management",
33
"description": "Content for working with Attack Surface Management (ASM).",
44
"support": "xsoar",
5-
"currentVersion": "1.7.64",
5+
"currentVersion": "1.7.65",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)