| @@ 4278-4384 (lines=107) @@ | ||
| 4275 | ||
| 4276 | return self._send_xml_command(cmd) |
|
| 4277 | ||
| 4278 | def modify_alert( |
|
| 4279 | self, |
|
| 4280 | alert_id: str, |
|
| 4281 | *, |
|
| 4282 | name: Optional[str] = None, |
|
| 4283 | comment: Optional[str] = None, |
|
| 4284 | filter_id: Optional[str] = None, |
|
| 4285 | event: Optional[AlertEvent] = None, |
|
| 4286 | event_data: Optional[dict] = None, |
|
| 4287 | condition: Optional[AlertCondition] = None, |
|
| 4288 | condition_data: Optional[dict] = None, |
|
| 4289 | method: Optional[AlertMethod] = None, |
|
| 4290 | method_data: Optional[dict] = None |
|
| 4291 | ) -> Any: |
|
| 4292 | """Modifies an existing alert. |
|
| 4293 | ||
| 4294 | Arguments: |
|
| 4295 | alert_id: UUID of the alert to be modified. |
|
| 4296 | name: Name of the Alert. |
|
| 4297 | condition: The condition that must be satisfied for the alert to |
|
| 4298 | occur. If the event is either 'Updated SecInfo |
|
| 4299 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 4300 | Otherwise, condition can also be on of 'Severity at least', |
|
| 4301 | 'Filter count changed' or 'Filter count at least'. |
|
| 4302 | condition_data: Data that defines the condition |
|
| 4303 | event: The event that must happen for the alert to occur, one of |
|
| 4304 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 4305 | 'New SecInfo arrived' |
|
| 4306 | event_data: Data that defines the event |
|
| 4307 | method: The method by which the user is alerted, one of 'SCP', |
|
| 4308 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 4309 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 4310 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 4311 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 4312 | method_data: Data that defines the method |
|
| 4313 | filter_id: Filter to apply when executing alert |
|
| 4314 | comment: Comment for the alert |
|
| 4315 | ||
| 4316 | Returns: |
|
| 4317 | The response. See :py:meth:`send_command` for details. |
|
| 4318 | """ |
|
| 4319 | ||
| 4320 | if not alert_id: |
|
| 4321 | raise RequiredArgument( |
|
| 4322 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 4323 | ) |
|
| 4324 | ||
| 4325 | cmd = XmlCommand("modify_alert") |
|
| 4326 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 4327 | ||
| 4328 | if name: |
|
| 4329 | cmd.add_element("name", name) |
|
| 4330 | ||
| 4331 | if comment: |
|
| 4332 | cmd.add_element("comment", comment) |
|
| 4333 | ||
| 4334 | if filter_id: |
|
| 4335 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 4336 | ||
| 4337 | if condition: |
|
| 4338 | if not isinstance(condition, AlertCondition): |
|
| 4339 | raise InvalidArgumentType( |
|
| 4340 | function=self.modify_alert.__name__, |
|
| 4341 | argument='condition', |
|
| 4342 | arg_type=AlertCondition.__name__, |
|
| 4343 | ) |
|
| 4344 | ||
| 4345 | conditions = cmd.add_element("condition", condition.value) |
|
| 4346 | ||
| 4347 | if condition_data is not None: |
|
| 4348 | for key, value in condition_data.items(): |
|
| 4349 | _data = conditions.add_element("data", value) |
|
| 4350 | _data.add_element("name", key) |
|
| 4351 | ||
| 4352 | if method: |
|
| 4353 | if not isinstance(method, AlertMethod): |
|
| 4354 | raise InvalidArgumentType( |
|
| 4355 | function=self.modify_alert.__name__, |
|
| 4356 | argument='method', |
|
| 4357 | arg_type=AlertMethod.__name__, |
|
| 4358 | ) |
|
| 4359 | ||
| 4360 | methods = cmd.add_element("method", method.value) |
|
| 4361 | ||
| 4362 | if method_data is not None: |
|
| 4363 | for key, value in method_data.items(): |
|
| 4364 | _data = methods.add_element("data", value) |
|
| 4365 | _data.add_element("name", key) |
|
| 4366 | ||
| 4367 | if event: |
|
| 4368 | if not isinstance(event, AlertEvent): |
|
| 4369 | raise InvalidArgumentType( |
|
| 4370 | function=self.modify_alert.__name__, |
|
| 4371 | argument='event', |
|
| 4372 | arg_type=AlertEvent.__name__, |
|
| 4373 | ) |
|
| 4374 | ||
| 4375 | _check_event(event, condition, method) |
|
| 4376 | ||
| 4377 | events = cmd.add_element("event", event.value) |
|
| 4378 | ||
| 4379 | if event_data is not None: |
|
| 4380 | for key, value in event_data.items(): |
|
| 4381 | _data = events.add_element("data", value) |
|
| 4382 | _data.add_element("name", key) |
|
| 4383 | ||
| 4384 | return self._send_xml_command(cmd) |
|
| 4385 | ||
| 4386 | def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
|
| 4387 | """Modifies an existing asset. |
|
| @@ 499-605 (lines=107) @@ | ||
| 496 | cmd.set_attribute("include_certificate_data", "1") |
|
| 497 | return self._send_xml_command(cmd) |
|
| 498 | ||
| 499 | def modify_alert( |
|
| 500 | self, |
|
| 501 | alert_id: str, |
|
| 502 | *, |
|
| 503 | name: Optional[str] = None, |
|
| 504 | comment: Optional[str] = None, |
|
| 505 | filter_id: Optional[str] = None, |
|
| 506 | event: Optional[AlertEvent] = None, |
|
| 507 | event_data: Optional[dict] = None, |
|
| 508 | condition: Optional[AlertCondition] = None, |
|
| 509 | condition_data: Optional[dict] = None, |
|
| 510 | method: Optional[AlertMethod] = None, |
|
| 511 | method_data: Optional[dict] = None |
|
| 512 | ) -> Any: |
|
| 513 | """Modifies an existing alert. |
|
| 514 | ||
| 515 | Arguments: |
|
| 516 | alert_id: UUID of the alert to be modified. |
|
| 517 | name: Name of the Alert. |
|
| 518 | condition: The condition that must be satisfied for the alert to |
|
| 519 | occur. If the event is either 'Updated SecInfo |
|
| 520 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 521 | Otherwise, condition can also be on of 'Severity at least', |
|
| 522 | 'Filter count changed' or 'Filter count at least'. |
|
| 523 | condition_data: Data that defines the condition |
|
| 524 | event: The event that must happen for the alert to occur, one of |
|
| 525 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 526 | 'New SecInfo arrived' |
|
| 527 | event_data: Data that defines the event |
|
| 528 | method: The method by which the user is alerted, one of 'SCP', |
|
| 529 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 530 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 531 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 532 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 533 | method_data: Data that defines the method |
|
| 534 | filter_id: Filter to apply when executing alert |
|
| 535 | comment: Comment for the alert |
|
| 536 | ||
| 537 | Returns: |
|
| 538 | The response. See :py:meth:`send_command` for details. |
|
| 539 | """ |
|
| 540 | ||
| 541 | if not alert_id: |
|
| 542 | raise RequiredArgument( |
|
| 543 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 544 | ) |
|
| 545 | ||
| 546 | cmd = XmlCommand("modify_alert") |
|
| 547 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 548 | ||
| 549 | if name: |
|
| 550 | cmd.add_element("name", name) |
|
| 551 | ||
| 552 | if comment: |
|
| 553 | cmd.add_element("comment", comment) |
|
| 554 | ||
| 555 | if filter_id: |
|
| 556 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 557 | ||
| 558 | if condition: |
|
| 559 | if not isinstance(condition, AlertCondition): |
|
| 560 | raise InvalidArgumentType( |
|
| 561 | function=self.modify_alert.__name__, |
|
| 562 | argument='condition', |
|
| 563 | arg_type=AlertCondition.__name__, |
|
| 564 | ) |
|
| 565 | ||
| 566 | conditions = cmd.add_element("condition", condition.value) |
|
| 567 | ||
| 568 | if condition_data is not None: |
|
| 569 | for key, value in condition_data.items(): |
|
| 570 | _data = conditions.add_element("data", value) |
|
| 571 | _data.add_element("name", key) |
|
| 572 | ||
| 573 | if method: |
|
| 574 | if not isinstance(method, AlertMethod): |
|
| 575 | raise InvalidArgumentType( |
|
| 576 | function=self.modify_alert.__name__, |
|
| 577 | argument='method', |
|
| 578 | arg_type=AlertMethod.__name__, |
|
| 579 | ) |
|
| 580 | ||
| 581 | methods = cmd.add_element("method", method.value) |
|
| 582 | ||
| 583 | if method_data is not None: |
|
| 584 | for key, value in method_data.items(): |
|
| 585 | _data = methods.add_element("data", value) |
|
| 586 | _data.add_element("name", key) |
|
| 587 | ||
| 588 | if event: |
|
| 589 | if not isinstance(event, AlertEvent): |
|
| 590 | raise InvalidArgumentType( |
|
| 591 | function=self.modify_alert.__name__, |
|
| 592 | argument='event', |
|
| 593 | arg_type=AlertEvent.__name__, |
|
| 594 | ) |
|
| 595 | ||
| 596 | _check_event(event, condition, method) |
|
| 597 | ||
| 598 | events = cmd.add_element("event", event.value) |
|
| 599 | ||
| 600 | if event_data is not None: |
|
| 601 | for key, value in event_data.items(): |
|
| 602 | _data = events.add_element("data", value) |
|
| 603 | _data.add_element("name", key) |
|
| 604 | ||
| 605 | return self._send_xml_command(cmd) |
|
| 606 | ||
| 607 | def modify_tls_certificate( |
|
| 608 | self, |
|