Skip to content

Commit

Permalink
Merge pull request #153 from PaloAltoNetworks/feature/add-severityto-…
Browse files Browse the repository at this point in the history
…alert-list

add policy severity to alert list command
  • Loading branch information
SimOnPanw committed Nov 23, 2023
2 parents 465dffd + 4e137dc commit 5e052ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions prismacloud/cli/cspm/cmd_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from prismacloud.cli import cli_output, pass_environment
from prismacloud.cli.api import pc_api
from urllib.parse import quote


@click.group(
Expand Down Expand Up @@ -53,10 +54,23 @@ def list_alerts(compliance_standard, cloud_account, account_group, amount, unit,
alerts = pc_api.get_endpoint("alert", query_params=data, api="cspm")

# Try to add a new column with a url to the alert investigate page
url = "https://app.eu.prismacloud.io/investigate/details?resourceId="
base_url = f"https://{pc_api.api.replace('api', 'app')}/alerts/overview?viewId=default"

for alert in alerts:
try:
alert["alert.resource.url"] = f"{url}{alert['resource']['rrn']}"
alert_id = alert['id']
# Correctly using double braces for literal curly braces in f-string
filters = (
f'{{"timeRange":{{"type":"to_now","value":"epoch"}},'
f'"timeRange.type":"ALERT_OPENED","alert.status":["open"],'
f'"alert.id":["{alert_id}"]}}'
)
# Encoding the filters part
encoded_filters = quote(filters)

# Constructing the full URL
alert_url = f'{base_url}&filters={encoded_filters}'
alert["alert.resource.url"] = alert_url
except Exception: # pylint:disable=broad-except
pass

Expand All @@ -69,6 +83,7 @@ def list_alerts(compliance_standard, cloud_account, account_group, amount, unit,
for policy in policies:
if policy["policyId"] == alert["policyId"]:
alert["policy.name"] = policy["name"]
alert["policy.severity"] = policy["severity"]
alert["policy.description"] = policy["description"]
logging.debug("Done iterating through alerts and adding policy information")

Expand Down
2 changes: 1 addition & 1 deletion prismacloud/cli/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.7.7"
version = "0.7.8"

0 comments on commit 5e052ec

Please sign in to comment.