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

[CIAC-6413][PANOS] Add CRUD commands for security profile groups #33064

Merged
merged 39 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8191cf0
panos add CRUD for security profile groups
yaakovpraisler Feb 21, 2024
af87597
pre-commit
yaakovpraisler Feb 21, 2024
08733ec
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Feb 21, 2024
84cd3dd
bump version
yaakovpraisler Feb 22, 2024
d420a26
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Feb 22, 2024
6aca94f
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Feb 22, 2024
121b0f8
test pb
yaakovpraisler Feb 26, 2024
12fbaf8
Merge branch 'panos-CIAC-6413' of github.com:demisto/content into pan…
yaakovpraisler Feb 26, 2024
ce79dde
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Feb 26, 2024
16f1970
bump version
yaakovpraisler Feb 26, 2024
c7cf4cb
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Feb 28, 2024
8ba8e16
Update Packs/PAN-OS/Integrations/Panorama/Panorama.py
yaakovpraisler Feb 29, 2024
c448c4b
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Feb 29, 2024
1b230a1
cr
yaakovpraisler Feb 29, 2024
94fb358
Update Packs/PAN-OS/Integrations/Panorama/Panorama.yml
yaakovpraisler Mar 4, 2024
27afd00
Update Packs/PAN-OS/Integrations/Panorama/Panorama.yml
yaakovpraisler Mar 4, 2024
c28c850
Update Packs/PAN-OS/Integrations/Panorama/README.md
yaakovpraisler Mar 4, 2024
68f74db
Update Packs/PAN-OS/Integrations/Panorama/README.md
yaakovpraisler Mar 4, 2024
34583b9
Update Packs/PAN-OS/ReleaseNotes/2_1_23.md
yaakovpraisler Mar 4, 2024
42ccd22
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 4, 2024
ca6bb7e
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 5, 2024
732526f
updated edit command
yaakovpraisler Mar 6, 2024
31e0920
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 6, 2024
784d37e
fix tests
yaakovpraisler Mar 6, 2024
2421abf
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 6, 2024
afc6a92
CR
yaakovpraisler Mar 6, 2024
dd0b470
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 6, 2024
43b9995
update docker
yaakovpraisler Mar 6, 2024
fa3c4f6
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 7, 2024
73d2c12
increas tpb timeout
yaakovpraisler Mar 7, 2024
03530f3
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 7, 2024
04136d9
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 10, 2024
5371ba3
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 12, 2024
67bf6b0
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 12, 2024
67e43bb
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 12, 2024
e18c0ad
Merge branch 'master' into panos-CIAC-6413
yaakovpraisler Mar 13, 2024
bcfe354
Update conf.json
yaakovpraisler Mar 13, 2024
a3df521
conf
yaakovpraisler Mar 13, 2024
96887e9
Update conf.json
yaakovpraisler Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
186 changes: 186 additions & 0 deletions Packs/PAN-OS/Integrations/Panorama/Panorama.py
Original file line number Diff line number Diff line change
Expand Up @@ -13660,6 +13660,184 @@ def pan_os_delete_tag_command(args: dict) -> CommandResults:
)


def prettify_security_profile_groups(sp_groups_list: list) -> list:
"""Prettify the keys in the security profile groups for the HR table.

Args:
sp_groups_list (list): The security profile groups list

Returns:
list: List of prettified security profile groups.
"""

profile_to_change_map = {
"virus": "Antivirus Profile",
"spyware": "Anti-Spyware Profile",
"vulnerability": "Vulnerability Protection Profile",
"url-filtering": "URL Filtering Profile",
"file-blocking": "File Blocking Profile",
"data-filtering": "Data Filtering Profile",
"wildfire-analysis": "WildFire Analysis Profile",
}

prettified_sp_groups_list = []
for sp_group in sp_groups_list:

prettified_sp_group = {"Name": sp_group["name"], "Location": sp_group["location"]}
for key in sp_group:

if key not in ("name", "location"):
sp_group[key] = extract_objects_info_by_key(sp_group, key)
prettified_sp_group[profile_to_change_map.get(key, key)] = sp_group[key]

prettified_sp_groups_list.append(prettified_sp_group)

return prettified_sp_groups_list


def pan_os_list_security_profile_group_command(args: dict) -> CommandResults:
"""
Returns a list of security profile groups.

Args:
args (dict): The command arguments.

Returns:
CommandResults: The command results with raw response, outputs and readable outputs.
"""
xpath = f"{XPATH_RULEBASE}profile-group/entry"
if group_name := args.get("group_name"):
xpath += f"[@name='{group_name}']"

params = {
"type": "config",
"action": "get",
"key": API_KEY,
"xpath": xpath
}
raw_response = http_request(URL, 'GET', params=params)
sp_groups_response_list = raw_response.get("response", {}).get("result", {}).get("entry") or []
if not isinstance(sp_groups_response_list, list):
sp_groups_response_list = [sp_groups_response_list]

for sp_group in sp_groups_response_list:
parse_pan_os_un_committed_data(sp_group, ['@admin', '@dirtyId', '@time'])
sp_group["name"] = sp_group.pop("@name", "")
sp_group["location"] = sp_group.pop("@loc", "")

prettified_sp_groups_list = prettify_security_profile_groups(sp_groups_response_list)

return CommandResults(
raw_response=raw_response,
outputs=sp_groups_response_list,
readable_output=tableToMarkdown(
f'Security Profile Groups:',
prettified_sp_groups_list,
["Name", "Location", "Antivirus Profile", "Anti-Spyware Profile", "Vulnerability Protection Profile",
"URL Filtering Profile", "File Blocking Profile", "Data Filtering Profile", "WildFire Analysis Profile"],
),
outputs_prefix='Panorama.ProfileGroup',
outputs_key_field='name'
)


def pan_os_create_security_profile_group_command(args: dict) -> CommandResults:
"""
Creates a security profile groups in the given Panorama instance.

Args:
args (dict): The command arguments.

Returns:
CommandResults: The command results with raw response and readable outputs.
"""
group_name = args.get('group_name')
params = {
"type": "config",
"action": "set",
"key": API_KEY,
"xpath": f"{XPATH_RULEBASE}profile-group/entry[@name='{group_name}']",
"element": (add_argument(args.get("antivirus_profile"), "virus", True)
+ add_argument(args.get("anti_spyware_profile"), "spyware", True)
+ add_argument(args.get("vulnerability_protection_profile"), "vulnerability", True)
+ add_argument(args.get("URL_filtering_profile"), "url-filtering", True)
+ add_argument(args.get("file_blocking_profile"), "file-blocking", True)
+ add_argument(args.get("data_filtering_profile"), "data-filtering", True)
+ add_argument(args.get("wildfire_analysis_profile"), "wildfire-analysis", True))
}

raw_response = http_request(URL, "GET", params=params)
return CommandResults(
raw_response=raw_response,
readable_output=f'Successfully created Security Profile Group: "{group_name}"',
)


def pan_os_edit_security_profile_group_command(args: dict) -> CommandResults:
"""
Edits a given security profile groups in the given Panorama instance.

Args:
args (dict): The command arguments.

Returns:
CommandResults: The command results with raw response and readable outputs.
"""
group_name = args.get("group_name")
profile_to_change = args.get("profile_to_change", "")
profile_value = args.get("profile_value")

profile_to_change_map = {
"Antivirus Profile": "virus",
"Anti-Spyware Profile": "spyware",
"Vulnerability Protection Profile": "vulnerability",
"URL Filtering Profile": "url-filtering",
"File Blocking Profile": "file-blocking",
"Data Filtering Profile": "data-filtering",
"WildFire Analysis Profile": "wildfire-analysis",
}

params = {
"type": "config",
"action": "edit",
"key": API_KEY,
"xpath": f"{XPATH_RULEBASE}profile-group/entry[@name='{group_name}']/{profile_to_change_map.get(profile_to_change)}",
"element": add_argument(profile_value, profile_to_change_map.get(profile_to_change), True) # type: ignore
}

raw_response = http_request(URL, "GET", params=params)
return CommandResults(
raw_response=raw_response,
readable_output=f'Successfully edited Security Profile Group: "{group_name}"',
)


def pan_os_delete_security_profile_group_command(args: dict) -> CommandResults:
"""
Deletes a given security profile groups in the given Panorama instance.

Args:
args (dict): The command arguments.

Returns:
CommandResults: The command results with raw response and readable outputs.
"""
group_name = args.get("group_name")

params = {
"type": "config",
"action": "delete",
"key": API_KEY,
"xpath": f"{XPATH_RULEBASE}profile-group/entry[@name='{group_name}']",
}

raw_response = http_request(URL, "GET", params=params)
return CommandResults(
raw_response=raw_response,
readable_output=f'Successfully deleted Security Profile Group: "{group_name}"',
)


""" Fetch Incidents """


Expand Down Expand Up @@ -14805,6 +14983,14 @@ def main(): # pragma: no cover
return_results(list_device_groups_names())
elif command == 'pan-os-export-tech-support-file':
return_results(export_tsf_command(args))
elif command == 'pan-os-list-security-profile-group':
return_results(pan_os_list_security_profile_group_command(args))
elif command == 'pan-os-create-security-profile-group':
return_results(pan_os_create_security_profile_group_command(args))
elif command == 'pan-os-edit-security-profile-group':
return_results(pan_os_edit_security_profile_group_command(args))
elif command == 'pan-os-delete-security-profile-group':
return_results(pan_os_delete_security_profile_group_command(args))
else:
raise NotImplementedError(f'Command {command} is not implemented.')
except Exception as err:
Expand Down
91 changes: 91 additions & 0 deletions Packs/PAN-OS/Integrations/Panorama/Panorama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9364,6 +9364,97 @@ script:
description: The job ID to use when polling.
description: Exports a tech support file (TSF).
polling: true
- arguments:
- description: A given group name to return the data for.
name: group_name
- description: The device group that the security profile groups are part of.
name: device-group
description: Returns a list of security profile groups from Panorama.
name: pan-os-list-security-profile-group
outputs:
- contextPath: Panorama.ProfileGroup.name
description: The name of the group.
type: String
- contextPath: Panorama.ProfileGroup.location
description: The security profile group's device group location.
type: String
- contextPath: Panorama.ProfileGroup.virus
description: The antivirus profile.
type: String
- contextPath: Panorama.ProfileGroup.spyware
description: The anti-spyware profile.
type: String
- contextPath: Panorama.ProfileGroup.vulnerability
description: The vulnerability protection profile.
type: String
- contextPath: Panorama.ProfileGroup.url-filtering
description: The URL filtering profile.
type: String
- contextPath: Panorama.ProfileGroup.file-blocking
description: The file blocking profile.
type: String
- contextPath: Panorama.ProfileGroup.data-filtering
description: The data filtering profile.
type: String
- contextPath: Panorama.ProfileGroup.wildfire-analysis
description: The wildFire analysis profile.
yaakovpraisler marked this conversation as resolved.
Show resolved Hide resolved
type: String
- contextPath: Panorama.ProfileGroup.disable-override
description: Whether overriding the security profile group is disabled.
type: String
- arguments:
- description: The name of the security profile group.
name: group_name
required: true
- description: The device group that the security profile group will be part of.
name: device-group
- description: The antivirus profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: antivirus_profile
- description: The anti-spyware profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: anti_spyware_profile
- description: The vulnerability protection profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: vulnerability_protection_profile
- description: The URL filtering profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: URL_filtering_profile
- description: The file blocking profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: file_blocking_profile
- description: The data filtering profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: data_filtering_profile
- description: The wildfire analysis profile of the group. You can get the possible values for this argument by running the pan-os-get-security-profile command.
yaakovpraisler marked this conversation as resolved.
Show resolved Hide resolved
name: wildfire_analysis_profile
description: Creates a new security profile group in Panorama.
name: pan-os-create-security-profile-group
- arguments:
- description: The name of the security profile group to edit.
name: group_name
required: true
- description: The profile to edit in the group.
name: profile_to_change
auto: PREDEFINED
predefined:
- 'Antivirus Profile'
- 'Anti-Spyware Profile'
- 'Vulnerability Protection Profile'
- 'URL Filtering Profile'
- 'File Blocking Profile'
- 'Data Filtering Profile'
- 'WildFire Analysis Profile'
required: true
- description: The value to set in the profile. You can get the possible values for this argument by running the pan-os-get-security-profile command.
name: profile_value
required: true
- description: The device group that the security profile group is part of.
name: device-group
description: Edits the security profile group in Panorama.
name: pan-os-edit-security-profile-group
- arguments:
- description: The name of the security profile group to delete.
name: group_name
required: true
- description: The device group that the security profile group is part of.
name: device-group
description: Deletes a security profile group from Panorama.
name: pan-os-delete-security-profile-group
dockerimage: demisto/pan-os-python:1.0.0.87401
isfetch: true
runonce: false
Expand Down