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/gmpv208/gmpv208.py 1 location

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

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,