@@ -8,48 +8,53 @@ def parseIds(idsArg):
8
8
if idsArg is None :
9
9
return
10
10
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' )))
14
16
return str (idsArg )
15
17
16
18
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.\n Verify 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.\n Verify 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 ()
0 commit comments