Code Duplication    Length = 113-113 lines in 3 locations

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 333-445 (lines=113) @@
330
        cmd.add_element("copy", agent_id)
331
        return self._send_xml_command(cmd)
332
333
    def create_alert(
334
        self,
335
        name: str,
336
        condition: AlertCondition,
337
        event: AlertEvent,
338
        method: AlertMethod,
339
        *,
340
        method_data: Optional[dict] = None,
341
        event_data: Optional[dict] = None,
342
        condition_data: Optional[dict] = None,
343
        filter_id: Optional[int] = None,
344
        comment: Optional[str] = None,
345
    ) -> Any:
346
        """Create a new alert
347
348
        Arguments:
349
            name: Name of the new Alert
350
            condition: The condition that must be satisfied for the alert
351
                to occur; if the event is either 'Updated SecInfo arrived' or
352
                'New SecInfo arrived', condition must be 'Always'. Otherwise,
353
                condition can also be on of 'Severity at least', 'Filter count
354
                changed' or 'Filter count at least'.
355
            event: The event that must happen for the alert to occur, one
356
                of 'Task run status changed', 'Updated SecInfo arrived' or 'New
357
                SecInfo arrived'
358
            method: The method by which the user is alerted, one of 'SCP',
359
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is
360
                neither 'Updated SecInfo arrived' nor 'New SecInfo arrived',
361
                method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire
362
                Connector' or 'verinice Connector'.
363
            condition_data: Data that defines the condition
364
            event_data: Data that defines the event
365
            method_data: Data that defines the method
366
            filter_id: Filter to apply when executing alert
367
            comment: Comment for the alert
368
369
        Returns:
370
            The response. See :py:meth:`send_command` for details.
371
        """
372
        if not name:
373
            raise RequiredArgument(
374
                function=self.create_alert.__name__, argument='name'
375
            )
376
377
        if not condition:
378
            raise RequiredArgument(
379
                function=self.create_alert.__name__, argument='condition'
380
            )
381
382
        if not event:
383
            raise RequiredArgument(
384
                function=self.create_alert.__name__, argument='event'
385
            )
386
387
        if not method:
388
            raise RequiredArgument(
389
                function=self.create_alert.__name__, argument='method'
390
            )
391
392
        if not isinstance(condition, AlertCondition):
393
            raise InvalidArgumentType(
394
                function=self.create_alert.__name__,
395
                argument='condition',
396
                arg_type=AlertCondition.__name__,
397
            )
398
399
        if not isinstance(event, AlertEvent):
400
            raise InvalidArgumentType(
401
                function=self.create_alert.__name__,
402
                argument='even',
403
                arg_type=AlertEvent.__name__,
404
            )
405
406
        if not isinstance(method, AlertMethod):
407
            raise InvalidArgumentType(
408
                function=self.create_alert.__name__,
409
                argument='method',
410
                arg_type=AlertMethod.__name__,
411
            )
412
413
        _check_event(event, condition, method)
414
415
        cmd = XmlCommand("create_alert")
416
        cmd.add_element("name", name)
417
418
        conditions = cmd.add_element("condition", condition.value)
419
420
        if condition_data is not None:
421
            for key, value in condition_data.items():
422
                _data = conditions.add_element("data", value)
423
                _data.add_element("name", key)
424
425
        events = cmd.add_element("event", event.value)
426
427
        if event_data is not None:
428
            for key, value in event_data.items():
429
                _data = events.add_element("data", value)
430
                _data.add_element("name", key)
431
432
        methods = cmd.add_element("method", method.value)
433
434
        if method_data is not None:
435
            for key, value in method_data.items():
436
                _data = methods.add_element("data", value)
437
                _data.add_element("name", key)
438
439
        if filter_id:
440
            cmd.add_element("filter", attrs={"id": filter_id})
441
442
        if comment:
443
            cmd.add_element("comment", comment)
444
445
        return self._send_xml_command(cmd)
446
447
    def clone_alert(self, alert_id: str) -> Any:
448
        """Clone an existing alert

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 158-270 (lines=113) @@
155
        # Is authenticated on gvmd
156
        self._authenticated = False
157
158
    def create_alert(
159
        self,
160
        name: str,
161
        condition: AlertCondition,
162
        event: AlertEvent,
163
        method: AlertMethod,
164
        *,
165
        method_data: Optional[dict] = None,
166
        event_data: Optional[dict] = None,
167
        condition_data: Optional[dict] = None,
168
        filter_id: Optional[int] = None,
169
        comment: Optional[str] = None,
170
    ) -> Any:
171
        """Create a new alert
172
173
        Arguments:
174
            name: Name of the new Alert
175
            condition: The condition that must be satisfied for the alert
176
                to occur; if the event is either 'Updated SecInfo arrived' or
177
                'New SecInfo arrived', condition must be 'Always'. Otherwise,
178
                condition can also be on of 'Severity at least', 'Filter count
179
                changed' or 'Filter count at least'.
180
            event: The event that must happen for the alert to occur, one
181
                of 'Task run status changed', 'Updated SecInfo arrived' or 'New
182
                SecInfo arrived'
183
            method: The method by which the user is alerted, one of 'SCP',
184
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is
185
                neither 'Updated SecInfo arrived' nor 'New SecInfo arrived',
186
                method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire
187
                Connector' or 'verinice Connector'.
188
            condition_data: Data that defines the condition
189
            event_data: Data that defines the event
190
            method_data: Data that defines the method
191
            filter_id: Filter to apply when executing alert
192
            comment: Comment for the alert
193
194
        Returns:
195
            The response. See :py:meth:`send_command` for details.
196
        """
197
        if not name:
198
            raise RequiredArgument(
199
                function=self.create_alert.__name__, argument='name'
200
            )
201
202
        if not condition:
203
            raise RequiredArgument(
204
                function=self.create_alert.__name__, argument='condition'
205
            )
206
207
        if not event:
208
            raise RequiredArgument(
209
                function=self.create_alert.__name__, argument='event'
210
            )
211
212
        if not method:
213
            raise RequiredArgument(
214
                function=self.create_alert.__name__, argument='method'
215
            )
216
217
        if not isinstance(condition, AlertCondition):
218
            raise InvalidArgumentType(
219
                function=self.create_alert.__name__,
220
                argument='condition',
221
                arg_type=AlertCondition.__name__,
222
            )
223
224
        if not isinstance(event, AlertEvent):
225
            raise InvalidArgumentType(
226
                function=self.create_alert.__name__,
227
                argument='even',
228
                arg_type=AlertEvent.__name__,
229
            )
230
231
        if not isinstance(method, AlertMethod):
232
            raise InvalidArgumentType(
233
                function=self.create_alert.__name__,
234
                argument='method',
235
                arg_type=AlertMethod.__name__,
236
            )
237
238
        _check_event(event, condition, method)
239
240
        cmd = XmlCommand("create_alert")
241
        cmd.add_element("name", name)
242
243
        conditions = cmd.add_element("condition", condition.value)
244
245
        if condition_data is not None:
246
            for key, value in condition_data.items():
247
                _data = conditions.add_element("data", value)
248
                _data.add_element("name", key)
249
250
        events = cmd.add_element("event", event.value)
251
252
        if event_data is not None:
253
            for key, value in event_data.items():
254
                _data = events.add_element("data", value)
255
                _data.add_element("name", key)
256
257
        methods = cmd.add_element("method", method.value)
258
259
        if method_data is not None:
260
            for key, value in method_data.items():
261
                _data = methods.add_element("data", value)
262
                _data.add_element("name", key)
263
264
        if filter_id:
265
            cmd.add_element("filter", attrs={"id": filter_id})
266
267
        if comment:
268
            cmd.add_element("comment", comment)
269
270
        return self._send_xml_command(cmd)
271
272
    def create_audit(
273
        self,

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 279-391 (lines=113) @@
276
277
        return self._transform(response)
278
279
    def create_alert(
280
        self,
281
        name: str,
282
        condition: AlertCondition,
283
        event: AlertEvent,
284
        method: AlertMethod,
285
        *,
286
        method_data: Optional[dict] = None,
287
        event_data: Optional[dict] = None,
288
        condition_data: Optional[dict] = None,
289
        filter_id: Optional[int] = None,
290
        comment: Optional[str] = None,
291
    ) -> Any:
292
        """Create a new alert
293
294
        Arguments:
295
            name: Name of the new Alert
296
            condition: The condition that must be satisfied for the alert
297
                to occur; if the event is either 'Updated SecInfo arrived' or
298
                'New SecInfo arrived', condition must be 'Always'. Otherwise,
299
                condition can also be on of 'Severity at least', 'Filter count
300
                changed' or 'Filter count at least'.
301
            event: The event that must happen for the alert to occur, one
302
                of 'Task run status changed', 'Updated SecInfo arrived' or 'New
303
                SecInfo arrived'
304
            method: The method by which the user is alerted, one of 'SCP',
305
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is
306
                neither 'Updated SecInfo arrived' nor 'New SecInfo arrived',
307
                method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire
308
                Connector' or 'verinice Connector'.
309
            condition_data: Data that defines the condition
310
            event_data: Data that defines the event
311
            method_data: Data that defines the method
312
            filter_id: Filter to apply when executing alert
313
            comment: Comment for the alert
314
315
        Returns:
316
            The response. See :py:meth:`send_command` for details.
317
        """
318
        if not name:
319
            raise RequiredArgument(
320
                function=self.create_alert.__name__, argument='name'
321
            )
322
323
        if not condition:
324
            raise RequiredArgument(
325
                function=self.create_alert.__name__, argument='condition'
326
            )
327
328
        if not event:
329
            raise RequiredArgument(
330
                function=self.create_alert.__name__, argument='event'
331
            )
332
333
        if not method:
334
            raise RequiredArgument(
335
                function=self.create_alert.__name__, argument='method'
336
            )
337
338
        if not isinstance(condition, AlertCondition):
339
            raise InvalidArgumentType(
340
                function=self.create_alert.__name__,
341
                argument='condition',
342
                arg_type=AlertCondition.__name__,
343
            )
344
345
        if not isinstance(event, AlertEvent):
346
            raise InvalidArgumentType(
347
                function=self.create_alert.__name__,
348
                argument='even',
349
                arg_type=AlertEvent.__name__,
350
            )
351
352
        if not isinstance(method, AlertMethod):
353
            raise InvalidArgumentType(
354
                function=self.create_alert.__name__,
355
                argument='method',
356
                arg_type=AlertMethod.__name__,
357
            )
358
359
        _check_event(event, condition, method)
360
361
        cmd = XmlCommand("create_alert")
362
        cmd.add_element("name", name)
363
364
        conditions = cmd.add_element("condition", condition.value)
365
366
        if condition_data is not None:
367
            for key, value in condition_data.items():
368
                _data = conditions.add_element("data", value)
369
                _data.add_element("name", key)
370
371
        events = cmd.add_element("event", event.value)
372
373
        if event_data is not None:
374
            for key, value in event_data.items():
375
                _data = events.add_element("data", value)
376
                _data.add_element("name", key)
377
378
        methods = cmd.add_element("method", method.value)
379
380
        if method_data is not None:
381
            for key, value in method_data.items():
382
                _data = methods.add_element("data", value)
383
                _data.add_element("name", key)
384
385
        if filter_id:
386
            cmd.add_element("filter", attrs={"id": filter_id})
387
388
        if comment:
389
            cmd.add_element("comment", comment)
390
391
        return self._send_xml_command(cmd)
392
393
    def create_audit(
394
        self,