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

Panoaram get-jobs command #38512

Merged
merged 15 commits into from
Feb 13, 2025
12 changes: 9 additions & 3 deletions Packs/PAN-OS/Integrations/Panorama/Panorama.py
Original file line number Diff line number Diff line change
Expand Up @@ -11166,8 +11166,11 @@ def show_jobs(
result_data = []
for device in topology.all(filter_string=device_filter_str, target=target):
command = UniversalCommand.SHOW_JOBS_ID_PREFIX.format(id) if id else UniversalCommand.SHOW_JOBS_COMMAND
response = run_op_command(device, command)

try:
response = run_op_command(device, command)
except panos.errors.PanDeviceXapiError:
demisto.debug(f'Could not find The given ID {id} in the specific device {device}.')
continue
for job in response.findall("./result/job"):
result_data_obj: ShowJobsAllResultData = dataclass_from_element(device, ShowJobsAllResultData, job)

Expand All @@ -11177,12 +11180,15 @@ def show_jobs(
and (result_data_obj.type == job_type or not job_type)
):
result_data.append(result_data_obj)

break
# The below is very important for XSOAR to de-duplicate the returned key. If there is only one obj
# being returned, return it as a dict instead of a list.
if len(result_data) == 1:
return result_data[0] # type: ignore

if not result_data and id: # in case of an empty list and a specific ID, it means ID not found in all devices
raise DemistoException(f"The given ID {id} is not found in all devices of the topology.")

return result_data


Expand Down
33 changes: 27 additions & 6 deletions Packs/PAN-OS/Integrations/Panorama/Panorama_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests_mock
from pytest_mock import MockerFixture
from requests_mock.mocker import Mocker as RequestsMock

import panos.errors
import demistomock as demisto
from unittest.mock import patch, MagicMock
from panos.device import Vsys
Expand All @@ -13,6 +13,7 @@
from CommonServerPython import DemistoException, CommandResults
from panos.objects import LogForwardingProfile, LogForwardingProfileMatchList
import dateparser

from test_data import fetch_incidents_input
from test_data import mock_rules
from freezegun import freeze_time
Expand Down Expand Up @@ -3310,11 +3311,10 @@ def test_get_jobs(self, patched_run_op_command, mock_topology):

result = UniversalCommand.show_jobs(mock_topology)
# Check all attributes of result data have values
for result_dataclass in result:
for key, value in result_dataclass.__dict__.items():
# Nullable Values
if key not in ["description", "user", "details", "warnings"]:
assert value
for key, value in result.__dict__.items():
# Nullable Values
if key not in ["description", "user", "details", "warnings"]:
assert value

@patch("Panorama.run_op_command")
@patch("Panorama.demisto.debug")
Expand Down Expand Up @@ -8046,3 +8046,24 @@ def test_pan_os_get_master_key_details_command(mocker: MockerFixture, requests_m
assert table_data == raw_response['response']['result']
assert command_results.outputs == raw_response['response']['result']
assert command_results.raw_response == raw_response


@patch("Panorama.run_op_command")
def test_show_jobs_id_not_found(patched_run_op_command):
"""
Given:
- A specific job_id (23)

When:
- running show_jobs function

Then:
- Ensure DemistoException is thrown with ann informative message (since the given ID does not exist in all devices)
"""
from Panorama import UniversalCommand

patched_run_op_command.side_effect = panos.errors.PanDeviceXapiError("job 23 not found")
MockTopology = type('MockTopology', (), {'all': lambda *x, **y: [Panorama(hostname='123')]})

with pytest.raises(DemistoException, match="The given ID 23 is not found in all devices of the topology."):
UniversalCommand.show_jobs(topology=MockTopology(), id=23)
6 changes: 6 additions & 0 deletions Packs/PAN-OS/ReleaseNotes/2_3_4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Palo Alto Networks PAN-OS

- Fixed an issue where ***pan-os-platform-get-jobs*** failed due to searching for job-id on the wrong device instead of the correct one.
2 changes: 1 addition & 1 deletion Packs/PAN-OS/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "PAN-OS by Palo Alto Networks",
"description": "Manage Palo Alto Networks Firewall and Panorama. Use this pack to manage Prisma Access through Panorama. For more information see Panorama documentation.",
"support": "xsoar",
"currentVersion": "2.3.3",
"currentVersion": "2.3.4",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading