Code Duplication    Length = 25-26 lines in 2 locations

scripts/start-multiple-alerts-scan.gmp.py 1 location

@@ 238-262 (lines=25) @@
235
    return scanner_ids[1]  # default scanner
236
237
238
def create_and_start_task(
239
    gmp, config_id, target_id, scanner_id, alerts, debug=False
240
):
241
    # Create the task
242
    tasks = gmp.get_tasks(filter="name~ScanDoneMultipleAlert")
243
    task_name = "ScanDoneMultipleAlert{0}".format(len(tasks.xpath('tasks/@id')))
244
    task_comment = "test comment"
245
    res = gmp.create_task(
246
        task_name,
247
        config_id,
248
        target_id,
249
        scanner_id,
250
        alert_ids=alerts,
251
        comment=task_comment,
252
    )
253
    # Start the task
254
    task_id = res.xpath('@id')[0]
255
    gmp.start_task(task_id)
256
257
    print('Task started: %s' % task_name)
258
259
    if debug:
260
        # Stop the task (for performance reasons)
261
        gmp.stop_task(task_id)
262
        print('Task stopped')
263
264
265
def main(gmp, args):

scripts/start-alert-scan.gmp.py 1 location

@@ 194-219 (lines=26) @@
191
    return scanner_ids[1]  # default scanner
192
193
194
def create_and_start_task(
195
    gmp, config_id, target_id, scanner_id, alert_id, debug=False
196
):
197
    # Create the task
198
    tasks = gmp.get_tasks(filter="name~ScanDoneAlert")
199
    task_name = "ScanDoneAlert{0}".format(len(tasks.xpath('tasks/@id')))
200
    task_comment = "Scan Done Alert"
201
    res = gmp.create_task(
202
        task_name,
203
        config_id,
204
        target_id,
205
        scanner_id,
206
        alert_ids=[alert_id],
207
        comment=task_comment,
208
    )
209
210
    # Start the task
211
    task_id = res.xpath('@id')[0]
212
    gmp.start_task(task_id)
213
214
    print('Task started: ' + task_name)
215
216
    if debug:
217
        # Stop the task (for performance reasons)
218
        gmp.stop_task(task_id)
219
        print('Task stopped')
220
221
222
def main(gmp, args):