Skip to content

Commit f9a171b

Browse files
authored
ScheduleGenericPolling (#24945)
* ScheduleGenericPolling * conflicts * ScheduleGenericPolling * fix CR comments * conflicts * conflicts * ScheduleGenericPolling_to_py3 * ScheduleGenericPolling * ScheduleGenericPolling * ScheduleGenericPolling * ScheduleGenericPolling
1 parent 444ab5f commit f9a171b

File tree

4 files changed

+59
-46
lines changed

4 files changed

+59
-46
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#### Scripts
3+
4+
##### ScheduleGenericPolling
5+
6+
- Converted the script from python 2 to python 3.
7+
- Updated the Docker image to: *demisto/python3:3.10.10.48392*.
8+

Packs/CommonScripts/Scripts/ScheduleGenericPolling/ScheduleGenericPolling.py

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,53 @@ def parseIds(idsArg):
88
if idsArg is None:
99
return
1010
if isinstance(idsArg, list):
11-
return ','.join(map(lambda item: str(item) if type(item) == int else item.encode('utf-8'), idsArg))
12-
if isinstance(idsArg, str) or isinstance(idsArg, bytes) or isinstance(idsArg, unicode):
13-
return ','.join(argToList(idsArg.encode('utf-8')))
11+
return ','.join(map(str, idsArg))
12+
if isinstance(idsArg, str):
13+
return ','.join(argToList(idsArg))
14+
if isinstance(idsArg, bytes):
15+
return ','.join(argToList(idsArg.decode('utf-8')))
1416
return str(idsArg)
1517

1618

17-
def get_arg_and_encode(arg_name):
18-
arg = demisto.getArg(arg_name)
19-
return arg.encode('utf-8') if type(arg) != int else arg
20-
21-
22-
ids = parseIds(demisto.getArg('ids'))
23-
dt = get_arg_and_encode('dt')
24-
pollingCommand = demisto.getArg('pollingCommand')
25-
pollingCommandArgName = demisto.getArg('pollingCommandArgName')
26-
tag = get_arg_and_encode('tag')
27-
playbookId = ' playbookId="{}"'.format(demisto.getArg('playbookId') if 'playbookId' in demisto.args() else '')
28-
interval = int(demisto.getArg('interval'))
29-
timeout = int(demisto.getArg('timeout'))
30-
31-
args_names = demisto.getArg('additionalPollingCommandArgNames').strip()
32-
args_values = get_arg_and_encode('additionalPollingCommandArgValues').strip()
33-
34-
if interval <= 0 or timeout <= 0:
35-
return_error("Interval and timeout must be positive numbers")
36-
37-
# Verify correct dt path (does not verify condition!)
38-
if not demisto.dt(demisto.context(), dt):
39-
if not demisto.dt(demisto.context(), re.sub('\(.*\)', '', dt)):
40-
return_error("Incorrect dt path: no ids found")
41-
demisto.results("Warning: no ids matching the dt condition were found.\nVerify that the condition is correct and "
42-
"that all ids have finished running.")
43-
command_string = '''!GenericPollingScheduledTask pollingCommand="{0}" pollingCommandArgName="{1}"{2} ids="{3}" \
44-
pendingIds="{4}" interval="{5}" timeout="{6}" tag="{7}" additionalPollingCommandArgNames="{8}" \
45-
additionalPollingCommandArgValues="{9}"'''.format(pollingCommand, pollingCommandArgName, playbookId,
46-
ids.replace('"', r'\"'), dt.replace('"', r'\"'),
47-
interval, timeout, tag, args_names, args_values)
48-
res = demisto.executeCommand("ScheduleCommand",
49-
{
50-
'command': command_string,
51-
'cron': '*/{} * * * *'.format(interval),
52-
'times': 1
53-
})
54-
if isError(res[0]):
55-
return_error(res)
19+
def main():
20+
args = demisto.args()
21+
ids = parseIds(args.get('ids'))
22+
dt = args.get('dt')
23+
pollingCommand = args.get('pollingCommand')
24+
pollingCommandArgName = args.get('pollingCommandArgName')
25+
tag = args.get('tag')
26+
playbookId = f' playbookId="{args.get("playbookId","")}"'
27+
interval = int(args.get('interval'))
28+
timeout = int(args.get('timeout'))
29+
30+
args_names = args.get('additionalPollingCommandArgNames').strip() \
31+
if args.get('additionalPollingCommandArgNames') else None
32+
args_values = args.get('additionalPollingCommandArgValues').strip() \
33+
if args.get('additionalPollingCommandArgValues') else None
34+
35+
if interval <= 0 or timeout <= 0:
36+
return_error("Interval and timeout must be positive numbers")
37+
38+
# Verify correct dt path (does not verify condition!)
39+
if not demisto.dt(demisto.context(), dt):
40+
if not demisto.dt(demisto.context(), re.sub('\(.*\)', '', dt)):
41+
return_error("Incorrect dt path: no ids found")
42+
demisto.results("Warning: no ids matching the dt condition were found.\nVerify that the condition is correct and "
43+
"that all ids have finished running.")
44+
command_string = '''!GenericPollingScheduledTask pollingCommand="{0}" pollingCommandArgName="{1}"{2} ids="{3}" \
45+
pendingIds="{4}" interval="{5}" timeout="{6}" tag="{7}" additionalPollingCommandArgNames="{8}" \
46+
additionalPollingCommandArgValues="{9}"'''.format(pollingCommand, pollingCommandArgName, playbookId,
47+
ids.replace('"', r'\"'), dt.replace('"', r'\"'),
48+
interval, timeout, tag, args_names, args_values)
49+
res = demisto.executeCommand("ScheduleCommand",
50+
{
51+
'command': command_string,
52+
'cron': f'*/{interval} * * * *',
53+
'times': 1
54+
})
55+
if isError(res[0]):
56+
return_error(res)
57+
58+
59+
if __name__ in ("__main__", "__builtin__", "builtins"):
60+
main()

Packs/CommonScripts/Scripts/ScheduleGenericPolling/ScheduleGenericPolling.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: ScheduleGenericPolling
55
fromversion: 5.0.0
66
script: ''
77
type: python
8-
subtype: python2
8+
subtype: python3
99
tags: []
1010
comment: Called by the GenericPolling playbook, schedules the polling task.
1111
enabled: true
@@ -49,5 +49,5 @@ args:
4949
scripttarget: 0
5050
runonce: false
5151
tests:
52-
- No test
53-
dockerimage: demisto/python:2.7.18.27799
52+
- Generic Polling Test
53+
dockerimage: demisto/python3:3.10.10.48392

Packs/CommonScripts/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Common Scripts",
33
"description": "Frequently used scripts pack.",
44
"support": "xsoar",
5-
"currentVersion": "1.11.39",
5+
"currentVersion": "1.11.40",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)