Code Duplication    Length = 25-26 lines in 2 locations

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

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

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):