Skip to content

Commit

Permalink
[Marketplace Contribution] ServiceNow - Content Pack Update (#36873)
Browse files Browse the repository at this point in the history
* [Marketplace Contribution] ServiceNow - Content Pack Update (#36679)

* "contribution update to pack 'ServiceNow'"

* add tests

* add tests

* add tests

* add tests

* add tests

* Update ServiceNowv2.py

* fix

* fix

* fix

* fix

* fix

* fix

---------

Co-authored-by: Tal <[email protected]>
Co-authored-by: nprenga <[email protected]>

* fix rn

* fix rn

* fix rn

* Bump pack from version ServiceNow to 2.6.11.

* fix

* Update Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py

Co-authored-by: Shelly Tzohar <[email protected]>

* Update Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.yml

Co-authored-by: Shelly Tzohar <[email protected]>

* fixes from shellys cr

* remove file

* remove file

* Update ServiceNowv2.py

* docker

* docker

* docker

* rn

---------

Co-authored-by: xsoar-bot <[email protected]>
Co-authored-by: Tal <[email protected]>
Co-authored-by: nprenga <[email protected]>
Co-authored-by: Content Bot <[email protected]>
Co-authored-by: Tal Carmeli <[email protected]>
Co-authored-by: Shelly Tzohar <[email protected]>
  • Loading branch information
7 people authored Nov 3, 2024
1 parent 0018a11 commit d4a4ef9
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
22 changes: 22 additions & 0 deletions Packs/ServiceNow/Integrations/ServiceNowv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2537,6 +2537,28 @@ Generic call to ServiceNow api

>Request for GET method is successful
### servicenow-get-ticket-attachments

***
Retrieve file attachments from tickets.

#### Base Command

`servicenow-get-ticket-attachments`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| sys_id | sys_id of the ticket containing the file. | Required |

#### Context Output

There is no context output for this command.

#### Human Readable Output

>Successfully retrieved attachments for ticket with sys id 111
### Troubleshooting
The following are tips for handling issues with mirroring incidents between ServiceNow and Cortex XSOAR.
Expand Down
20 changes: 20 additions & 0 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,24 @@ def delete_attachment_command(client: Client, args: dict) -> tuple[str, dict, di
raise DemistoException("Error: No record found. Record doesn't exist or ACL restricts the record retrieval.")


def get_attachment_command(client: Client, args: dict) -> list | CommandResults:
"""Retreives attachment from a ticket.
Args:
client: Client object with request.
args: Usually demisto.args()
Returns:
Command results and file results.
"""
sys_id = str(args.get('sys_id', ''))

result = client.get_ticket_attachment_entries(sys_id)
if result:
return [CommandResults(readable_output=f'Successfully retrieved attachments for ticket with sys id {sys_id}.'), result]
return CommandResults(readable_output=f'Ticket with sys id {sys_id} has no attachments to retrieve.')


def add_tag_command(client: Client, args: dict) -> tuple[str, dict, dict, bool]:
"""Add tag to a ticket.
Expand Down Expand Up @@ -3339,6 +3357,8 @@ def main():
return_results(get_tasks_for_co_command(client, demisto.args()))
elif demisto.command() == 'servicenow-get-ticket-notes':
return_results(get_ticket_notes_command(client, args, params))
elif demisto.command() == 'servicenow-get-ticket-attachments':
return_results(get_attachment_command(client, args))
elif command in commands:
md_, ec_, raw_response, ignore_auto_extract = commands[command](client, args)
return_outputs(md_, ec_, raw_response, ignore_auto_extract=ignore_auto_extract)
Expand Down
8 changes: 7 additions & 1 deletion Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,13 @@ script:
- contextPath: ServiceNow.Generic.Response
description: Generic response to servicenow api.
type: string
dockerimage: demisto/python3:3.11.9.103066
- arguments:
- description: sys_id of the ticket containing the attachment.
name: sys_id
required: true
description: Retrieves attachments from a ticket.
name: servicenow-get-ticket-attachments
dockerimage: demisto/python3:3.11.10.113941
isfetch: true
ismappable: true
isremotesyncin: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ the look back to a number that is greater than the previous value, then in the i
If the integration was already set with look back > 0, and the look-back is not being increased at any point of time, then those incident duplications would not occur.

---
[View Integration Documentation](https://xsoar.pan.dev/docs/reference/integrations/service-now-v2)
[View Integration Documentation](https://xsoar.pan.dev/docs/reference/integrations/service-now-v2)
31 changes: 30 additions & 1 deletion Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from unittest.mock import MagicMock

from pytest_mock import MockerFixture
from requests_mock import MockerCore
Expand All @@ -19,7 +20,8 @@
ServiceNowClient, oauth_test_module, login_command, get_modified_remote_data_command, \
get_ticket_fields, check_assigned_to_field, generic_api_call_command, get_closure_case, get_timezone_offset, \
converts_close_code_or_state_to_close_reason, split_notes, DATE_FORMAT, convert_to_notes_result, DATE_FORMAT_OPTIONS, \
format_incidents_response_with_display_values, get_entries_for_notes, is_time_field, delete_attachment_command
format_incidents_response_with_display_values, get_entries_for_notes, is_time_field, delete_attachment_command, \
get_attachment_command
from ServiceNowv2 import test_module as module
from test_data.response_constants import RESPONSE_TICKET, RESPONSE_MULTIPLE_TICKET, RESPONSE_UPDATE_TICKET, \
RESPONSE_UPDATE_TICKET_SC_REQ, RESPONSE_CREATE_TICKET, RESPONSE_CREATE_TICKET_WITH_OUT_JSON, RESPONSE_QUERY_TICKETS, \
Expand Down Expand Up @@ -2474,3 +2476,30 @@ def test_is_time_field(input_string, expected):
It should return True if string contains valid datetime, False otherwise
"""
assert is_time_field(input_string) is expected


def test_get_attachment_command_success():
client = MagicMock()
args = {'sys_id': '12345'}
mock_attachments = [
{'file_name': 'file1.txt', 'content': 'file1 content'},
{'file_name': 'file2.txt', 'content': 'file2 content'}
]
client.get_ticket_attachment_entries = MagicMock(return_value=mock_attachments)
result = get_attachment_command(client, args)
client.get_ticket_attachment_entries.assert_called_once_with('12345')
assert isinstance(result, list)
assert isinstance(result[0], CommandResults)
assert result[0].readable_output == 'Successfully retrieved attachments for ticket with sys id 12345.'
assert result[1] == mock_attachments


def test_get_attachment_command_missing_sys_id():
client = MagicMock()
args = {'sys_id': '12345'}
mock_attachments = []
client.get_ticket_attachment_entries = MagicMock(return_value=mock_attachments)
result = get_attachment_command(client, args)
client.get_ticket_attachment_entries.assert_called_once_with('12345')
assert isinstance(result, CommandResults)
assert result.readable_output == 'Ticket with sys id 12345 has no attachments to retrieve.'
8 changes: 8 additions & 0 deletions Packs/ServiceNow/ReleaseNotes/2_6_11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#### Integrations

##### ServiceNow v2

- Updated the docker image to: *demisto/python3:3.11.10.113941*.

- Added the ***servicenow-get-attachments*** command, which retrieves attachments from tickets.
2 changes: 1 addition & 1 deletion Packs/ServiceNow/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ServiceNow",
"description": "Use The ServiceNow IT Service Management (ITSM) solution to modernize the way you manage and deliver services to your users.",
"support": "xsoar",
"currentVersion": "2.6.10",
"currentVersion": "2.6.11",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit d4a4ef9

Please sign in to comment.