| Total Complexity | 687 |
| Total Lines | 4751 |
| Duplicated Lines | 12.29 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like gvm.protocols.gmpv7 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | # Copyright (C) 2018 Greenbone Networks GmbH |
||
| 3 | # |
||
| 4 | # SPDX-License-Identifier: GPL-3.0-or-later |
||
| 5 | # |
||
| 6 | # This program is free software: you can redistribute it and/or modify |
||
| 7 | # it under the terms of the GNU General Public License as published by |
||
| 8 | # the Free Software Foundation, either version 3 of the License, or |
||
| 9 | # (at your option) any later version. |
||
| 10 | # |
||
| 11 | # This program is distributed in the hope that it will be useful, |
||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 14 | # GNU General Public License for more details. |
||
| 15 | # |
||
| 16 | # You should have received a copy of the GNU General Public License |
||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | # pylint: disable=too-many-lines,redefined-builtin |
||
| 20 | """ |
||
| 21 | Module for communication with gvmd in `Greenbone Management Protocol version 7`_ |
||
| 22 | |||
| 23 | .. _Greenbone Management Protocol version 7: |
||
| 24 | https://docs.greenbone.net/API/GMP/gmp-7.0.html |
||
| 25 | """ |
||
| 26 | import logging |
||
| 27 | |||
| 28 | from lxml import etree |
||
| 29 | |||
| 30 | from gvm.errors import InvalidArgument, RequiredArgument |
||
| 31 | from gvm.utils import get_version_string |
||
| 32 | from gvm.xml import XmlCommand, create_parser |
||
| 33 | |||
| 34 | from .base import GvmProtocol |
||
| 35 | |||
| 36 | logger = logging.getLogger(__name__) |
||
| 37 | |||
| 38 | PROTOCOL_VERSION = (7,) |
||
| 39 | |||
| 40 | FILTER_TYPES = ( |
||
| 41 | 'agent', |
||
| 42 | 'alert', |
||
| 43 | 'asset', |
||
| 44 | 'config', |
||
| 45 | 'credential', |
||
| 46 | 'filter', |
||
| 47 | 'group', |
||
| 48 | 'note', |
||
| 49 | 'override', |
||
| 50 | 'permission', |
||
| 51 | 'port_list', |
||
| 52 | 'report', |
||
| 53 | 'report_format', |
||
| 54 | 'result', |
||
| 55 | 'role', |
||
| 56 | 'schedule', |
||
| 57 | 'secinfo', |
||
| 58 | 'tag', |
||
| 59 | 'target', |
||
| 60 | 'task', |
||
| 61 | 'user', |
||
| 62 | ) |
||
| 63 | |||
| 64 | TIME_UNITS = ( |
||
| 65 | 'second', |
||
| 66 | 'minute', |
||
| 67 | 'hour', |
||
| 68 | 'day', |
||
| 69 | 'week', |
||
| 70 | 'month', |
||
| 71 | 'year', |
||
| 72 | 'decade', |
||
| 73 | ) |
||
| 74 | |||
| 75 | ALIVE_TESTS = ( |
||
| 76 | 'ICMP, TCP Service & ARP Ping', |
||
| 77 | 'TCP Service & ARP Ping', |
||
| 78 | 'ICMP & ARP Ping', |
||
| 79 | 'ICMP & TCP Service Ping', |
||
| 80 | 'ARP Ping', |
||
| 81 | 'TCP Service Ping', |
||
| 82 | 'ICMP Ping', |
||
| 83 | 'Scan Config Default', |
||
| 84 | ) |
||
| 85 | |||
| 86 | CREDENTIAL_TYPES = ( |
||
| 87 | 'cc', |
||
| 88 | 'snmp', |
||
| 89 | 'up', |
||
| 90 | 'usk', |
||
| 91 | ) |
||
| 92 | |||
| 93 | SCANNER_TYPES = ( |
||
| 94 | '1', |
||
| 95 | '2', |
||
| 96 | ) |
||
| 97 | |||
| 98 | ALERT_EVENTS = ( |
||
| 99 | 'Task run status changed', |
||
| 100 | ) |
||
| 101 | |||
| 102 | ALERT_EVENTS_SECINFO = ( |
||
| 103 | 'Updated SecInfo arrived', |
||
| 104 | 'New SecInfo arrived' |
||
| 105 | ) |
||
| 106 | |||
| 107 | ALERT_CONDITIONS = ( |
||
| 108 | 'Always', |
||
| 109 | 'Severity at least', |
||
| 110 | 'Filter count changed', |
||
| 111 | 'Filter count at least', |
||
| 112 | ) |
||
| 113 | |||
| 114 | ALERT_CONDITIONS_SECINFO = ( |
||
| 115 | 'Always', |
||
| 116 | ) |
||
| 117 | |||
| 118 | ALERT_METHODS = ( |
||
| 119 | 'SCP', |
||
| 120 | 'Send', |
||
| 121 | 'SMB', |
||
| 122 | 'SNMP', |
||
| 123 | 'Syslog', |
||
| 124 | 'Email', |
||
| 125 | 'Start Task', |
||
| 126 | 'HTTP Get', |
||
| 127 | 'Sourcefire Connector', |
||
| 128 | 'verinice Connector', |
||
| 129 | ) |
||
| 130 | |||
| 131 | ALERT_METHODS_SECINFO = ( |
||
| 132 | 'SCP', |
||
| 133 | 'Send', |
||
| 134 | 'SMB', |
||
| 135 | 'SNMP', |
||
| 136 | 'Syslog', |
||
| 137 | 'Email', |
||
| 138 | ) |
||
| 139 | |||
| 140 | def _check_command_status(xml): |
||
| 141 | """Check gmp response |
||
| 142 | |||
| 143 | Look into the gmp response and check for the status in the root element |
||
| 144 | |||
| 145 | Arguments: |
||
| 146 | xml {string} -- XML-Source |
||
| 147 | |||
| 148 | Returns: |
||
| 149 | bool -- True if valid, otherwise False |
||
| 150 | """ |
||
| 151 | |||
| 152 | if xml is 0 or xml is None: |
||
|
|
|||
| 153 | logger.error('XML Command is empty') |
||
| 154 | return False |
||
| 155 | |||
| 156 | try: |
||
| 157 | root = etree.XML(xml, parser=create_parser()) |
||
| 158 | status = root.attrib['status'] |
||
| 159 | return status is not None and status[0] == '2' |
||
| 160 | |||
| 161 | except etree.Error as e: |
||
| 162 | logger.error('etree.XML(xml): %s', e) |
||
| 163 | return False |
||
| 164 | |||
| 165 | |||
| 166 | def _to_bool(value): |
||
| 167 | return '1' if value else '0' |
||
| 168 | |||
| 169 | |||
| 170 | def _add_filter(cmd, filter, filter_id): |
||
| 171 | if filter: |
||
| 172 | cmd.set_attribute('filter', filter) |
||
| 173 | |||
| 174 | if filter_id: |
||
| 175 | cmd.set_attribute('filt_id', filter_id) |
||
| 176 | |||
| 177 | |||
| 178 | class Gmp(GvmProtocol): |
||
| 179 | """Python interface for Greenbone Management Protocol |
||
| 180 | |||
| 181 | This class implements the `Greenbone Management Protocol version 7`_ |
||
| 182 | |||
| 183 | Attributes: |
||
| 184 | connection (:class:`gvm.connections.GvmConnection`): Connection to use |
||
| 185 | to talk with the gvmd daemon. See :mod:`gvm.connections` for |
||
| 186 | possible connection types. |
||
| 187 | transform (`callable`_, optional): Optional transform callable to |
||
| 188 | convert response data. After each request the callable gets passed |
||
| 189 | the plain response data which can be used to check the data and/or |
||
| 190 | conversion into different representations like a xml dom. |
||
| 191 | |||
| 192 | See :mod:`gvm.transforms` for existing transforms. |
||
| 193 | |||
| 194 | .. _Greenbone Management Protocol version 7: |
||
| 195 | https://docs.greenbone.net/API/GMP/gmp-7.0.html |
||
| 196 | .. _callable: |
||
| 197 | https://docs.python.org/3/library/functions.html#callable |
||
| 198 | """ |
||
| 199 | |||
| 200 | def __init__(self, connection, *, transform=None): |
||
| 201 | super().__init__(connection, transform=transform) |
||
| 202 | |||
| 203 | # Is authenticated on gvmd |
||
| 204 | self._authenticated = False |
||
| 205 | |||
| 206 | @staticmethod |
||
| 207 | def get_protocol_version(): |
||
| 208 | """Allow to determine the Greenbone Management Protocol version. |
||
| 209 | |||
| 210 | Returns: |
||
| 211 | str: Implemented version of the Greenbone Management Protocol |
||
| 212 | """ |
||
| 213 | return get_version_string(PROTOCOL_VERSION) |
||
| 214 | |||
| 215 | def is_authenticated(self): |
||
| 216 | """Checks if the user is authenticated |
||
| 217 | |||
| 218 | If the user is authenticated privileged GMP commands like get_tasks |
||
| 219 | may be send to gvmd. |
||
| 220 | |||
| 221 | Returns: |
||
| 222 | bool: True if an authenticated connection to gvmd has been |
||
| 223 | established. |
||
| 224 | """ |
||
| 225 | return self._authenticated |
||
| 226 | |||
| 227 | def authenticate(self, username, password): |
||
| 228 | """Authenticate to gvmd. |
||
| 229 | |||
| 230 | The generated authenticate command will be send to server. |
||
| 231 | Afterwards the response is read, transformed and returned. |
||
| 232 | |||
| 233 | Arguments: |
||
| 234 | username (str): Username |
||
| 235 | password (str): Password |
||
| 236 | |||
| 237 | Returns: |
||
| 238 | any, str by default: Transformed response from server. |
||
| 239 | """ |
||
| 240 | cmd = XmlCommand('authenticate') |
||
| 241 | |||
| 242 | if not username: |
||
| 243 | raise RequiredArgument('authenticate requires username') |
||
| 244 | |||
| 245 | if not password: |
||
| 246 | raise RequiredArgument('authenticate requires password') |
||
| 247 | |||
| 248 | credentials = cmd.add_element('credentials') |
||
| 249 | credentials.add_element('username', username) |
||
| 250 | credentials.add_element('password', password) |
||
| 251 | |||
| 252 | self._send(cmd.to_string()) |
||
| 253 | response = self._read() |
||
| 254 | |||
| 255 | if _check_command_status(response): |
||
| 256 | self._authenticated = True |
||
| 257 | |||
| 258 | return self._transform(response) |
||
| 259 | |||
| 260 | def create_agent(self, installer, signature, name, *, comment=None, |
||
| 261 | howto_install=None, howto_use=None): |
||
| 262 | """Create a new agent |
||
| 263 | |||
| 264 | Arguments: |
||
| 265 | installer (str): A base64 encoded file that installs the agent on a |
||
| 266 | target machine |
||
| 267 | signature: (str): A detached OpenPGP signature of the installer |
||
| 268 | name (str): A name for the agent |
||
| 269 | comment (str, optional): A comment for the agent |
||
| 270 | howto_install (str, optional): A file that describes how to install |
||
| 271 | the agent |
||
| 272 | howto_use (str, optional): A file that describes how to use the |
||
| 273 | agent |
||
| 274 | |||
| 275 | Returns: |
||
| 276 | The response. See :py:meth:`send_command` for details. |
||
| 277 | """ |
||
| 278 | if not name: |
||
| 279 | raise RequiredArgument('create_agent requires name argument') |
||
| 280 | |||
| 281 | if not installer: |
||
| 282 | raise RequiredArgument('create_agent requires installer argument') |
||
| 283 | |||
| 284 | if not signature: |
||
| 285 | raise RequiredArgument('create_agent requires signature argument') |
||
| 286 | |||
| 287 | cmd = XmlCommand('create_agent') |
||
| 288 | cmd.add_element('installer', installer) |
||
| 289 | cmd.add_element('signature', signature) |
||
| 290 | cmd.add_element('name', name) |
||
| 291 | |||
| 292 | if comment: |
||
| 293 | cmd.add_element('comment', comment) |
||
| 294 | |||
| 295 | if howto_install: |
||
| 296 | cmd.add_element('howto_install', howto_install) |
||
| 297 | |||
| 298 | if howto_use: |
||
| 299 | cmd.add_element('howto_use', howto_use) |
||
| 300 | |||
| 301 | return self._send_xml_command(cmd) |
||
| 302 | |||
| 303 | def clone_agent(self, agent_id): |
||
| 304 | """Clone an existing agent |
||
| 305 | |||
| 306 | Arguments: |
||
| 307 | copy (str): UUID of an existing agent to clone from |
||
| 308 | |||
| 309 | Returns: |
||
| 310 | The response. See :py:meth:`send_command` for details. |
||
| 311 | """ |
||
| 312 | if not agent_id: |
||
| 313 | raise RequiredArgument('clone_agent requires a agent_id argument') |
||
| 314 | |||
| 315 | cmd = XmlCommand('create_agent') |
||
| 316 | cmd.add_element('copy', agent_id) |
||
| 317 | return self._send_xml_command(cmd) |
||
| 318 | |||
| 319 | def create_alert(self, name, condition, event, method, *, method_data=None, |
||
| 320 | event_data=None, condition_data=None, filter_id=None, |
||
| 321 | comment=None): |
||
| 322 | """Create a new alert |
||
| 323 | |||
| 324 | Arguments: |
||
| 325 | name (str): Name of the new Alert |
||
| 326 | condition (str): The condition that must be satisfied for the alert |
||
| 327 | to occur; if the event is either 'Updated SecInfo arrived' or |
||
| 328 | 'New SecInfo arrived', condition must be 'Always'. Otherwise, |
||
| 329 | condition can also be on of 'Severity at least', 'Filter count |
||
| 330 | changed' or 'Filter count at least'. |
||
| 331 | event (str): The event that must happen for the alert to occur, one |
||
| 332 | of 'Task run status changed', 'Updated SecInfo arrived' or 'New |
||
| 333 | SecInfo arrived' |
||
| 334 | method (str): The method by which the user is alerted, one of 'SCP', |
||
| 335 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is |
||
| 336 | neither 'Updated SecInfo arrived' nor 'New SecInfo arrived', |
||
| 337 | method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire |
||
| 338 | Connector' or 'verinice Connector'. |
||
| 339 | condition_data (dict, optional): Data that defines the condition |
||
| 340 | event_data (dict, optional): Data that defines the event |
||
| 341 | method_data (dict, optional): Data that defines the method |
||
| 342 | filter_id (str, optional): Filter to apply when executing alert |
||
| 343 | comment (str, optional): Comment for the alert |
||
| 344 | |||
| 345 | Returns: |
||
| 346 | The response. See :py:meth:`send_command` for details. |
||
| 347 | """ |
||
| 348 | if not name: |
||
| 349 | raise RequiredArgument('create_alert requires name argument') |
||
| 350 | |||
| 351 | if not condition: |
||
| 352 | raise RequiredArgument('create_alert requires condition argument') |
||
| 353 | |||
| 354 | if not event: |
||
| 355 | raise RequiredArgument('create_alert requires event argument') |
||
| 356 | |||
| 357 | if not method: |
||
| 358 | raise RequiredArgument('create_alert requires method argument') |
||
| 359 | |||
| 360 | if event in ALERT_EVENTS: |
||
| 361 | if condition not in ALERT_CONDITIONS: |
||
| 362 | raise InvalidArgument('Invalid condition for event') |
||
| 363 | if method not in ALERT_METHODS: |
||
| 364 | raise InvalidArgument('Invalid method for event') |
||
| 365 | elif event in ALERT_EVENTS_SECINFO: |
||
| 366 | if condition not in ALERT_CONDITIONS_SECINFO: |
||
| 367 | raise InvalidArgument('Invalid condition for event') |
||
| 368 | if method not in ALERT_METHODS_SECINFO: |
||
| 369 | raise InvalidArgument('Invalid method for event') |
||
| 370 | else: |
||
| 371 | raise InvalidArgument('Invalid event') |
||
| 372 | |||
| 373 | |||
| 374 | cmd = XmlCommand('create_alert') |
||
| 375 | cmd.add_element('name', name) |
||
| 376 | |||
| 377 | conditions = cmd.add_element('condition', condition) |
||
| 378 | |||
| 379 | if not condition_data is None: |
||
| 380 | for key, value in condition_data.items(): |
||
| 381 | _data = conditions.add_element('data', value) |
||
| 382 | _data.add_element('name', key) |
||
| 383 | |||
| 384 | events = cmd.add_element('event', event) |
||
| 385 | |||
| 386 | if not event_data is None: |
||
| 387 | for key, value in event_data.items(): |
||
| 388 | _data = events.add_element('data', value) |
||
| 389 | _data.add_element('name', key) |
||
| 390 | |||
| 391 | methods = cmd.add_element('method', method) |
||
| 392 | |||
| 393 | if not method_data is None: |
||
| 394 | for key, value in method_data.items(): |
||
| 395 | _data = methods.add_element('data', value) |
||
| 396 | _data.add_element('name', key) |
||
| 397 | |||
| 398 | if filter_id: |
||
| 399 | cmd.add_element('filter', attrs={'id': filter_id}) |
||
| 400 | |||
| 401 | if comment: |
||
| 402 | cmd.add_element('comment', comment) |
||
| 403 | |||
| 404 | return self._send_xml_command(cmd) |
||
| 405 | |||
| 406 | def clone_alert(self, alert_id): |
||
| 407 | """Clone an existing alert |
||
| 408 | |||
| 409 | Arguments: |
||
| 410 | copy (str): UUID of an existing alert to clone from |
||
| 411 | |||
| 412 | Returns: |
||
| 413 | The response. See :py:meth:`send_command` for details. |
||
| 414 | """ |
||
| 415 | if not alert_id: |
||
| 416 | raise RequiredArgument('clone_alert requires a alert_id argument') |
||
| 417 | |||
| 418 | cmd = XmlCommand('create_alert') |
||
| 419 | cmd.add_element('copy', alert_id) |
||
| 420 | return self._send_xml_command(cmd) |
||
| 421 | |||
| 422 | def create_config(self, config_id, name): |
||
| 423 | """Create a new scan config from an existing one |
||
| 424 | |||
| 425 | Arguments: |
||
| 426 | config_id (str): UUID of the existing scan config |
||
| 427 | name (str): Name of the new scan config |
||
| 428 | |||
| 429 | Returns: |
||
| 430 | The response. See :py:meth:`send_command` for details. |
||
| 431 | """ |
||
| 432 | if not name: |
||
| 433 | raise RequiredArgument('create_config requires name argument') |
||
| 434 | |||
| 435 | if not config_id: |
||
| 436 | raise RequiredArgument('create_config requires config_id argument') |
||
| 437 | |||
| 438 | cmd = XmlCommand('create_config') |
||
| 439 | cmd.add_element('copy', config_id) |
||
| 440 | cmd.add_element('name', name) |
||
| 441 | return self._send_xml_command(cmd) |
||
| 442 | |||
| 443 | def clone_config(self, config_id): |
||
| 444 | """Clone a scan config from an existing one |
||
| 445 | |||
| 446 | Arguments: |
||
| 447 | config_id (str): UUID of the existing scan config |
||
| 448 | |||
| 449 | Returns: |
||
| 450 | The response. See :py:meth:`send_command` for details. |
||
| 451 | """ |
||
| 452 | if not config_id: |
||
| 453 | raise RequiredArgument('clone_config requires config_id argument') |
||
| 454 | |||
| 455 | cmd = XmlCommand('create_config') |
||
| 456 | cmd.add_element('copy', config_id) |
||
| 457 | return self._send_xml_command(cmd) |
||
| 458 | |||
| 459 | def import_config(self, config): |
||
| 460 | """Import a scan config from XML |
||
| 461 | |||
| 462 | Arguments: |
||
| 463 | config (str): Scan Config XML as string to import. This XML must |
||
| 464 | contain a :code:`<get_configs_response>` root element. |
||
| 465 | |||
| 466 | Returns: |
||
| 467 | The response. See :py:meth:`send_command` for details. |
||
| 468 | """ |
||
| 469 | if not config: |
||
| 470 | raise RequiredArgument('import_config requires config argument') |
||
| 471 | |||
| 472 | cmd = XmlCommand('create_config') |
||
| 473 | |||
| 474 | try: |
||
| 475 | cmd.append_xml_str(config) |
||
| 476 | except etree.XMLSyntaxError as e: |
||
| 477 | raise InvalidArgument( |
||
| 478 | 'Invalid xml passed as config to import_config', e) |
||
| 479 | |||
| 480 | return self._send_xml_command(cmd) |
||
| 481 | |||
| 482 | def create_credential(self, name, credential_type, *, comment=None, |
||
| 483 | allow_insecure=False, certificate=None, |
||
| 484 | key_phrase=None, private_key=None, |
||
| 485 | login=None, password=None, auth_algorithm=None, |
||
| 486 | community=None, privacy_algorithm=None, |
||
| 487 | privacy_password=None): |
||
| 488 | """Create a new credential |
||
| 489 | |||
| 490 | Create a new credential e.g. to be used in the method of an alert. |
||
| 491 | |||
| 492 | Currently the following credential types are supported: |
||
| 493 | |||
| 494 | - 'up' - Username + Password |
||
| 495 | - 'usk' - Username + private SSH-Key |
||
| 496 | - 'cc' - Client Certificates |
||
| 497 | - 'snmp' - SNMPv1 or SNMPv2c protocol |
||
| 498 | |||
| 499 | Arguments: |
||
| 500 | name (str): Name of the new credential |
||
| 501 | credential_type (str): The credential type. One of 'cc', 'snmp', |
||
| 502 | 'up', 'usk' |
||
| 503 | comment (str, optional): Comment for the credential |
||
| 504 | allow_insecure (boolean, optional): Whether to allow insecure use of |
||
| 505 | the credential |
||
| 506 | certificate (str, optional): Certificate for the credential. |
||
| 507 | Required for cc credential type. |
||
| 508 | key_phrase (str, optional): Key passphrase for the private key. |
||
| 509 | Used for the usk credential type. |
||
| 510 | private_key (str, optional): Private key to use for login. Required |
||
| 511 | for usk credential type. Also used for the cc credential type. |
||
| 512 | The supported key types (dsa, rsa, ecdsa, ...) and formats (PEM, |
||
| 513 | PKC#12, OpenSSL, ...) depend on your installed GnuTLS version. |
||
| 514 | login (str, optional): Username for the credential. Required for |
||
| 515 | up, usk and snmp credential type. |
||
| 516 | password (str, optional): Password for the credential. Used for |
||
| 517 | up and snmp credential types. |
||
| 518 | community (str, optional): The SNMP community. |
||
| 519 | auth_algorithm (str, optional): The SNMP authentication algorithm. |
||
| 520 | Either 'md5' or 'sha1'. Required for snmp credential type. |
||
| 521 | privacy_algorithm (str, optional): The SNMP privacy algorithm, |
||
| 522 | either aes or des. |
||
| 523 | privacy_password (str, optional): The SNMP privacy password |
||
| 524 | |||
| 525 | Examples: |
||
| 526 | Creating a Username + Password credential |
||
| 527 | |||
| 528 | .. code-block:: python |
||
| 529 | |||
| 530 | gmp.create_credential( |
||
| 531 | name='UP Credential', |
||
| 532 | credential_type='up', |
||
| 533 | login='foo', |
||
| 534 | password='bar', |
||
| 535 | ); |
||
| 536 | |||
| 537 | Creating a Username + SSH Key credential |
||
| 538 | |||
| 539 | .. code-block:: python |
||
| 540 | |||
| 541 | with open('path/to/private-ssh-key') as f: |
||
| 542 | key = f.read() |
||
| 543 | |||
| 544 | gmp.create_credential( |
||
| 545 | name='USK Credential', |
||
| 546 | credential_type='usk', |
||
| 547 | login='foo', |
||
| 548 | key_phrase='foobar', |
||
| 549 | private_key=key, |
||
| 550 | ) |
||
| 551 | |||
| 552 | Returns: |
||
| 553 | The response. See :py:meth:`send_command` for details. |
||
| 554 | """ |
||
| 555 | if not name: |
||
| 556 | raise RequiredArgument('create_credential requires name argument') |
||
| 557 | |||
| 558 | if credential_type not in CREDENTIAL_TYPES: |
||
| 559 | raise InvalidArgument( |
||
| 560 | 'create_credential requires type to be either cc, snmp, up ' |
||
| 561 | ' or usk') |
||
| 562 | |||
| 563 | cmd = XmlCommand('create_credential') |
||
| 564 | cmd.add_element('name', name) |
||
| 565 | |||
| 566 | cmd.add_element('type', credential_type) |
||
| 567 | |||
| 568 | if comment: |
||
| 569 | cmd.add_element('comment', comment) |
||
| 570 | |||
| 571 | if allow_insecure: |
||
| 572 | cmd.add_element('allow_insecure', '1') |
||
| 573 | |||
| 574 | if credential_type == 'cc': |
||
| 575 | if not certificate: |
||
| 576 | raise RequiredArgument( |
||
| 577 | 'create_credential requires certificate argument for ' |
||
| 578 | 'credential_type {0}'.format(credential_type)) |
||
| 579 | |||
| 580 | cmd.add_element('certificate', certificate) |
||
| 581 | |||
| 582 | if (credential_type == 'up' or credential_type == 'usk' or \ |
||
| 583 | credential_type == 'snmp'): |
||
| 584 | if not login: |
||
| 585 | raise RequiredArgument( |
||
| 586 | 'create_credential requires login argument for ' |
||
| 587 | 'credential_type {0}'.format(credential_type)) |
||
| 588 | |||
| 589 | cmd.add_element('login', login) |
||
| 590 | |||
| 591 | if (credential_type == 'up' or credential_type == 'snmp') and password: |
||
| 592 | cmd.add_element('password', password) |
||
| 593 | |||
| 594 | View Code Duplication | if credential_type == 'usk': |
|
| 595 | if not private_key: |
||
| 596 | raise RequiredArgument( |
||
| 597 | 'create_credential requires certificate argument for ' |
||
| 598 | 'credential_type usk') |
||
| 599 | |||
| 600 | _xmlkey = cmd.add_element('key') |
||
| 601 | _xmlkey.add_element('private', private_key) |
||
| 602 | |||
| 603 | if key_phrase: |
||
| 604 | _xmlkey.add_element('phrase', key_phrase) |
||
| 605 | |||
| 606 | if credential_type == 'cc' and private_key: |
||
| 607 | _xmlkey = cmd.add_element('key') |
||
| 608 | _xmlkey.add_element('private', private_key) |
||
| 609 | |||
| 610 | View Code Duplication | if credential_type == 'snmp': |
|
| 611 | if auth_algorithm not in ('md5', 'sha1'): |
||
| 612 | raise InvalidArgument( |
||
| 613 | 'create_credential requires auth_algorithm to be either ' |
||
| 614 | 'md5 or sha1') |
||
| 615 | |||
| 616 | cmd.add_element('auth_algorithm', auth_algorithm) |
||
| 617 | |||
| 618 | if community: |
||
| 619 | cmd.add_element('community', community) |
||
| 620 | |||
| 621 | if privacy_algorithm is not None or privacy_password: |
||
| 622 | _xmlprivacy = cmd.add_element('privacy') |
||
| 623 | |||
| 624 | if privacy_algorithm is not None: |
||
| 625 | if privacy_algorithm not in ('aes', 'des'): |
||
| 626 | raise InvalidArgument( |
||
| 627 | 'create_credential requires algorithm to be either ' |
||
| 628 | 'aes or des') |
||
| 629 | |||
| 630 | _xmlprivacy.add_element('algorithm', privacy_algorithm) |
||
| 631 | |||
| 632 | if privacy_password: |
||
| 633 | _xmlprivacy.add_element('password', privacy_password) |
||
| 634 | |||
| 635 | return self._send_xml_command(cmd) |
||
| 636 | |||
| 637 | def clone_credential(self, credential_id): |
||
| 638 | """Clone an existing credential |
||
| 639 | |||
| 640 | Arguments: |
||
| 641 | copy (str): UUID of an existing credential to clone from |
||
| 642 | |||
| 643 | Returns: |
||
| 644 | The response. See :py:meth:`send_command` for details. |
||
| 645 | """ |
||
| 646 | if not credential_id: |
||
| 647 | raise RequiredArgument( |
||
| 648 | 'clone_credential requires a credential_id argument') |
||
| 649 | |||
| 650 | cmd = XmlCommand('create_credential') |
||
| 651 | cmd.add_element('copy', credential_id) |
||
| 652 | return self._send_xml_command(cmd) |
||
| 653 | |||
| 654 | def create_filter(self, name, *, make_unique=False, filter_type=None, |
||
| 655 | comment=None, term=None): |
||
| 656 | """Create a new filter |
||
| 657 | |||
| 658 | Arguments: |
||
| 659 | name (str): Name of the new filter |
||
| 660 | make_unique (boolean, optional): |
||
| 661 | filter_type (str, optional): Filter for entity type |
||
| 662 | comment (str, optional): Comment for the filter |
||
| 663 | term (str, optional): Filter term e.g. 'name=foo' |
||
| 664 | |||
| 665 | Returns: |
||
| 666 | The response. See :py:meth:`send_command` for details. |
||
| 667 | """ |
||
| 668 | if not name: |
||
| 669 | raise RequiredArgument('create_filter requires a name argument') |
||
| 670 | |||
| 671 | cmd = XmlCommand('create_filter') |
||
| 672 | _xmlname = cmd.add_element('name', name) |
||
| 673 | if make_unique: |
||
| 674 | _xmlname.add_element('make_unique', '1') |
||
| 675 | |||
| 676 | if comment: |
||
| 677 | cmd.add_element('comment', comment) |
||
| 678 | |||
| 679 | if term: |
||
| 680 | cmd.add_element('term', term) |
||
| 681 | |||
| 682 | if filter_type: |
||
| 683 | filter_type = filter_type.lower() |
||
| 684 | if filter_type not in FILTER_TYPES: |
||
| 685 | raise InvalidArgument( |
||
| 686 | 'create_filter requires type to be one of {0} but ' |
||
| 687 | 'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
||
| 688 | cmd.add_element('type', filter_type) |
||
| 689 | |||
| 690 | return self._send_xml_command(cmd) |
||
| 691 | |||
| 692 | def clone_filter(self, filter_id): |
||
| 693 | """Clone an existing filter |
||
| 694 | |||
| 695 | Arguments: |
||
| 696 | copy (str): UUID of an existing filter to clone from |
||
| 697 | |||
| 698 | Returns: |
||
| 699 | The response. See :py:meth:`send_command` for details. |
||
| 700 | """ |
||
| 701 | if not filter_id: |
||
| 702 | raise RequiredArgument('clone_filter requires a filter_id argument') |
||
| 703 | |||
| 704 | cmd = XmlCommand('create_filter') |
||
| 705 | cmd.add_element('copy', filter_id) |
||
| 706 | return self._send_xml_command(cmd) |
||
| 707 | |||
| 708 | def create_group(self, name, *, comment=None, special=False, users=None): |
||
| 709 | """Create a new group |
||
| 710 | |||
| 711 | Arguments: |
||
| 712 | name (str): Name of the new group |
||
| 713 | comment (str, optional): Comment for the group |
||
| 714 | special (boolean, optional): Create permission giving members full |
||
| 715 | access to each other's entities |
||
| 716 | users (list, optional): List of user names to be in the group |
||
| 717 | |||
| 718 | Returns: |
||
| 719 | The response. See :py:meth:`send_command` for details. |
||
| 720 | """ |
||
| 721 | if not name: |
||
| 722 | raise RequiredArgument('create_group requires a name argument') |
||
| 723 | |||
| 724 | cmd = XmlCommand('create_group') |
||
| 725 | cmd.add_element('name', name) |
||
| 726 | |||
| 727 | if comment: |
||
| 728 | cmd.add_element('comment', comment) |
||
| 729 | |||
| 730 | if special: |
||
| 731 | _xmlspecial = cmd.add_element('specials') |
||
| 732 | _xmlspecial.add_element('full') |
||
| 733 | |||
| 734 | if users: |
||
| 735 | cmd.add_element('users', ','.join(users)) |
||
| 736 | |||
| 737 | return self._send_xml_command(cmd) |
||
| 738 | |||
| 739 | def clone_group(self, group_id): |
||
| 740 | """Clone an existing group |
||
| 741 | |||
| 742 | Arguments: |
||
| 743 | copy (str): UUID of an existing group to clone from |
||
| 744 | |||
| 745 | Returns: |
||
| 746 | The response. See :py:meth:`send_command` for details. |
||
| 747 | """ |
||
| 748 | if not group_id: |
||
| 749 | raise RequiredArgument('clone_group requires a group_id argument') |
||
| 750 | |||
| 751 | cmd = XmlCommand('create_group') |
||
| 752 | cmd.add_element('copy', group_id) |
||
| 753 | return self._send_xml_command(cmd) |
||
| 754 | |||
| 755 | def create_host(self, name, *, comment=None): |
||
| 756 | """Create a new host asset |
||
| 757 | |||
| 758 | Arguments: |
||
| 759 | name (str): Name for the new host asset |
||
| 760 | comment (str, optional): Comment for the new host asset |
||
| 761 | |||
| 762 | Returns: |
||
| 763 | The response. See :py:meth:`send_command` for details. |
||
| 764 | """ |
||
| 765 | if not name: |
||
| 766 | raise RequiredArgument('create_host requires name argument') |
||
| 767 | |||
| 768 | cmd = XmlCommand('create_asset') |
||
| 769 | asset = cmd.add_element('asset') |
||
| 770 | asset.add_element('type', 'host') # ignored for gmp7, required for gmp8 |
||
| 771 | asset.add_element('name', name) |
||
| 772 | |||
| 773 | if comment: |
||
| 774 | asset.add_element('comment', comment) |
||
| 775 | |||
| 776 | return self._send_xml_command(cmd) |
||
| 777 | |||
| 778 | def create_note(self, text, nvt_oid, *, seconds_active=None, comment=None, |
||
| 779 | hosts=None, result_id=None, severity=None, task_id=None, |
||
| 780 | threat=None, port=None): |
||
| 781 | """Create a new note |
||
| 782 | |||
| 783 | Arguments: |
||
| 784 | text (str): Text of the new note |
||
| 785 | nvt_id (str): OID of the nvt to which note applies |
||
| 786 | seconds_active (int, optional): Seconds note will be active. -1 on |
||
| 787 | always, 0 off |
||
| 788 | comment (str, optional): Comment for the note |
||
| 789 | hosts (list, optional): A list of hosts addresses |
||
| 790 | port (str, optional): Port to which the note applies |
||
| 791 | result_id (str, optional): UUID of a result to which note applies |
||
| 792 | severity (decimal, optional): Severity to which note applies |
||
| 793 | task_id (str, optional): UUID of task to which note applies |
||
| 794 | threat (str, optional): Threat level to which note applies. Will be |
||
| 795 | converted to severity |
||
| 796 | |||
| 797 | Returns: |
||
| 798 | The response. See :py:meth:`send_command` for details. |
||
| 799 | """ |
||
| 800 | if not text: |
||
| 801 | raise RequiredArgument('create_note requires a text argument') |
||
| 802 | |||
| 803 | if not nvt_oid: |
||
| 804 | raise RequiredArgument('create_note requires a nvt_oid argument') |
||
| 805 | |||
| 806 | cmd = XmlCommand('create_note') |
||
| 807 | cmd.add_element('text', text) |
||
| 808 | cmd.add_element('nvt', attrs={"oid": nvt_oid}) |
||
| 809 | |||
| 810 | if not seconds_active is None: |
||
| 811 | cmd.add_element('active', str(seconds_active)) |
||
| 812 | |||
| 813 | if comment: |
||
| 814 | cmd.add_element('comment', comment) |
||
| 815 | |||
| 816 | if hosts: |
||
| 817 | cmd.add_element('hosts', ', '.join(hosts)) |
||
| 818 | |||
| 819 | if port: |
||
| 820 | cmd.add_element('port', port) |
||
| 821 | |||
| 822 | if result_id: |
||
| 823 | cmd.add_element('result', attrs={'id': result_id}) |
||
| 824 | |||
| 825 | if severity: |
||
| 826 | cmd.add_element('severity', severity) |
||
| 827 | |||
| 828 | if task_id: |
||
| 829 | cmd.add_element('task', attrs={'id': task_id}) |
||
| 830 | |||
| 831 | if threat: |
||
| 832 | cmd.add_element('threat', threat) |
||
| 833 | |||
| 834 | return self._send_xml_command(cmd) |
||
| 835 | |||
| 836 | def clone_note(self, note_id): |
||
| 837 | """Clone an existing note |
||
| 838 | |||
| 839 | Arguments: |
||
| 840 | copy (str): UUID of an existing note to clone from |
||
| 841 | |||
| 842 | Returns: |
||
| 843 | The response. See :py:meth:`send_command` for details. |
||
| 844 | """ |
||
| 845 | if not note_id: |
||
| 846 | raise RequiredArgument('clone_note requires a note_id argument') |
||
| 847 | |||
| 848 | cmd = XmlCommand('create_note') |
||
| 849 | cmd.add_element('copy', note_id) |
||
| 850 | return self._send_xml_command(cmd) |
||
| 851 | |||
| 852 | View Code Duplication | def create_override(self, text, nvt_oid, *, seconds_active=None, hosts=None, |
|
| 853 | port=None, result_id=None, severity=None, comment=None, |
||
| 854 | new_severity=None, task_id=None, threat=None, |
||
| 855 | new_threat=None): |
||
| 856 | """Create a new override |
||
| 857 | |||
| 858 | Arguments: |
||
| 859 | text (str): Text of the new override |
||
| 860 | nvt_id (str): OID of the nvt to which override applies |
||
| 861 | seconds_active (int, optional): Seconds override will be active. |
||
| 862 | -1 on always, 0 off |
||
| 863 | comment (str, optional): Comment for the override |
||
| 864 | hosts (list, optional): A list of host addresses |
||
| 865 | port (str, optional): Port to which the override applies |
||
| 866 | result_id (str, optional): UUID of a result to which override |
||
| 867 | applies |
||
| 868 | severity (decimal, optional): Severity to which override applies |
||
| 869 | new_severity (decimal, optional): New severity for result |
||
| 870 | task_id (str, optional): UUID of task to which override applies |
||
| 871 | threat (str, optional): Threat level to which override applies. Will |
||
| 872 | be converted to severity |
||
| 873 | new_threat (str, optional): New threat level for result, will be |
||
| 874 | converted to a new_severity |
||
| 875 | |||
| 876 | Returns: |
||
| 877 | The response. See :py:meth:`send_command` for details. |
||
| 878 | """ |
||
| 879 | if not text: |
||
| 880 | raise RequiredArgument('create_override requires a text argument') |
||
| 881 | |||
| 882 | if not nvt_oid: |
||
| 883 | raise RequiredArgument('create_override requires a nvt_oid ' |
||
| 884 | 'argument') |
||
| 885 | |||
| 886 | cmd = XmlCommand('create_override') |
||
| 887 | cmd.add_element('text', text) |
||
| 888 | cmd.add_element('nvt', attrs={'oid': nvt_oid}) |
||
| 889 | |||
| 890 | if not seconds_active is None: |
||
| 891 | cmd.add_element('active', str(seconds_active)) |
||
| 892 | |||
| 893 | if comment: |
||
| 894 | cmd.add_element('comment', comment) |
||
| 895 | |||
| 896 | if hosts: |
||
| 897 | cmd.add_element('hosts', ', '.join(hosts)) |
||
| 898 | |||
| 899 | if port: |
||
| 900 | cmd.add_element('port', port) |
||
| 901 | |||
| 902 | if result_id: |
||
| 903 | cmd.add_element('result', attrs={'id': result_id}) |
||
| 904 | |||
| 905 | if severity: |
||
| 906 | cmd.add_element('severity', severity) |
||
| 907 | |||
| 908 | if new_severity: |
||
| 909 | cmd.add_element('new_severity', new_severity) |
||
| 910 | |||
| 911 | if task_id: |
||
| 912 | cmd.add_element('task', attrs={'id': task_id}) |
||
| 913 | |||
| 914 | if threat: |
||
| 915 | cmd.add_element('threat', threat) |
||
| 916 | |||
| 917 | if new_threat: |
||
| 918 | cmd.add_element('new_threat', new_threat) |
||
| 919 | |||
| 920 | return self._send_xml_command(cmd) |
||
| 921 | |||
| 922 | def clone_override(self, override_id): |
||
| 923 | """Clone an existing override |
||
| 924 | |||
| 925 | Arguments: |
||
| 926 | copy (str): UUID of an existing override to clone from |
||
| 927 | |||
| 928 | Returns: |
||
| 929 | The response. See :py:meth:`send_command` for details. |
||
| 930 | """ |
||
| 931 | if not override_id: |
||
| 932 | raise RequiredArgument( |
||
| 933 | 'clone_override requires a override_id argument') |
||
| 934 | |||
| 935 | cmd = XmlCommand('create_override') |
||
| 936 | cmd.add_element('copy', override_id) |
||
| 937 | return self._send_xml_command(cmd) |
||
| 938 | |||
| 939 | def create_permission(self, name, subject_id, subject_type, *, |
||
| 940 | resource_id=None, resource_type=None, |
||
| 941 | comment=None): |
||
| 942 | """Create a new permission |
||
| 943 | |||
| 944 | Arguments: |
||
| 945 | name (str): Name of the new permission |
||
| 946 | subject_id (str): UUID of subject to whom the permission is granted |
||
| 947 | subject_type (str): Type of the subject user, group or role |
||
| 948 | comment (str, optional): Comment for the permission |
||
| 949 | resource_id (str, optional): UUID of entity to which the permission |
||
| 950 | applies |
||
| 951 | resource_type (str, optional): Type of the resource. For Super |
||
| 952 | permissions user, group or role |
||
| 953 | |||
| 954 | Returns: |
||
| 955 | The response. See :py:meth:`send_command` for details. |
||
| 956 | """ |
||
| 957 | if not name: |
||
| 958 | raise RequiredArgument('create_permission requires a name argument') |
||
| 959 | |||
| 960 | if not subject_id: |
||
| 961 | raise RequiredArgument( |
||
| 962 | 'create_permission requires a subject_id argument') |
||
| 963 | |||
| 964 | if subject_type not in ('user', 'group', 'role'): |
||
| 965 | raise InvalidArgument( |
||
| 966 | 'create_permission requires subject_type to be either user, ' |
||
| 967 | 'group or role') |
||
| 968 | |||
| 969 | cmd = XmlCommand('create_permission') |
||
| 970 | cmd.add_element('name', name) |
||
| 971 | |||
| 972 | _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id}) |
||
| 973 | _xmlsubject.add_element('type', subject_type) |
||
| 974 | |||
| 975 | if comment: |
||
| 976 | cmd.add_element('comment', comment) |
||
| 977 | |||
| 978 | if resource_id or resource_type: |
||
| 979 | if not resource_id: |
||
| 980 | raise RequiredArgument( |
||
| 981 | 'create_permission requires resource_id for resource_type') |
||
| 982 | |||
| 983 | if not resource_type: |
||
| 984 | raise RequiredArgument( |
||
| 985 | 'create_permission requires resource_type for resource_id') |
||
| 986 | |||
| 987 | _xmlresource = cmd.add_element('resource', |
||
| 988 | attrs={'id': resource_id}) |
||
| 989 | _xmlresource.add_element('type', resource_type) |
||
| 990 | |||
| 991 | |||
| 992 | return self._send_xml_command(cmd) |
||
| 993 | |||
| 994 | def clone_permission(self, permission_id): |
||
| 995 | """Clone an existing permission |
||
| 996 | |||
| 997 | Arguments: |
||
| 998 | copy (str): UUID of an existing permission to clone from |
||
| 999 | |||
| 1000 | Returns: |
||
| 1001 | The response. See :py:meth:`send_command` for details. |
||
| 1002 | """ |
||
| 1003 | if not permission_id: |
||
| 1004 | raise RequiredArgument( |
||
| 1005 | 'clone_permission requires a permission_id argument') |
||
| 1006 | |||
| 1007 | cmd = XmlCommand('create_permission') |
||
| 1008 | cmd.add_element('copy', permission_id) |
||
| 1009 | return self._send_xml_command(cmd) |
||
| 1010 | |||
| 1011 | def create_port_list(self, name, port_range, *, comment=None): |
||
| 1012 | """Create a new port list |
||
| 1013 | |||
| 1014 | Arguments: |
||
| 1015 | name (str): Name of the new port list |
||
| 1016 | port_range (str): Port list ranges e.g. `"T: 1-1234"` for tcp port |
||
| 1017 | 1 - 1234 |
||
| 1018 | comment (str, optional): Comment for the port list |
||
| 1019 | |||
| 1020 | Returns: |
||
| 1021 | The response. See :py:meth:`send_command` for details. |
||
| 1022 | """ |
||
| 1023 | if not name: |
||
| 1024 | raise RequiredArgument('create_port_list requires a name argument') |
||
| 1025 | |||
| 1026 | if not port_range: |
||
| 1027 | raise RequiredArgument( |
||
| 1028 | 'create_port_list requires a port_range argument') |
||
| 1029 | |||
| 1030 | cmd = XmlCommand('create_port_list') |
||
| 1031 | cmd.add_element('name', name) |
||
| 1032 | cmd.add_element('port_range', port_range) |
||
| 1033 | |||
| 1034 | if comment: |
||
| 1035 | cmd.add_element('comment', comment) |
||
| 1036 | |||
| 1037 | return self._send_xml_command(cmd) |
||
| 1038 | |||
| 1039 | def clone_port_list(self, port_list_id): |
||
| 1040 | """Clone an existing port list |
||
| 1041 | |||
| 1042 | Arguments: |
||
| 1043 | copy (str): UUID of an existing port list to clone from |
||
| 1044 | |||
| 1045 | Returns: |
||
| 1046 | The response. See :py:meth:`send_command` for details. |
||
| 1047 | """ |
||
| 1048 | if not port_list_id: |
||
| 1049 | raise RequiredArgument( |
||
| 1050 | 'clone_port_list requires a port_list_id argument') |
||
| 1051 | |||
| 1052 | cmd = XmlCommand('create_port_list') |
||
| 1053 | cmd.add_element('copy', port_list_id) |
||
| 1054 | return self._send_xml_command(cmd) |
||
| 1055 | |||
| 1056 | def create_port_range(self, port_list_id, start, end, port_range_type, |
||
| 1057 | *, comment=None): |
||
| 1058 | """Create new port range |
||
| 1059 | |||
| 1060 | Arguments: |
||
| 1061 | port_list_id (str): UUID of the port list to which to add the range |
||
| 1062 | start (int): The first port in the range |
||
| 1063 | end (int): The last port in the range |
||
| 1064 | port_range_type (str): The type of the ports: TCP, UDP, ... |
||
| 1065 | comment (str, optional): Comment for the port range |
||
| 1066 | |||
| 1067 | Returns: |
||
| 1068 | The response. See :py:meth:`send_command` for details. |
||
| 1069 | """ |
||
| 1070 | if not port_list_id: |
||
| 1071 | raise RequiredArgument('create_port_range requires ' |
||
| 1072 | 'a port_list_id argument') |
||
| 1073 | |||
| 1074 | if not port_range_type: |
||
| 1075 | raise RequiredArgument( |
||
| 1076 | 'create_port_range requires a port_range_type argument') |
||
| 1077 | |||
| 1078 | if not start: |
||
| 1079 | raise RequiredArgument( |
||
| 1080 | 'create_port_range requires a start argument') |
||
| 1081 | |||
| 1082 | if not end: |
||
| 1083 | raise RequiredArgument( |
||
| 1084 | 'create_port_range requires a end argument') |
||
| 1085 | |||
| 1086 | cmd = XmlCommand('create_port_range') |
||
| 1087 | cmd.add_element('port_list', attrs={'id': port_list_id}) |
||
| 1088 | cmd.add_element('start', start) |
||
| 1089 | cmd.add_element('end', end) |
||
| 1090 | cmd.add_element('type', port_range_type) |
||
| 1091 | |||
| 1092 | if comment: |
||
| 1093 | cmd.add_element('comment', comment) |
||
| 1094 | |||
| 1095 | return self._send_xml_command(cmd) |
||
| 1096 | |||
| 1097 | def import_report(self, report, *, task_id=None, task_name=None, |
||
| 1098 | task_comment=None, in_assets=None): |
||
| 1099 | """Import a Report from XML |
||
| 1100 | |||
| 1101 | Arguments: |
||
| 1102 | report (str): Report XML as string to import. This XML must contain |
||
| 1103 | a :code:`<report>` root element. |
||
| 1104 | task_id (str, optional): UUID of task to import report to |
||
| 1105 | task_name (str, optional): Name of task to be created if task_id is |
||
| 1106 | not present. Either task_id or task_name must be passed |
||
| 1107 | task_comment (str, optional): Comment for task to be created if |
||
| 1108 | task_id is not present |
||
| 1109 | in_asset (boolean, optional): Whether to create or update assets |
||
| 1110 | using the report |
||
| 1111 | |||
| 1112 | Returns: |
||
| 1113 | The response. See :py:meth:`send_command` for details. |
||
| 1114 | """ |
||
| 1115 | if not report: |
||
| 1116 | raise RequiredArgument('create_report requires a report argument') |
||
| 1117 | |||
| 1118 | cmd = XmlCommand('create_report') |
||
| 1119 | |||
| 1120 | if task_id: |
||
| 1121 | cmd.add_element('task', attrs={'id': task_id}) |
||
| 1122 | elif task_name: |
||
| 1123 | _xmltask = cmd.add_element('task') |
||
| 1124 | _xmltask.add_element('name', task_name) |
||
| 1125 | |||
| 1126 | if task_comment: |
||
| 1127 | _xmltask.add_element('comment', task_comment) |
||
| 1128 | else: |
||
| 1129 | raise RequiredArgument( |
||
| 1130 | 'import_report requires a task_id or task_name argument') |
||
| 1131 | |||
| 1132 | if not in_assets is None: |
||
| 1133 | cmd.add_element('in_assets', _to_bool(in_assets)) |
||
| 1134 | |||
| 1135 | try: |
||
| 1136 | cmd.append_xml_str(report) |
||
| 1137 | except etree.XMLSyntaxError as e: |
||
| 1138 | raise InvalidArgument( |
||
| 1139 | 'Invalid xml passed as report to import_report', e) |
||
| 1140 | |||
| 1141 | return self._send_xml_command(cmd) |
||
| 1142 | |||
| 1143 | def create_role(self, name, *, comment=None, users=None): |
||
| 1144 | """Create a new role |
||
| 1145 | |||
| 1146 | Arguments: |
||
| 1147 | name (str): Name of the role |
||
| 1148 | comment (str, optional): Comment for the role |
||
| 1149 | users (list, optional): List of user names to add to the role |
||
| 1150 | |||
| 1151 | Returns: |
||
| 1152 | The response. See :py:meth:`send_command` for details. |
||
| 1153 | """ |
||
| 1154 | |||
| 1155 | if not name: |
||
| 1156 | raise RequiredArgument('create_role requires a name argument') |
||
| 1157 | |||
| 1158 | cmd = XmlCommand('create_role') |
||
| 1159 | cmd.add_element('name', name) |
||
| 1160 | |||
| 1161 | if comment: |
||
| 1162 | cmd.add_element('comment', comment) |
||
| 1163 | |||
| 1164 | if users: |
||
| 1165 | cmd.add_element('users', ",".join(users)) |
||
| 1166 | |||
| 1167 | return self._send_xml_command(cmd) |
||
| 1168 | |||
| 1169 | def clone_role(self, role_id): |
||
| 1170 | """Clone an existing role |
||
| 1171 | |||
| 1172 | Arguments: |
||
| 1173 | copy (str): UUID of an existing role to clone from |
||
| 1174 | |||
| 1175 | Returns: |
||
| 1176 | The response. See :py:meth:`send_command` for details. |
||
| 1177 | """ |
||
| 1178 | if not role_id: |
||
| 1179 | raise RequiredArgument('clone_role requires a role_id argument') |
||
| 1180 | |||
| 1181 | cmd = XmlCommand('create_role') |
||
| 1182 | cmd.add_element('copy', role_id) |
||
| 1183 | return self._send_xml_command(cmd) |
||
| 1184 | |||
| 1185 | View Code Duplication | def create_scanner(self, name, host, port, scanner_type, ca_pub, |
|
| 1186 | credential_id, *, comment=None): |
||
| 1187 | """Create a new scanner |
||
| 1188 | |||
| 1189 | Arguments: |
||
| 1190 | name (str): Name of the scanner |
||
| 1191 | host (str): The host of the scanner |
||
| 1192 | port (str): The port of the scanner |
||
| 1193 | scanner_type (str): Type of the scanner. |
||
| 1194 | '1' for OSP, '2' for OpenVAS (classic) Scanner. |
||
| 1195 | ca_pub (str): Certificate of CA to verify scanner certificate |
||
| 1196 | credential_id (str): UUID of client certificate credential for the |
||
| 1197 | scanner |
||
| 1198 | comment (str, optional): Comment for the scanner |
||
| 1199 | |||
| 1200 | Returns: |
||
| 1201 | The response. See :py:meth:`send_command` for details. |
||
| 1202 | """ |
||
| 1203 | if not name: |
||
| 1204 | raise RequiredArgument('create_scanner requires a name argument') |
||
| 1205 | |||
| 1206 | if not host: |
||
| 1207 | raise RequiredArgument('create_scanner requires a host argument') |
||
| 1208 | |||
| 1209 | if not port: |
||
| 1210 | raise RequiredArgument('create_scanner requires a port argument') |
||
| 1211 | |||
| 1212 | if not scanner_type: |
||
| 1213 | raise RequiredArgument('create_scanner requires a scanner_type ' |
||
| 1214 | 'argument') |
||
| 1215 | if not ca_pub: |
||
| 1216 | raise RequiredArgument('create_scanner requires a ca_pub argument') |
||
| 1217 | |||
| 1218 | if not credential_id: |
||
| 1219 | raise RequiredArgument('create_scanner requires a credential_id ' |
||
| 1220 | 'argument') |
||
| 1221 | |||
| 1222 | if scanner_type not in SCANNER_TYPES: |
||
| 1223 | raise InvalidArgument('create_scanner requires a scanner_type ' |
||
| 1224 | 'argument which must be either "1" for OSP ' |
||
| 1225 | 'or "2" OpenVAS (Classic).') |
||
| 1226 | |||
| 1227 | cmd = XmlCommand('create_scanner') |
||
| 1228 | cmd.add_element('name', name) |
||
| 1229 | cmd.add_element('host', host) |
||
| 1230 | cmd.add_element('port', port) |
||
| 1231 | cmd.add_element('type', scanner_type) |
||
| 1232 | cmd.add_element('ca_pub', ca_pub) |
||
| 1233 | cmd.add_element('credential', attrs={'id': str(credential_id)}) |
||
| 1234 | |||
| 1235 | if comment: |
||
| 1236 | cmd.add_element('comment', comment) |
||
| 1237 | |||
| 1238 | return self._send_xml_command(cmd) |
||
| 1239 | |||
| 1240 | def clone_scanner(self, scanner_id): |
||
| 1241 | """Clone an existing scanner |
||
| 1242 | |||
| 1243 | Arguments: |
||
| 1244 | copy (str): UUID of an existing scanner to clone from |
||
| 1245 | |||
| 1246 | Returns: |
||
| 1247 | The response. See :py:meth:`send_command` for details. |
||
| 1248 | """ |
||
| 1249 | if not scanner_id: |
||
| 1250 | raise RequiredArgument( |
||
| 1251 | 'clone_scanner requires a scanner_id argument') |
||
| 1252 | |||
| 1253 | cmd = XmlCommand('create_scanner') |
||
| 1254 | cmd.add_element('copy', scanner_id) |
||
| 1255 | return self._send_xml_command(cmd) |
||
| 1256 | |||
| 1257 | def create_schedule(self, name, *, comment=None, first_time_minute=None, |
||
| 1258 | first_time_hour=None, first_time_day_of_month=None, |
||
| 1259 | first_time_month=None, first_time_year=None, |
||
| 1260 | duration=None, duration_unit=None, period=None, |
||
| 1261 | period_unit=None, timezone=None): |
||
| 1262 | """Create a new schedule |
||
| 1263 | |||
| 1264 | Arguments: |
||
| 1265 | name (str): Name of the schedule |
||
| 1266 | comment (str, optional): Comment for the schedule |
||
| 1267 | first_time_minute (int, optional): First time minute the schedule |
||
| 1268 | will run |
||
| 1269 | first_time_hour (int, optional): First time hour the schedule |
||
| 1270 | will run |
||
| 1271 | first_time_day_of_month (int, optional): First time day of month the |
||
| 1272 | schedule will run |
||
| 1273 | first_time_month (int, optional): First time month the schedule |
||
| 1274 | will run |
||
| 1275 | first_time_year (int, optional): First time year the schedule |
||
| 1276 | will run |
||
| 1277 | duration (int, optional): How long the Manager will run the |
||
| 1278 | scheduled task for until it gets paused if not finished yet. |
||
| 1279 | duration_unit (str, optional): Unit of the duration. One of second, |
||
| 1280 | minute, hour, day, week, month, year, decade. Required if |
||
| 1281 | duration is set. |
||
| 1282 | period (int, optional): How often the Manager will repeat the |
||
| 1283 | scheduled task |
||
| 1284 | period_unit (str, optional): Unit of the period. One of second, |
||
| 1285 | minute, hour, day, week, month, year, decade. Required if |
||
| 1286 | period is set. |
||
| 1287 | timezone (str, optional): The timezone the schedule will follow |
||
| 1288 | |||
| 1289 | Returns: |
||
| 1290 | The response. See :py:meth:`send_command` for details. |
||
| 1291 | """ |
||
| 1292 | if not name: |
||
| 1293 | raise RequiredArgument('create_schedule requires a name argument') |
||
| 1294 | |||
| 1295 | cmd = XmlCommand('create_schedule') |
||
| 1296 | cmd.add_element('name', name) |
||
| 1297 | |||
| 1298 | if comment: |
||
| 1299 | cmd.add_element('comment', comment) |
||
| 1300 | |||
| 1301 | View Code Duplication | if first_time_minute or first_time_hour or first_time_day_of_month or \ |
|
| 1302 | first_time_month or first_time_year: |
||
| 1303 | |||
| 1304 | if not first_time_minute: |
||
| 1305 | raise RequiredArgument( |
||
| 1306 | 'Setting first_time requires first_time_minute argument') |
||
| 1307 | if not first_time_hour: |
||
| 1308 | raise RequiredArgument( |
||
| 1309 | 'Setting first_time requires first_time_hour argument') |
||
| 1310 | if not first_time_day_of_month: |
||
| 1311 | raise RequiredArgument( |
||
| 1312 | 'Setting first_time requires first_time_day_of_month ' |
||
| 1313 | 'argument') |
||
| 1314 | if not first_time_month: |
||
| 1315 | raise RequiredArgument( |
||
| 1316 | 'Setting first_time requires first_time_month argument') |
||
| 1317 | if not first_time_year: |
||
| 1318 | raise RequiredArgument( |
||
| 1319 | 'Setting first_time requires first_time_year argument') |
||
| 1320 | |||
| 1321 | _xmlftime = cmd.add_element('first_time') |
||
| 1322 | _xmlftime.add_element('minute', str(first_time_minute)) |
||
| 1323 | _xmlftime.add_element('hour', str(first_time_hour)) |
||
| 1324 | _xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
||
| 1325 | _xmlftime.add_element('month', str(first_time_month)) |
||
| 1326 | _xmlftime.add_element('year', str(first_time_year)) |
||
| 1327 | |||
| 1328 | View Code Duplication | if duration: |
|
| 1329 | if not duration_unit: |
||
| 1330 | raise RequiredArgument( |
||
| 1331 | 'Setting duration requires duration_unit argument') |
||
| 1332 | |||
| 1333 | if not duration_unit in TIME_UNITS: |
||
| 1334 | raise InvalidArgument( |
||
| 1335 | 'duration_unit must be one of {units} but {actual} has ' |
||
| 1336 | 'been passed'.format( |
||
| 1337 | units=', '.join(TIME_UNITS), actual=duration_unit)) |
||
| 1338 | |||
| 1339 | _xmlduration = cmd.add_element('duration', str(duration)) |
||
| 1340 | _xmlduration.add_element('unit', duration_unit) |
||
| 1341 | |||
| 1342 | View Code Duplication | if period: |
|
| 1343 | if not period_unit: |
||
| 1344 | raise RequiredArgument( |
||
| 1345 | 'Setting period requires period_unit argument') |
||
| 1346 | |||
| 1347 | if not period_unit in TIME_UNITS: |
||
| 1348 | raise InvalidArgument( |
||
| 1349 | 'period_unit must be one of {units} but {actual} has ' |
||
| 1350 | 'been passed'.format( |
||
| 1351 | units=', '.join(TIME_UNITS), actual=period_unit)) |
||
| 1352 | |||
| 1353 | _xmlperiod = cmd.add_element('period', str(period)) |
||
| 1354 | _xmlperiod.add_element('unit', period_unit) |
||
| 1355 | |||
| 1356 | if timezone: |
||
| 1357 | cmd.add_element('timezone', timezone) |
||
| 1358 | |||
| 1359 | return self._send_xml_command(cmd) |
||
| 1360 | |||
| 1361 | def clone_schedule(self, schedule_id): |
||
| 1362 | """Clone an existing schedule |
||
| 1363 | |||
| 1364 | Arguments: |
||
| 1365 | copy (str): UUID of an existing schedule to clone from |
||
| 1366 | |||
| 1367 | Returns: |
||
| 1368 | The response. See :py:meth:`send_command` for details. |
||
| 1369 | """ |
||
| 1370 | if not schedule_id: |
||
| 1371 | raise RequiredArgument( |
||
| 1372 | 'clone_schedule requires a schedule_id argument') |
||
| 1373 | |||
| 1374 | cmd = XmlCommand('create_schedule') |
||
| 1375 | cmd.add_element('copy', schedule_id) |
||
| 1376 | return self._send_xml_command(cmd) |
||
| 1377 | |||
| 1378 | def create_tag(self, name, resource_id, resource_type, *, value=None, |
||
| 1379 | comment=None, active=None): |
||
| 1380 | """Create a new tag |
||
| 1381 | |||
| 1382 | Arguments: |
||
| 1383 | name (str): Name of the tag. A full tag name consisting of namespace |
||
| 1384 | and predicate e.g. `foo:bar`. |
||
| 1385 | resource_id (str): ID of the resource the tag is to be attached to. |
||
| 1386 | resource_type (str): Entity type the tag is to be attached to |
||
| 1387 | value (str, optional): Value associated with the tag |
||
| 1388 | comment (str, optional): Comment for the tag |
||
| 1389 | active (boolean, optional): Whether the tag should be active |
||
| 1390 | |||
| 1391 | Returns: |
||
| 1392 | The response. See :py:meth:`send_command` for details. |
||
| 1393 | """ |
||
| 1394 | cmd = XmlCommand('create_tag') |
||
| 1395 | cmd.add_element('name', name) |
||
| 1396 | _xmlresource = cmd.add_element('resource', |
||
| 1397 | attrs={'id': str(resource_id)}) |
||
| 1398 | _xmlresource.add_element('type', resource_type) |
||
| 1399 | |||
| 1400 | if comment: |
||
| 1401 | cmd.add_element('comment', comment) |
||
| 1402 | |||
| 1403 | if value: |
||
| 1404 | cmd.add_element('value', value) |
||
| 1405 | |||
| 1406 | if not active is None: |
||
| 1407 | if active: |
||
| 1408 | cmd.add_element('active', '1') |
||
| 1409 | else: |
||
| 1410 | cmd.add_element('active', '0') |
||
| 1411 | |||
| 1412 | return self._send_xml_command(cmd) |
||
| 1413 | |||
| 1414 | def clone_tag(self, tag_id): |
||
| 1415 | """Clone an existing tag |
||
| 1416 | |||
| 1417 | Arguments: |
||
| 1418 | copy (str): UUID of an existing tag to clone from |
||
| 1419 | |||
| 1420 | Returns: |
||
| 1421 | The response. See :py:meth:`send_command` for details. |
||
| 1422 | """ |
||
| 1423 | if not tag_id: |
||
| 1424 | raise RequiredArgument('clone_tag requires a tag_id argument') |
||
| 1425 | |||
| 1426 | cmd = XmlCommand('create_tag') |
||
| 1427 | cmd.add_element('copy', tag_id) |
||
| 1428 | return self._send_xml_command(cmd) |
||
| 1429 | |||
| 1430 | def create_target(self, name, *, make_unique=False, asset_hosts_filter=None, |
||
| 1431 | hosts=None, comment=None, exclude_hosts=None, |
||
| 1432 | ssh_credential_id=None, ssh_credential_port=None, |
||
| 1433 | smb_credential_id=None, esxi_credential_id=None, |
||
| 1434 | snmp_credential_id=None, alive_tests=None, |
||
| 1435 | reverse_lookup_only=None, reverse_lookup_unify=None, |
||
| 1436 | port_range=None, port_list_id=None): |
||
| 1437 | """Create a new target |
||
| 1438 | |||
| 1439 | Arguments: |
||
| 1440 | name (str): Name of the target |
||
| 1441 | make_unique (boolean, optional): Append a unique suffix if the name |
||
| 1442 | already exists |
||
| 1443 | asset_hosts_filter (str, optional): Filter to select target host |
||
| 1444 | from assets hosts |
||
| 1445 | hosts (list, optional): List of hosts addresses to scan |
||
| 1446 | exclude_hosts (list, optional): List of hosts addresses to exclude |
||
| 1447 | from scan |
||
| 1448 | comment (str, optional): Comment for the target |
||
| 1449 | ssh_credential_id (str, optional): UUID of a ssh credential to use |
||
| 1450 | on target |
||
| 1451 | ssh_credential_port (str, optional): The port to use for ssh |
||
| 1452 | credential |
||
| 1453 | smb_credential_id (str, optional): UUID of a smb credential to use |
||
| 1454 | on target |
||
| 1455 | snmp_credential_id (str, optional): UUID of a snmp credential to use |
||
| 1456 | on target |
||
| 1457 | esxi_credential_id (str, optional): UUID of a esxi credential to use |
||
| 1458 | on target |
||
| 1459 | alive_tests (str, optional): Which alive tests to use |
||
| 1460 | reverse_lookup_only (boolean, optional): Whether to scan only hosts |
||
| 1461 | that have names |
||
| 1462 | reverse_lookup_unify (boolean, optional): Whether to scan only one |
||
| 1463 | IP when multiple IPs have the same name. |
||
| 1464 | port_range (str, optional): Port range for the target |
||
| 1465 | port_list_id (str, optional): UUID of the port list to use on target |
||
| 1466 | |||
| 1467 | Returns: |
||
| 1468 | The response. See :py:meth:`send_command` for details. |
||
| 1469 | """ |
||
| 1470 | if not name: |
||
| 1471 | raise RequiredArgument('create_target requires a name argument') |
||
| 1472 | |||
| 1473 | cmd = XmlCommand('create_target') |
||
| 1474 | _xmlname = cmd.add_element('name', name) |
||
| 1475 | if make_unique: |
||
| 1476 | _xmlname.add_element('make_unique', '1') |
||
| 1477 | |||
| 1478 | if asset_hosts_filter: |
||
| 1479 | cmd.add_element('asset_hosts', |
||
| 1480 | attrs={'filter': str(asset_hosts_filter)}) |
||
| 1481 | elif hosts: |
||
| 1482 | cmd.add_element('hosts', ', '.join(hosts)) |
||
| 1483 | else: |
||
| 1484 | raise RequiredArgument('create_target requires either a hosts or ' |
||
| 1485 | 'an asset_hosts_filter argument') |
||
| 1486 | |||
| 1487 | if comment: |
||
| 1488 | cmd.add_element('comment', comment) |
||
| 1489 | |||
| 1490 | if exclude_hosts: |
||
| 1491 | cmd.add_element('exclude_hosts', ', '.join(exclude_hosts)) |
||
| 1492 | |||
| 1493 | if ssh_credential_id: |
||
| 1494 | _xmlssh = cmd.add_element('ssh_credential', |
||
| 1495 | attrs={'id': ssh_credential_id}) |
||
| 1496 | if ssh_credential_port: |
||
| 1497 | _xmlssh.add_element('port', ssh_credential_port) |
||
| 1498 | |||
| 1499 | if smb_credential_id: |
||
| 1500 | cmd.add_element('smb_credential', attrs={'id': smb_credential_id}) |
||
| 1501 | |||
| 1502 | if esxi_credential_id: |
||
| 1503 | cmd.add_element('esxi_credential', attrs={'id': esxi_credential_id}) |
||
| 1504 | |||
| 1505 | if snmp_credential_id: |
||
| 1506 | cmd.add_element('snmp_credential', attrs={'id': snmp_credential_id}) |
||
| 1507 | |||
| 1508 | if alive_tests: |
||
| 1509 | cmd.add_element('alive_tests', alive_tests) |
||
| 1510 | |||
| 1511 | if not reverse_lookup_only is None: |
||
| 1512 | if reverse_lookup_only: |
||
| 1513 | cmd.add_element('reverse_lookup_only', '1') |
||
| 1514 | else: |
||
| 1515 | cmd.add_element('reverse_lookup_only', '0') |
||
| 1516 | |||
| 1517 | if not reverse_lookup_unify is None: |
||
| 1518 | if reverse_lookup_unify: |
||
| 1519 | cmd.add_element('reverse_lookup_unify', '1') |
||
| 1520 | else: |
||
| 1521 | cmd.add_element('reverse_lookup_unify', '0') |
||
| 1522 | |||
| 1523 | if port_range: |
||
| 1524 | cmd.add_element('port_range', port_range) |
||
| 1525 | |||
| 1526 | if port_list_id: |
||
| 1527 | cmd.add_element('port_list', attrs={'id': port_list_id}) |
||
| 1528 | |||
| 1529 | return self._send_xml_command(cmd) |
||
| 1530 | |||
| 1531 | def clone_target(self, target_id): |
||
| 1532 | """Clone an existing target |
||
| 1533 | |||
| 1534 | Arguments: |
||
| 1535 | copy (str): UUID of an existing target to clone from |
||
| 1536 | |||
| 1537 | Returns: |
||
| 1538 | The response. See :py:meth:`send_command` for details. |
||
| 1539 | """ |
||
| 1540 | if not target_id: |
||
| 1541 | raise RequiredArgument('clone_target requires a target_id argument') |
||
| 1542 | |||
| 1543 | cmd = XmlCommand('create_target') |
||
| 1544 | cmd.add_element('copy', target_id) |
||
| 1545 | return self._send_xml_command(cmd) |
||
| 1546 | |||
| 1547 | def create_task(self, name, config_id, target_id, scanner_id, *, |
||
| 1548 | alterable=None, hosts_ordering=None, schedule_id=None, |
||
| 1549 | alert_ids=None, comment=None, schedule_periods=None, |
||
| 1550 | observers=None): |
||
| 1551 | """Create a new task |
||
| 1552 | |||
| 1553 | Arguments: |
||
| 1554 | name (str): Name of the task |
||
| 1555 | config_id (str): UUID of scan config to use by the task |
||
| 1556 | target_id (str): UUID of target to be scanned |
||
| 1557 | scanner_id (str): UUID of scanner to use for scanning the target |
||
| 1558 | comment (str, optional): Comment for the task |
||
| 1559 | alterable (boolean, optional): Whether the task should be alterable |
||
| 1560 | alert_ids (list, optional): List of UUIDs for alerts to be applied |
||
| 1561 | to the task |
||
| 1562 | hosts_ordering (str, optional): The order hosts are scanned in |
||
| 1563 | schedule_id (str, optional): UUID of a schedule when the task should |
||
| 1564 | be run. |
||
| 1565 | schedule_periods (int, optional): A limit to the number of times the |
||
| 1566 | task will be scheduled, or 0 for no limit |
||
| 1567 | observers (list, optional): List of user names which should be |
||
| 1568 | allowed to observe this task |
||
| 1569 | |||
| 1570 | Returns: |
||
| 1571 | The response. See :py:meth:`send_command` for details. |
||
| 1572 | """ |
||
| 1573 | if not name: |
||
| 1574 | raise RequiredArgument('create_task requires a name argument') |
||
| 1575 | |||
| 1576 | if not config_id: |
||
| 1577 | raise RequiredArgument('create_task requires a config_id argument') |
||
| 1578 | |||
| 1579 | if not target_id: |
||
| 1580 | raise RequiredArgument('create_task requires a target_id argument') |
||
| 1581 | |||
| 1582 | if not scanner_id: |
||
| 1583 | raise RequiredArgument('create_task requires a scanner_id argument') |
||
| 1584 | |||
| 1585 | cmd = XmlCommand('create_task') |
||
| 1586 | cmd.add_element('name', name) |
||
| 1587 | cmd.add_element('config', attrs={'id': config_id}) |
||
| 1588 | cmd.add_element('target', attrs={'id': target_id}) |
||
| 1589 | cmd.add_element('scanner', attrs={'id': scanner_id}) |
||
| 1590 | |||
| 1591 | if comment: |
||
| 1592 | cmd.add_element('comment', comment) |
||
| 1593 | |||
| 1594 | if not alterable is None: |
||
| 1595 | if alterable: |
||
| 1596 | cmd.add_element('alterable', '1') |
||
| 1597 | else: |
||
| 1598 | cmd.add_element('alterable', '0') |
||
| 1599 | |||
| 1600 | if hosts_ordering: |
||
| 1601 | cmd.add_element('hosts_ordering', hosts_ordering) |
||
| 1602 | |||
| 1603 | if alert_ids: |
||
| 1604 | if isinstance(alert_ids, str): |
||
| 1605 | logger.warning( |
||
| 1606 | 'Please pass a list as alert_ids parameter to create_task. ' |
||
| 1607 | 'Passing a string is deprecated and will be removed in ' |
||
| 1608 | 'future.') |
||
| 1609 | |||
| 1610 | #if a single id is given as a string wrap it into a list |
||
| 1611 | alert_ids = [alert_ids] |
||
| 1612 | if isinstance(alert_ids, list): |
||
| 1613 | #parse all given alert id's |
||
| 1614 | for alert in alert_ids: |
||
| 1615 | cmd.add_element('alert', attrs={'id': str(alert)}) |
||
| 1616 | |||
| 1617 | if schedule_id: |
||
| 1618 | cmd.add_element('schedule', schedule_id) |
||
| 1619 | |||
| 1620 | if schedule_periods: |
||
| 1621 | cmd.add_element('schedule_periods', str(schedule_periods)) |
||
| 1622 | |||
| 1623 | if observers: |
||
| 1624 | cmd.add_element('observers', ' '.join(observers)) |
||
| 1625 | |||
| 1626 | return self._send_xml_command(cmd) |
||
| 1627 | |||
| 1628 | def clone_task(self, task_id): |
||
| 1629 | """Clone an existing task |
||
| 1630 | |||
| 1631 | Arguments: |
||
| 1632 | task_id (str): UUID of existing task to clone from |
||
| 1633 | |||
| 1634 | Returns: |
||
| 1635 | The response. See :py:meth:`send_command` for details. |
||
| 1636 | """ |
||
| 1637 | if not task_id: |
||
| 1638 | raise RequiredArgument('clone_task requires a task_id argument') |
||
| 1639 | |||
| 1640 | cmd = XmlCommand('create_task') |
||
| 1641 | cmd.add_element('copy', task_id) |
||
| 1642 | return self._send_xml_command(cmd) |
||
| 1643 | |||
| 1644 | def create_user(self, name, *, password=None, hosts=None, hosts_allow=False, |
||
| 1645 | ifaces=None, ifaces_allow=False, role_ids=None): |
||
| 1646 | """Create a new user |
||
| 1647 | |||
| 1648 | Arguments: |
||
| 1649 | name (str): Name of the user |
||
| 1650 | password (str, optional): Password of the user |
||
| 1651 | hosts (list, optional): A list of host addresses (IPs, DNS names) |
||
| 1652 | hosts_allow (boolean, optional): If True allow only access to passed |
||
| 1653 | hosts otherwise deny access. Default is False for deny hosts. |
||
| 1654 | ifaces (list, optional): A list of interface names |
||
| 1655 | ifaces_allow (boolean, optional): If True allow only access to |
||
| 1656 | passed interfaces otherwise deny access. Default is False for |
||
| 1657 | deny interfaces. |
||
| 1658 | role_ids (list, optional): A list of role UUIDs for the user |
||
| 1659 | |||
| 1660 | Returns: |
||
| 1661 | The response. See :py:meth:`send_command` for details. |
||
| 1662 | """ |
||
| 1663 | if not name: |
||
| 1664 | raise RequiredArgument('create_user requires a name argument') |
||
| 1665 | |||
| 1666 | cmd = XmlCommand('create_user') |
||
| 1667 | cmd.add_element('name', name) |
||
| 1668 | |||
| 1669 | if password: |
||
| 1670 | cmd.add_element('password', password) |
||
| 1671 | |||
| 1672 | if hosts: |
||
| 1673 | cmd.add_element('hosts', ', '.join(hosts), |
||
| 1674 | attrs={'allow': '1' if hosts_allow else '0'}) |
||
| 1675 | |||
| 1676 | if ifaces: |
||
| 1677 | cmd.add_element('ifaces', ', '.join(ifaces), |
||
| 1678 | attrs={'allow': '1' if ifaces_allow else '0'}) |
||
| 1679 | |||
| 1680 | if role_ids: |
||
| 1681 | for role in role_ids: |
||
| 1682 | cmd.add_element('role', attrs={'id': role}) |
||
| 1683 | |||
| 1684 | return self._send_xml_command(cmd) |
||
| 1685 | |||
| 1686 | def clone_user(self, user_id): |
||
| 1687 | """Clone an existing user |
||
| 1688 | |||
| 1689 | Arguments: |
||
| 1690 | user_id (str): UUID of existing user to clone from |
||
| 1691 | |||
| 1692 | Returns: |
||
| 1693 | The response. See :py:meth:`send_command` for details. |
||
| 1694 | """ |
||
| 1695 | if not user_id: |
||
| 1696 | raise RequiredArgument('clone_user requires a user_id argument') |
||
| 1697 | |||
| 1698 | cmd = XmlCommand('create_user') |
||
| 1699 | cmd.add_element('copy', user_id) |
||
| 1700 | return self._send_xml_command(cmd) |
||
| 1701 | |||
| 1702 | def delete_agent(self, agent_id, *, ultimate=False): |
||
| 1703 | """Deletes an existing agent |
||
| 1704 | |||
| 1705 | Arguments: |
||
| 1706 | agent_id (str) UUID of the agent to be deleted. |
||
| 1707 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1708 | or to the trashcan. |
||
| 1709 | """ |
||
| 1710 | if not agent_id: |
||
| 1711 | raise RequiredArgument('delete_agent requires an agent_id argument') |
||
| 1712 | |||
| 1713 | cmd = XmlCommand('delete_agent') |
||
| 1714 | cmd.set_attribute('agent_id', agent_id) |
||
| 1715 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1716 | |||
| 1717 | return self._send_xml_command(cmd) |
||
| 1718 | |||
| 1719 | def delete_alert(self, alert_id, *, ultimate=False): |
||
| 1720 | """Deletes an existing alert |
||
| 1721 | |||
| 1722 | Arguments: |
||
| 1723 | alert_id (str) UUID of the alert to be deleted. |
||
| 1724 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1725 | or to the trashcan. |
||
| 1726 | """ |
||
| 1727 | if not alert_id: |
||
| 1728 | raise RequiredArgument('delete_alert requires an alert_id argument') |
||
| 1729 | |||
| 1730 | cmd = XmlCommand('delete_alert') |
||
| 1731 | cmd.set_attribute('alert_id', alert_id) |
||
| 1732 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1733 | |||
| 1734 | return self._send_xml_command(cmd) |
||
| 1735 | |||
| 1736 | def delete_asset(self, *, asset_id=None, report_id=None): |
||
| 1737 | """Deletes an existing asset |
||
| 1738 | |||
| 1739 | Arguments: |
||
| 1740 | asset_id (str, optional): UUID of the single asset to delete. |
||
| 1741 | report_id (str,optional): UUID of report from which to get all |
||
| 1742 | assets to delete. |
||
| 1743 | """ |
||
| 1744 | if not asset_id and not report_id: |
||
| 1745 | raise RequiredArgument('delete_asset requires an asset_id or ' |
||
| 1746 | 'a report_id argument') |
||
| 1747 | |||
| 1748 | cmd = XmlCommand('delete_asset') |
||
| 1749 | if asset_id: |
||
| 1750 | cmd.set_attribute('asset_id', asset_id) |
||
| 1751 | else: |
||
| 1752 | cmd.set_attribute('report_id', report_id) |
||
| 1753 | |||
| 1754 | return self._send_xml_command(cmd) |
||
| 1755 | |||
| 1756 | def delete_config(self, config_id, *, ultimate=False): |
||
| 1757 | """Deletes an existing config |
||
| 1758 | |||
| 1759 | Arguments: |
||
| 1760 | config_id (str) UUID of the config to be deleted. |
||
| 1761 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1762 | or to the trashcan. |
||
| 1763 | """ |
||
| 1764 | if not config_id: |
||
| 1765 | raise RequiredArgument('delete_config requires a ' |
||
| 1766 | 'config_id argument') |
||
| 1767 | |||
| 1768 | cmd = XmlCommand('delete_config') |
||
| 1769 | cmd.set_attribute('config_id', config_id) |
||
| 1770 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1771 | |||
| 1772 | return self._send_xml_command(cmd) |
||
| 1773 | |||
| 1774 | def delete_credential(self, credential_id, *, ultimate=False): |
||
| 1775 | """Deletes an existing credential |
||
| 1776 | |||
| 1777 | Arguments: |
||
| 1778 | credential_id (str) UUID of the credential to be deleted. |
||
| 1779 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1780 | or to the trashcan. |
||
| 1781 | """ |
||
| 1782 | if not credential_id: |
||
| 1783 | raise RequiredArgument('delete_credential requires a ' |
||
| 1784 | 'credential_id argument') |
||
| 1785 | |||
| 1786 | cmd = XmlCommand('delete_credential') |
||
| 1787 | cmd.set_attribute('credential_id', credential_id) |
||
| 1788 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1789 | |||
| 1790 | return self._send_xml_command(cmd) |
||
| 1791 | |||
| 1792 | def delete_filter(self, filter_id, *, ultimate=False): |
||
| 1793 | """Deletes an existing filter |
||
| 1794 | |||
| 1795 | Arguments: |
||
| 1796 | filter_id (str) UUID of the filter to be deleted. |
||
| 1797 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1798 | or to the trashcan. |
||
| 1799 | """ |
||
| 1800 | if not filter_id: |
||
| 1801 | raise RequiredArgument('delete_filter requires a ' |
||
| 1802 | 'filter_id argument') |
||
| 1803 | |||
| 1804 | cmd = XmlCommand('delete_filter') |
||
| 1805 | cmd.set_attribute('filter_id', filter_id) |
||
| 1806 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1807 | |||
| 1808 | return self._send_xml_command(cmd) |
||
| 1809 | |||
| 1810 | def delete_group(self, group_id, *, ultimate=False): |
||
| 1811 | """Deletes an existing group |
||
| 1812 | |||
| 1813 | Arguments: |
||
| 1814 | group_id (str) UUID of the group to be deleted. |
||
| 1815 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1816 | or to the trashcan. |
||
| 1817 | """ |
||
| 1818 | if not group_id: |
||
| 1819 | raise RequiredArgument('delete_group requires a ' |
||
| 1820 | 'group_id argument') |
||
| 1821 | |||
| 1822 | cmd = XmlCommand('delete_group') |
||
| 1823 | cmd.set_attribute('group_id', group_id) |
||
| 1824 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1825 | |||
| 1826 | return self._send_xml_command(cmd) |
||
| 1827 | |||
| 1828 | def delete_note(self, note_id, *, ultimate=False): |
||
| 1829 | """Deletes an existing note |
||
| 1830 | |||
| 1831 | Arguments: |
||
| 1832 | note_id (str) UUID of the note to be deleted. |
||
| 1833 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1834 | or to the trashcan. |
||
| 1835 | """ |
||
| 1836 | if not note_id: |
||
| 1837 | raise RequiredArgument('delete_note requires a ' |
||
| 1838 | 'note_id argument') |
||
| 1839 | |||
| 1840 | cmd = XmlCommand('delete_note') |
||
| 1841 | cmd.set_attribute('note_id', note_id) |
||
| 1842 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1843 | |||
| 1844 | return self._send_xml_command(cmd) |
||
| 1845 | |||
| 1846 | def delete_override(self, override_id, *, ultimate=False): |
||
| 1847 | """Deletes an existing override |
||
| 1848 | |||
| 1849 | Arguments: |
||
| 1850 | override_id (str) UUID of the override to be deleted. |
||
| 1851 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1852 | or to the trashcan. |
||
| 1853 | """ |
||
| 1854 | if not override_id: |
||
| 1855 | raise RequiredArgument('delete_override requires a ' |
||
| 1856 | 'override_id argument') |
||
| 1857 | |||
| 1858 | cmd = XmlCommand('delete_override') |
||
| 1859 | cmd.set_attribute('override_id', override_id) |
||
| 1860 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1861 | |||
| 1862 | return self._send_xml_command(cmd) |
||
| 1863 | |||
| 1864 | def delete_permission(self, permission_id, *, ultimate=False): |
||
| 1865 | """Deletes an existing permission |
||
| 1866 | |||
| 1867 | Arguments: |
||
| 1868 | permission_id (str) UUID of the permission to be deleted. |
||
| 1869 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1870 | or to the trashcan. |
||
| 1871 | """ |
||
| 1872 | if not permission_id: |
||
| 1873 | raise RequiredArgument('delete_permission requires a ' |
||
| 1874 | 'permission_id argument') |
||
| 1875 | |||
| 1876 | cmd = XmlCommand('delete_permission') |
||
| 1877 | cmd.set_attribute('permission_id', permission_id) |
||
| 1878 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1879 | |||
| 1880 | return self._send_xml_command(cmd) |
||
| 1881 | |||
| 1882 | def delete_port_list(self, port_list_id, *, ultimate=False): |
||
| 1883 | """Deletes an existing port list |
||
| 1884 | |||
| 1885 | Arguments: |
||
| 1886 | port_list_id (str) UUID of the port list to be deleted. |
||
| 1887 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1888 | or to the trashcan. |
||
| 1889 | """ |
||
| 1890 | if not port_list_id: |
||
| 1891 | raise RequiredArgument('delete_port_list requires a ' |
||
| 1892 | 'port_list_id argument') |
||
| 1893 | |||
| 1894 | cmd = XmlCommand('delete_port_list') |
||
| 1895 | cmd.set_attribute('port_list_id', port_list_id) |
||
| 1896 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1897 | |||
| 1898 | return self._send_xml_command(cmd) |
||
| 1899 | |||
| 1900 | def delete_port_range(self, port_range_id): |
||
| 1901 | """Deletes an existing port range |
||
| 1902 | |||
| 1903 | Arguments: |
||
| 1904 | port_range_id (str) UUID of the port range to be deleted. |
||
| 1905 | """ |
||
| 1906 | if not port_range_id: |
||
| 1907 | raise RequiredArgument('delete_port_range requires a ' |
||
| 1908 | 'port_range_id argument') |
||
| 1909 | |||
| 1910 | cmd = XmlCommand('delete_port_range') |
||
| 1911 | cmd.set_attribute('port_range_id', port_range_id) |
||
| 1912 | |||
| 1913 | return self._send_xml_command(cmd) |
||
| 1914 | |||
| 1915 | def delete_report(self, report_id): |
||
| 1916 | """Deletes an existing report |
||
| 1917 | |||
| 1918 | Arguments: |
||
| 1919 | report_id (str) UUID of the report to be deleted. |
||
| 1920 | """ |
||
| 1921 | if not report_id: |
||
| 1922 | raise RequiredArgument('delete_report requires a ' |
||
| 1923 | 'report_id argument') |
||
| 1924 | |||
| 1925 | cmd = XmlCommand('delete_report') |
||
| 1926 | cmd.set_attribute('report_id', report_id) |
||
| 1927 | |||
| 1928 | return self._send_xml_command(cmd) |
||
| 1929 | |||
| 1930 | |||
| 1931 | def delete_report_format(self, report_format_id, *, ultimate=False): |
||
| 1932 | """Deletes an existing report format |
||
| 1933 | |||
| 1934 | Arguments: |
||
| 1935 | report_format_id (str) UUID of the report format to be deleted. |
||
| 1936 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1937 | or to the trashcan. |
||
| 1938 | """ |
||
| 1939 | if not report_format_id: |
||
| 1940 | raise RequiredArgument('delete_report_format requires a ' |
||
| 1941 | 'report_format_id argument') |
||
| 1942 | |||
| 1943 | cmd = XmlCommand('delete_report_format') |
||
| 1944 | cmd.set_attribute('report_format_id', report_format_id) |
||
| 1945 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1946 | |||
| 1947 | return self._send_xml_command(cmd) |
||
| 1948 | |||
| 1949 | |||
| 1950 | def delete_role(self, role_id, *, ultimate=False): |
||
| 1951 | """Deletes an existing role |
||
| 1952 | |||
| 1953 | Arguments: |
||
| 1954 | role_id (str) UUID of the role to be deleted. |
||
| 1955 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1956 | or to the trashcan. |
||
| 1957 | """ |
||
| 1958 | if not role_id: |
||
| 1959 | raise RequiredArgument('delete_role requires a ' |
||
| 1960 | 'role_id argument') |
||
| 1961 | |||
| 1962 | cmd = XmlCommand('delete_role') |
||
| 1963 | cmd.set_attribute('role_id', role_id) |
||
| 1964 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1965 | |||
| 1966 | return self._send_xml_command(cmd) |
||
| 1967 | |||
| 1968 | def delete_scanner(self, scanner_id, *, ultimate=False): |
||
| 1969 | """Deletes an existing scanner |
||
| 1970 | |||
| 1971 | Arguments: |
||
| 1972 | scanner_id (str) UUID of the scanner to be deleted. |
||
| 1973 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1974 | or to the trashcan. |
||
| 1975 | """ |
||
| 1976 | if not scanner_id: |
||
| 1977 | raise RequiredArgument('delete_scanner requires a ' |
||
| 1978 | 'scanner_id argument') |
||
| 1979 | |||
| 1980 | cmd = XmlCommand('delete_scanner') |
||
| 1981 | cmd.set_attribute('scanner_id', scanner_id) |
||
| 1982 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 1983 | |||
| 1984 | return self._send_xml_command(cmd) |
||
| 1985 | |||
| 1986 | def delete_schedule(self, schedule_id, *, ultimate=False): |
||
| 1987 | """Deletes an existing schedule |
||
| 1988 | |||
| 1989 | Arguments: |
||
| 1990 | schedule_id (str) UUID of the schedule to be deleted. |
||
| 1991 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 1992 | or to the trashcan. |
||
| 1993 | """ |
||
| 1994 | if not schedule_id: |
||
| 1995 | raise RequiredArgument('delete_schedule requires a ' |
||
| 1996 | 'schedule_id argument') |
||
| 1997 | |||
| 1998 | cmd = XmlCommand('delete_schedule') |
||
| 1999 | cmd.set_attribute('schedule_id', schedule_id) |
||
| 2000 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 2001 | |||
| 2002 | return self._send_xml_command(cmd) |
||
| 2003 | |||
| 2004 | def delete_tag(self, tag_id, *, ultimate=False): |
||
| 2005 | """Deletes an existing tag |
||
| 2006 | |||
| 2007 | Arguments: |
||
| 2008 | tag_id (str) UUID of the tag to be deleted. |
||
| 2009 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 2010 | or to the trashcan. |
||
| 2011 | """ |
||
| 2012 | if not tag_id: |
||
| 2013 | raise RequiredArgument('delete_tag requires a ' |
||
| 2014 | 'tag_id argument') |
||
| 2015 | |||
| 2016 | cmd = XmlCommand('delete_tag') |
||
| 2017 | cmd.set_attribute('tag_id', tag_id) |
||
| 2018 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 2019 | |||
| 2020 | return self._send_xml_command(cmd) |
||
| 2021 | |||
| 2022 | def delete_target(self, target_id, *, ultimate=False): |
||
| 2023 | """Deletes an existing target |
||
| 2024 | |||
| 2025 | Arguments: |
||
| 2026 | target_id (str) UUID of the target to be deleted. |
||
| 2027 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 2028 | or to the trashcan. |
||
| 2029 | """ |
||
| 2030 | if not target_id: |
||
| 2031 | raise RequiredArgument('delete_target requires a ' |
||
| 2032 | 'target_id argument') |
||
| 2033 | |||
| 2034 | cmd = XmlCommand('delete_target') |
||
| 2035 | cmd.set_attribute('target_id', target_id) |
||
| 2036 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 2037 | |||
| 2038 | return self._send_xml_command(cmd) |
||
| 2039 | |||
| 2040 | def delete_task(self, task_id, *, ultimate=False): |
||
| 2041 | """Deletes an existing task |
||
| 2042 | |||
| 2043 | Arguments: |
||
| 2044 | task_id (str) UUID of the task to be deleted. |
||
| 2045 | ultimate (boolean, optional): Whether to remove entirely, |
||
| 2046 | or to the trashcan. |
||
| 2047 | """ |
||
| 2048 | if not task_id: |
||
| 2049 | raise RequiredArgument('delete_task requires a ' |
||
| 2050 | 'task_id argument') |
||
| 2051 | |||
| 2052 | cmd = XmlCommand('delete_task') |
||
| 2053 | cmd.set_attribute('task_id', task_id) |
||
| 2054 | cmd.set_attribute('ultimate', _to_bool(ultimate)) |
||
| 2055 | |||
| 2056 | return self._send_xml_command(cmd) |
||
| 2057 | |||
| 2058 | def delete_user(self, user_id, *, name=None, inheritor_id=None, |
||
| 2059 | inheritor_name=None): |
||
| 2060 | """Deletes an existing user |
||
| 2061 | |||
| 2062 | Arguments: |
||
| 2063 | user_id (str): UUID of the task to be deleted. |
||
| 2064 | name (str, optional): The name of the user to be deleted. |
||
| 2065 | inheritor_id (str, optional): The ID of the inheriting user |
||
| 2066 | or "self". Overrides inheritor_name. |
||
| 2067 | inheritor_name (str, optional): The name of the inheriting user. |
||
| 2068 | |||
| 2069 | """ |
||
| 2070 | if not user_id: |
||
| 2071 | raise RequiredArgument('delete_user requires a ' |
||
| 2072 | 'user_id argument') |
||
| 2073 | |||
| 2074 | cmd = XmlCommand('delete_user') |
||
| 2075 | cmd.set_attribute('user_id', user_id) |
||
| 2076 | |||
| 2077 | if name: |
||
| 2078 | cmd.set_attribute('name', name) |
||
| 2079 | |||
| 2080 | if not inheritor_id and not inheritor_name: |
||
| 2081 | raise RequiredArgument('delete_user requires a ' |
||
| 2082 | 'inheritor_id or inheritor_name argument') |
||
| 2083 | if inheritor_id: |
||
| 2084 | cmd.set_attribute('inheritor_id', inheritor_id) |
||
| 2085 | |||
| 2086 | if inheritor_name: |
||
| 2087 | cmd.set_attribute('inheritor_name', inheritor_name) |
||
| 2088 | |||
| 2089 | return self._send_xml_command(cmd) |
||
| 2090 | |||
| 2091 | def describe_auth(self): |
||
| 2092 | """Describe authentication methods |
||
| 2093 | |||
| 2094 | Returns a list of all used authentication methods if such a list is |
||
| 2095 | available. |
||
| 2096 | |||
| 2097 | Returns: |
||
| 2098 | The response. See :py:meth:`send_command` for details. |
||
| 2099 | """ |
||
| 2100 | return self._send_xml_command(XmlCommand('describe_auth')) |
||
| 2101 | |||
| 2102 | def empty_trashcan(self): |
||
| 2103 | """Empty the trashcan |
||
| 2104 | |||
| 2105 | Remove all entities from the trashcan. **Attention:** this command can |
||
| 2106 | not be reverted |
||
| 2107 | |||
| 2108 | Returns: |
||
| 2109 | The response. See :py:meth:`send_command` for details. |
||
| 2110 | """ |
||
| 2111 | return self._send_xml_command(XmlCommand('empty_trashcan')) |
||
| 2112 | |||
| 2113 | def get_agents(self, *, filter=None, filter_id=None, trash=None, |
||
| 2114 | details=None, format=None): |
||
| 2115 | """Request a list of agents |
||
| 2116 | |||
| 2117 | Arguments: |
||
| 2118 | filter (str, optional): Filter term to use for the query |
||
| 2119 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2120 | the query |
||
| 2121 | trash (boolean, optional): True to request the agents in the |
||
| 2122 | trashcan |
||
| 2123 | details (boolean, optional): Whether to include agents package |
||
| 2124 | information when no format was provided |
||
| 2125 | format (str, optional): One of "installer", "howto_install" or |
||
| 2126 | "howto_use" |
||
| 2127 | |||
| 2128 | Returns: |
||
| 2129 | The response. See :py:meth:`send_command` for details. |
||
| 2130 | """ |
||
| 2131 | cmd = XmlCommand('get_agents') |
||
| 2132 | |||
| 2133 | _add_filter(cmd, filter, filter_id) |
||
| 2134 | |||
| 2135 | if not trash is None: |
||
| 2136 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2137 | |||
| 2138 | if not details is None: |
||
| 2139 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2140 | |||
| 2141 | if format: |
||
| 2142 | if not format in ('installer', 'howto_install', 'howto_use'): |
||
| 2143 | raise InvalidArgument( |
||
| 2144 | 'installer argument needs to be one of installer, ' |
||
| 2145 | 'howto_install or howto_use') |
||
| 2146 | |||
| 2147 | cmd.set_attribute('format', format) |
||
| 2148 | |||
| 2149 | return self._send_xml_command(cmd) |
||
| 2150 | |||
| 2151 | def get_agent(self, agent_id): |
||
| 2152 | """Request a single agent |
||
| 2153 | |||
| 2154 | Arguments: |
||
| 2155 | agent_id (str): UUID of an existing agent |
||
| 2156 | |||
| 2157 | Returns: |
||
| 2158 | The response. See :py:meth:`send_command` for details. |
||
| 2159 | """ |
||
| 2160 | cmd = XmlCommand('get_agents') |
||
| 2161 | cmd.set_attribute('agent_id', agent_id) |
||
| 2162 | |||
| 2163 | # for single entity always request all details |
||
| 2164 | cmd.set_attribute('details', '1') |
||
| 2165 | return self._send_xml_command(cmd) |
||
| 2166 | |||
| 2167 | def get_aggregates(self, **kwargs): |
||
| 2168 | cmd = XmlCommand('get_aggregates') |
||
| 2169 | cmd.set_attributes(kwargs) |
||
| 2170 | return self._send_xml_command(cmd) |
||
| 2171 | |||
| 2172 | View Code Duplication | def get_alerts(self, *, filter=None, filter_id=None, trash=None, |
|
| 2173 | tasks=None): |
||
| 2174 | """Request a list of alerts |
||
| 2175 | |||
| 2176 | Arguments: |
||
| 2177 | filter (str, optional): Filter term to use for the query |
||
| 2178 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2179 | the query |
||
| 2180 | trash (boolean, optional): True to request the alerts in the |
||
| 2181 | trashcan |
||
| 2182 | tasks (boolean, optional): Whether to include the tasks using the |
||
| 2183 | alerts |
||
| 2184 | Returns: |
||
| 2185 | The response. See :py:meth:`send_command` for details. |
||
| 2186 | """ |
||
| 2187 | cmd = XmlCommand('get_alerts') |
||
| 2188 | |||
| 2189 | _add_filter(cmd, filter, filter_id) |
||
| 2190 | |||
| 2191 | if not trash is None: |
||
| 2192 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2193 | |||
| 2194 | if not tasks is None: |
||
| 2195 | cmd.set_attribute('tasks', _to_bool(tasks)) |
||
| 2196 | |||
| 2197 | return self._send_xml_command(cmd) |
||
| 2198 | |||
| 2199 | def get_alert(self, alert_id): |
||
| 2200 | """Request a single alert |
||
| 2201 | |||
| 2202 | Arguments: |
||
| 2203 | alert_id (str): UUID of an existing alert |
||
| 2204 | |||
| 2205 | Returns: |
||
| 2206 | The response. See :py:meth:`send_command` for details. |
||
| 2207 | """ |
||
| 2208 | cmd = XmlCommand('get_alerts') |
||
| 2209 | cmd.set_attribute('alert_id', alert_id) |
||
| 2210 | return self._send_xml_command(cmd) |
||
| 2211 | |||
| 2212 | def get_assets(self, asset_type, *, filter=None, filter_id=None): |
||
| 2213 | """Request a list of assets |
||
| 2214 | |||
| 2215 | Arguments: |
||
| 2216 | asset_type (str): Either 'os' or 'host' |
||
| 2217 | filter (str, optional): Filter term to use for the query |
||
| 2218 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2219 | the query |
||
| 2220 | |||
| 2221 | Returns: |
||
| 2222 | The response. See :py:meth:`send_command` for details. |
||
| 2223 | """ |
||
| 2224 | if not asset_type in ('os', 'host'): |
||
| 2225 | raise InvalidArgument('asset_type must be either os or host') |
||
| 2226 | |||
| 2227 | cmd = XmlCommand('get_assets') |
||
| 2228 | |||
| 2229 | _add_filter(cmd, filter, filter_id) |
||
| 2230 | |||
| 2231 | cmd.set_attribute('type', asset_type) |
||
| 2232 | |||
| 2233 | return self._send_xml_command(cmd) |
||
| 2234 | |||
| 2235 | def get_asset(self, asset_id, asset_type): |
||
| 2236 | """Request a single asset |
||
| 2237 | |||
| 2238 | Arguments: |
||
| 2239 | asset_type (str): Either 'os' or 'host' |
||
| 2240 | asset_id (str): UUID of an existing asset |
||
| 2241 | |||
| 2242 | Returns: |
||
| 2243 | The response. See :py:meth:`send_command` for details. |
||
| 2244 | """ |
||
| 2245 | if not asset_type in ('os', 'host'): |
||
| 2246 | raise InvalidArgument('asset_type must be either os or host') |
||
| 2247 | |||
| 2248 | cmd = XmlCommand('get_assets') |
||
| 2249 | cmd.set_attribute('asset_id', asset_id) |
||
| 2250 | cmd.set_attribute('type', asset_type) |
||
| 2251 | |||
| 2252 | return self._send_xml_command(cmd) |
||
| 2253 | |||
| 2254 | def get_credentials(self, *, filter=None, filter_id=None, scanners=None, |
||
| 2255 | trash=None, targets=None, format=None): |
||
| 2256 | """Request a list of credentials |
||
| 2257 | |||
| 2258 | Arguments: |
||
| 2259 | filter (str, optional): Filter term to use for the query |
||
| 2260 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2261 | the query |
||
| 2262 | scanners (boolean, optional): Whether to include a list of scanners |
||
| 2263 | using the credentials |
||
| 2264 | trash (boolean, optional): Whether to get the trashcan credentials |
||
| 2265 | instead |
||
| 2266 | targets (boolean, optional): Whether to include a list of targets |
||
| 2267 | using the credentials |
||
| 2268 | format (str, optional): One of "key", "rpm", "deb" or "exe" |
||
| 2269 | |||
| 2270 | Returns: |
||
| 2271 | The response. See :py:meth:`send_command` for details. |
||
| 2272 | """ |
||
| 2273 | cmd = XmlCommand('get_credentials') |
||
| 2274 | |||
| 2275 | _add_filter(cmd, filter, filter_id) |
||
| 2276 | |||
| 2277 | if not scanners is None: |
||
| 2278 | cmd.set_attribute('scanners', _to_bool(scanners)) |
||
| 2279 | |||
| 2280 | if not trash is None: |
||
| 2281 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2282 | |||
| 2283 | if not targets is None: |
||
| 2284 | cmd.set_attribute('targets', _to_bool(targets)) |
||
| 2285 | |||
| 2286 | if format: |
||
| 2287 | if not format in ('key', 'rpm', 'deb', 'exe'): |
||
| 2288 | raise InvalidArgument( |
||
| 2289 | 'format argument needs to one of key, rpm, deb or exe') |
||
| 2290 | |||
| 2291 | cmd.set_attribute('format', format) |
||
| 2292 | |||
| 2293 | return self._send_xml_command(cmd) |
||
| 2294 | |||
| 2295 | def get_credential(self, credential_id, *, credential_format=None): |
||
| 2296 | """Request a single credential |
||
| 2297 | |||
| 2298 | Arguments: |
||
| 2299 | credential_id (str): UUID of an existing credential |
||
| 2300 | credential_format (str, optional): One of "key", "rpm", "deb", |
||
| 2301 | "exe" or "pem" |
||
| 2302 | |||
| 2303 | Returns: |
||
| 2304 | The response. See :py:meth:`send_command` for details. |
||
| 2305 | """ |
||
| 2306 | if not credential_id: |
||
| 2307 | raise RequiredArgument( |
||
| 2308 | 'get_credential requires credential_id argument') |
||
| 2309 | |||
| 2310 | cmd = XmlCommand('get_credentials') |
||
| 2311 | cmd.set_attribute('credential_id', credential_id) |
||
| 2312 | if credential_format: |
||
| 2313 | if not credential_format in ('key', 'rpm', 'deb', 'exe', 'pem'): |
||
| 2314 | raise InvalidArgument( |
||
| 2315 | 'credential_format argument needs to be one of ' |
||
| 2316 | 'key, rpm, deb, exe or pem') |
||
| 2317 | |||
| 2318 | cmd.set_attribute('format', credential_format) |
||
| 2319 | return self._send_xml_command(cmd) |
||
| 2320 | |||
| 2321 | def get_configs(self, *, filter=None, filter_id=None, trash=None, |
||
| 2322 | details=None, families=None, preferences=None, tasks=None): |
||
| 2323 | """Request a list of scan configs |
||
| 2324 | |||
| 2325 | Arguments: |
||
| 2326 | filter (str, optional): Filter term to use for the query |
||
| 2327 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2328 | the query |
||
| 2329 | trash (boolean, optional): Whether to get the trashcan scan configs |
||
| 2330 | instead |
||
| 2331 | details (boolean, optional): Whether to get config families, |
||
| 2332 | preferences, nvt selectors and tasks. |
||
| 2333 | families (boolean, optional): Whether to include the families if no |
||
| 2334 | details are requested |
||
| 2335 | preferences (boolean, optional): Whether to include the preferences |
||
| 2336 | if no details are requested |
||
| 2337 | tasks (boolean, optional): Whether to get tasks using this config |
||
| 2338 | |||
| 2339 | Returns: |
||
| 2340 | The response. See :py:meth:`send_command` for details. |
||
| 2341 | """ |
||
| 2342 | cmd = XmlCommand('get_configs') |
||
| 2343 | |||
| 2344 | _add_filter(cmd, filter, filter_id) |
||
| 2345 | |||
| 2346 | if not trash is None: |
||
| 2347 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2348 | |||
| 2349 | if not details is None: |
||
| 2350 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2351 | |||
| 2352 | if not families is None: |
||
| 2353 | cmd.set_attribute('families', _to_bool(families)) |
||
| 2354 | |||
| 2355 | if not preferences is None: |
||
| 2356 | cmd.set_attribute('preferences', _to_bool(preferences)) |
||
| 2357 | |||
| 2358 | if not tasks is None: |
||
| 2359 | cmd.set_attribute('tasks', _to_bool(tasks)) |
||
| 2360 | |||
| 2361 | return self._send_xml_command(cmd) |
||
| 2362 | |||
| 2363 | def get_config(self, config_id): |
||
| 2364 | """Request a single scan config |
||
| 2365 | |||
| 2366 | Arguments: |
||
| 2367 | config_id (str): UUID of an existing scan config |
||
| 2368 | |||
| 2369 | Returns: |
||
| 2370 | The response. See :py:meth:`send_command` for details. |
||
| 2371 | """ |
||
| 2372 | if not config_id: |
||
| 2373 | raise RequiredArgument('get_config requires config_id argument') |
||
| 2374 | |||
| 2375 | cmd = XmlCommand('get_configs') |
||
| 2376 | cmd.set_attribute('config_id', config_id) |
||
| 2377 | |||
| 2378 | # for single entity always request all details |
||
| 2379 | cmd.set_attribute('details', '1') |
||
| 2380 | return self._send_xml_command(cmd) |
||
| 2381 | |||
| 2382 | def get_feeds(self): |
||
| 2383 | """Request the list of feeds |
||
| 2384 | |||
| 2385 | Returns: |
||
| 2386 | The response. See :py:meth:`send_command` for details. |
||
| 2387 | """ |
||
| 2388 | return self._send_xml_command(XmlCommand('get_feeds')) |
||
| 2389 | |||
| 2390 | def get_feed(self, feed_type): |
||
| 2391 | """Request a single feed |
||
| 2392 | |||
| 2393 | Arguments: |
||
| 2394 | feed_type (str): Type of single feed to get: NVT, CERT or SCAP |
||
| 2395 | |||
| 2396 | Returns: |
||
| 2397 | The response. See :py:meth:`send_command` for details. |
||
| 2398 | """ |
||
| 2399 | feed_type = feed_type.upper() |
||
| 2400 | |||
| 2401 | if not feed_type in ('NVT', 'CERT', 'SCAP'): |
||
| 2402 | raise InvalidArgument( |
||
| 2403 | 'get_feed type arguments must be one of NVT, CERT or SCAP') |
||
| 2404 | |||
| 2405 | cmd = XmlCommand('get_feeds') |
||
| 2406 | cmd.set_attribute('type', feed_type) |
||
| 2407 | |||
| 2408 | return self._send_xml_command(cmd) |
||
| 2409 | |||
| 2410 | def get_filters(self, *, filter=None, filter_id=None, trash=None, |
||
| 2411 | alerts=None): |
||
| 2412 | """Request a list of filters |
||
| 2413 | |||
| 2414 | Arguments: |
||
| 2415 | filter (str, optional): Filter term to use for the query |
||
| 2416 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2417 | the query |
||
| 2418 | trash (boolean, optional): Whether to get the trashcan filters |
||
| 2419 | instead |
||
| 2420 | alerts (boolean, optional): Whether to include list of alerts that |
||
| 2421 | use the filter. |
||
| 2422 | |||
| 2423 | Returns: |
||
| 2424 | The response. See :py:meth:`send_command` for details. |
||
| 2425 | """ |
||
| 2426 | cmd = XmlCommand('get_filters') |
||
| 2427 | |||
| 2428 | _add_filter(cmd, filter, filter_id) |
||
| 2429 | |||
| 2430 | if not trash is None: |
||
| 2431 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2432 | |||
| 2433 | if not alerts is None: |
||
| 2434 | cmd.set_attribute('alerts', _to_bool(alerts)) |
||
| 2435 | |||
| 2436 | return self._send_xml_command(cmd) |
||
| 2437 | |||
| 2438 | def get_filter(self, filter_id): |
||
| 2439 | """Request a single filter |
||
| 2440 | |||
| 2441 | Arguments: |
||
| 2442 | filter_id (str): UUID of an existing filter |
||
| 2443 | |||
| 2444 | Returns: |
||
| 2445 | The response. See :py:meth:`send_command` for details. |
||
| 2446 | """ |
||
| 2447 | cmd = XmlCommand('get_filters') |
||
| 2448 | cmd.set_attribute('filter_id', filter_id) |
||
| 2449 | return self._send_xml_command(cmd) |
||
| 2450 | |||
| 2451 | def get_groups(self, *, filter=None, filter_id=None, trash=None): |
||
| 2452 | """Request a list of groups |
||
| 2453 | |||
| 2454 | Arguments: |
||
| 2455 | filter (str, optional): Filter term to use for the query |
||
| 2456 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2457 | the query |
||
| 2458 | trash (boolean, optional): Whether to get the trashcan groups |
||
| 2459 | instead |
||
| 2460 | |||
| 2461 | Returns: |
||
| 2462 | The response. See :py:meth:`send_command` for details. |
||
| 2463 | """ |
||
| 2464 | cmd = XmlCommand('get_groups') |
||
| 2465 | |||
| 2466 | _add_filter(cmd, filter, filter_id) |
||
| 2467 | |||
| 2468 | if not trash is None: |
||
| 2469 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2470 | |||
| 2471 | return self._send_xml_command(cmd) |
||
| 2472 | |||
| 2473 | def get_group(self, group_id): |
||
| 2474 | """Request a single group |
||
| 2475 | |||
| 2476 | Arguments: |
||
| 2477 | group_id (str): UUID of an existing group |
||
| 2478 | |||
| 2479 | Returns: |
||
| 2480 | The response. See :py:meth:`send_command` for details. |
||
| 2481 | """ |
||
| 2482 | cmd = XmlCommand('get_groups') |
||
| 2483 | cmd.set_attribute('group_id', group_id) |
||
| 2484 | return self._send_xml_command(cmd) |
||
| 2485 | |||
| 2486 | def get_info_list(self, info_type, *, filter=None, filter_id=None, |
||
| 2487 | name=None, details=None): |
||
| 2488 | """Request a list of security information |
||
| 2489 | |||
| 2490 | Arguments: |
||
| 2491 | info_type (str): Type must be either CERT_BUND_ADV, CPE, CVE, |
||
| 2492 | DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
||
| 2493 | filter (str, optional): Filter term to use for the query |
||
| 2494 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2495 | the query |
||
| 2496 | name (str, optional): Name or identifier of the requested |
||
| 2497 | information |
||
| 2498 | details (boolean, optional): Whether to include information about |
||
| 2499 | references to this information |
||
| 2500 | |||
| 2501 | Returns: |
||
| 2502 | The response. See :py:meth:`send_command` for details. |
||
| 2503 | """ |
||
| 2504 | info_type = info_type.upper() |
||
| 2505 | |||
| 2506 | if not info_type in ( |
||
| 2507 | 'CERT_BUND_ADV', 'CPE', 'CVE', 'DFN_CERT_ADV', 'OVALDEF', 'NVT', |
||
| 2508 | 'ALLINFO'): |
||
| 2509 | raise InvalidArgument( |
||
| 2510 | 'get_info_list info_type argument must be one of CERT_BUND_ADV' |
||
| 2511 | ', CPE, CVE, DFN_CERT_ADV, OVALDEF, NVT or ALLINFO') |
||
| 2512 | |||
| 2513 | cmd = XmlCommand('get_info') |
||
| 2514 | |||
| 2515 | _add_filter(cmd, filter, filter_id) |
||
| 2516 | |||
| 2517 | cmd.set_attribute('type', info_type) |
||
| 2518 | |||
| 2519 | if name: |
||
| 2520 | cmd.set_attribute('name', name) |
||
| 2521 | |||
| 2522 | if not details is None: |
||
| 2523 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2524 | |||
| 2525 | return self._send_xml_command(cmd) |
||
| 2526 | |||
| 2527 | def get_info(self, info_id, info_type): |
||
| 2528 | """Request a single secinfo |
||
| 2529 | |||
| 2530 | Arguments: |
||
| 2531 | info_id (str): UUID of an existing secinfo |
||
| 2532 | info_type (str): Type must be either CERT_BUND_ADV, CPE, CVE, |
||
| 2533 | DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
||
| 2534 | |||
| 2535 | Returns: |
||
| 2536 | The response. See :py:meth:`send_command` for details. |
||
| 2537 | """ |
||
| 2538 | if not info_type in ( |
||
| 2539 | 'CERT_BUND_ADV', 'CPE', 'CVE', 'DFN_CERT_ADV', 'OVALDEF', 'NVT', |
||
| 2540 | 'ALLINFO'): |
||
| 2541 | raise InvalidArgument( |
||
| 2542 | 'get_info_list info_type argument must be one of CERT_BUND_ADV' |
||
| 2543 | ', CPE, CVE, DFN_CERT_ADV, OVALDEF, NVT or ALLINFO') |
||
| 2544 | |||
| 2545 | cmd = XmlCommand('get_info') |
||
| 2546 | cmd.set_attribute('info_id', info_id) |
||
| 2547 | |||
| 2548 | cmd.set_attribute('type', info_type) |
||
| 2549 | |||
| 2550 | # for single entity always request all details |
||
| 2551 | cmd.set_attribute('details', '1') |
||
| 2552 | return self._send_xml_command(cmd) |
||
| 2553 | |||
| 2554 | View Code Duplication | def get_notes(self, *, filter=None, filter_id=None, nvt_oid=None, |
|
| 2555 | task_id=None, details=None, result=None): |
||
| 2556 | """Request a list of notes |
||
| 2557 | |||
| 2558 | Arguments: |
||
| 2559 | filter (str, optional): Filter term to use for the query |
||
| 2560 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2561 | the query |
||
| 2562 | nvt_oid (str, optional): OID of a nvt |
||
| 2563 | task_id (str, optional): UUID of a task |
||
| 2564 | details (boolean, optional): |
||
| 2565 | result (boolean, optional): |
||
| 2566 | |||
| 2567 | Returns: |
||
| 2568 | The response. See :py:meth:`send_command` for details. |
||
| 2569 | """ |
||
| 2570 | cmd = XmlCommand('get_notes') |
||
| 2571 | |||
| 2572 | _add_filter(cmd, filter, filter_id) |
||
| 2573 | |||
| 2574 | if nvt_oid: |
||
| 2575 | cmd.set_attribute('nvt_oid', nvt_oid) |
||
| 2576 | |||
| 2577 | if task_id: |
||
| 2578 | cmd.set_attribute('task_id', task_id) |
||
| 2579 | |||
| 2580 | if not details is None: |
||
| 2581 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2582 | |||
| 2583 | if not result is None: |
||
| 2584 | cmd.set_attribute('result', _to_bool(result)) |
||
| 2585 | |||
| 2586 | return self._send_xml_command(cmd) |
||
| 2587 | |||
| 2588 | def get_note(self, note_id): |
||
| 2589 | """Request a single note |
||
| 2590 | |||
| 2591 | Arguments: |
||
| 2592 | note_id (str): UUID of an existing note |
||
| 2593 | |||
| 2594 | Returns: |
||
| 2595 | The response. See :py:meth:`send_command` for details. |
||
| 2596 | """ |
||
| 2597 | cmd = XmlCommand('get_notes') |
||
| 2598 | cmd.set_attribute('note_id', note_id) |
||
| 2599 | |||
| 2600 | # for single entity always request all details |
||
| 2601 | cmd.set_attribute('details', '1') |
||
| 2602 | return self._send_xml_command(cmd) |
||
| 2603 | |||
| 2604 | def get_nvts(self, *, details=None, preferences=None, preference_count=None, |
||
| 2605 | timeout=None, config_id=None, preferences_config_id=None, |
||
| 2606 | family=None, sort_order=None, sort_field=None): |
||
| 2607 | """Request a list of nvts |
||
| 2608 | |||
| 2609 | Arguments: |
||
| 2610 | details (boolean, optional): Whether to include full details |
||
| 2611 | preferences (boolean, optional): Whether to include nvt preferences |
||
| 2612 | preference_count (boolean, optional): Whether to include preference |
||
| 2613 | count |
||
| 2614 | timeout (boolean, optional): Whether to include the special timeout |
||
| 2615 | preference |
||
| 2616 | config_id (str, optional): UUID of scan config to which to limit the |
||
| 2617 | NVT listing |
||
| 2618 | preferences_config_id (str, optional): UUID of scan config to use |
||
| 2619 | for preference values |
||
| 2620 | family (str, optional): Family to which to limit NVT listing |
||
| 2621 | sort_order (str, optional): Sort order |
||
| 2622 | sort_field (str, optional): Sort field |
||
| 2623 | |||
| 2624 | Returns: |
||
| 2625 | The response. See :py:meth:`send_command` for details. |
||
| 2626 | """ |
||
| 2627 | cmd = XmlCommand('get_nvts') |
||
| 2628 | |||
| 2629 | if not details is None: |
||
| 2630 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2631 | |||
| 2632 | if not preferences is None: |
||
| 2633 | cmd.set_attribute('preferences', _to_bool(preferences)) |
||
| 2634 | |||
| 2635 | if not preference_count is None: |
||
| 2636 | cmd.set_attribute('preference_count', _to_bool(preference_count)) |
||
| 2637 | |||
| 2638 | if not timeout is None: |
||
| 2639 | cmd.set_attribute('timeout', _to_bool(timeout)) |
||
| 2640 | |||
| 2641 | if config_id: |
||
| 2642 | cmd.set_attribute('config_id', config_id) |
||
| 2643 | |||
| 2644 | if preferences_config_id: |
||
| 2645 | cmd.set_attribute('preferences_config_id', preferences_config_id) |
||
| 2646 | |||
| 2647 | if family: |
||
| 2648 | cmd.set_attribute('family', family) |
||
| 2649 | |||
| 2650 | if sort_order: |
||
| 2651 | cmd.set_attribute('sort_order', sort_order) |
||
| 2652 | |||
| 2653 | if sort_field: |
||
| 2654 | cmd.set_attribute('sort_field', sort_field) |
||
| 2655 | |||
| 2656 | return self._send_xml_command(cmd) |
||
| 2657 | |||
| 2658 | def get_nvt(self, nvt_oid): |
||
| 2659 | """Request a single nvt |
||
| 2660 | |||
| 2661 | Arguments: |
||
| 2662 | nvt_oid (str): OID of an existing nvt |
||
| 2663 | |||
| 2664 | Returns: |
||
| 2665 | The response. See :py:meth:`send_command` for details. |
||
| 2666 | """ |
||
| 2667 | cmd = XmlCommand('get_nvts') |
||
| 2668 | cmd.set_attribute('nvt_oid', nvt_oid) |
||
| 2669 | |||
| 2670 | # for single entity always request all details |
||
| 2671 | cmd.set_attribute('details', '1') |
||
| 2672 | return self._send_xml_command(cmd) |
||
| 2673 | |||
| 2674 | def get_nvt_families(self, *, sort_order=None): |
||
| 2675 | """Request a list of nvt families |
||
| 2676 | |||
| 2677 | Arguments: |
||
| 2678 | sort_order (str, optional): Sort order |
||
| 2679 | |||
| 2680 | Returns: |
||
| 2681 | The response. See :py:meth:`send_command` for details. |
||
| 2682 | """ |
||
| 2683 | cmd = XmlCommand('get_nvt_families') |
||
| 2684 | |||
| 2685 | if sort_order: |
||
| 2686 | cmd.set_attribute('sort_order', sort_order) |
||
| 2687 | |||
| 2688 | return self._send_xml_command(cmd) |
||
| 2689 | |||
| 2690 | View Code Duplication | def get_overrides(self, *, filter=None, filter_id=None, nvt_oid=None, |
|
| 2691 | task_id=None, details=None, result=None): |
||
| 2692 | """Request a list of overrides |
||
| 2693 | |||
| 2694 | Arguments: |
||
| 2695 | filter (str, optional): Filter term to use for the query |
||
| 2696 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2697 | the query |
||
| 2698 | nvt_oid (str, optional): OID of a nvt |
||
| 2699 | task_id (str, optional): UUID of a task |
||
| 2700 | details (boolean, optional): |
||
| 2701 | result (boolean, optional): |
||
| 2702 | |||
| 2703 | Returns: |
||
| 2704 | The response. See :py:meth:`send_command` for details. |
||
| 2705 | """ |
||
| 2706 | cmd = XmlCommand('get_overrides') |
||
| 2707 | |||
| 2708 | _add_filter(cmd, filter, filter_id) |
||
| 2709 | |||
| 2710 | if nvt_oid: |
||
| 2711 | cmd.set_attribute('nvt_oid', nvt_oid) |
||
| 2712 | |||
| 2713 | if task_id: |
||
| 2714 | cmd.set_attribute('task_id', task_id) |
||
| 2715 | |||
| 2716 | if not details is None: |
||
| 2717 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2718 | |||
| 2719 | if not result is None: |
||
| 2720 | cmd.set_attribute('result', _to_bool(result)) |
||
| 2721 | |||
| 2722 | return self._send_xml_command(cmd) |
||
| 2723 | |||
| 2724 | def get_override(self, override_id): |
||
| 2725 | """Request a single override |
||
| 2726 | |||
| 2727 | Arguments: |
||
| 2728 | override_id (str): UUID of an existing override |
||
| 2729 | |||
| 2730 | Returns: |
||
| 2731 | The response. See :py:meth:`send_command` for details. |
||
| 2732 | """ |
||
| 2733 | cmd = XmlCommand('get_overrides') |
||
| 2734 | cmd.set_attribute('override_id', override_id) |
||
| 2735 | |||
| 2736 | # for single entity always request all details |
||
| 2737 | cmd.set_attribute('details', '1') |
||
| 2738 | return self._send_xml_command(cmd) |
||
| 2739 | |||
| 2740 | def get_permissions(self, *, filter=None, filter_id=None, trash=None): |
||
| 2741 | """Request a list of permissions |
||
| 2742 | |||
| 2743 | Arguments: |
||
| 2744 | filter (str, optional): Filter term to use for the query |
||
| 2745 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2746 | the query |
||
| 2747 | trash (boolean, optional): Whether to get permissions in the |
||
| 2748 | trashcan instead |
||
| 2749 | |||
| 2750 | Returns: |
||
| 2751 | The response. See :py:meth:`send_command` for details. |
||
| 2752 | """ |
||
| 2753 | cmd = XmlCommand('get_permissions') |
||
| 2754 | |||
| 2755 | _add_filter(cmd, filter, filter_id) |
||
| 2756 | |||
| 2757 | if not trash is None: |
||
| 2758 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2759 | |||
| 2760 | return self._send_xml_command(cmd) |
||
| 2761 | |||
| 2762 | def get_permission(self, permission_id): |
||
| 2763 | """Request a single permission |
||
| 2764 | |||
| 2765 | Arguments: |
||
| 2766 | permission_id (str): UUID of an existing permission |
||
| 2767 | |||
| 2768 | Returns: |
||
| 2769 | The response. See :py:meth:`send_command` for details. |
||
| 2770 | """ |
||
| 2771 | cmd = XmlCommand('get_permissions') |
||
| 2772 | cmd.set_attribute('permission_id', permission_id) |
||
| 2773 | return self._send_xml_command(cmd) |
||
| 2774 | |||
| 2775 | View Code Duplication | def get_port_lists(self, *, filter=None, filter_id=None, details=None, |
|
| 2776 | targets=None, trash=None): |
||
| 2777 | """Request a list of port lists |
||
| 2778 | |||
| 2779 | Arguments: |
||
| 2780 | filter (str, optional): Filter term to use for the query |
||
| 2781 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2782 | the query |
||
| 2783 | details (boolean, optional): Whether to include full port list |
||
| 2784 | details |
||
| 2785 | targets (boolean, optional): Whether to include targets using this |
||
| 2786 | port list |
||
| 2787 | trash (boolean, optional): Whether to get port lists in the |
||
| 2788 | trashcan instead |
||
| 2789 | |||
| 2790 | Returns: |
||
| 2791 | The response. See :py:meth:`send_command` for details. |
||
| 2792 | """ |
||
| 2793 | cmd = XmlCommand('get_port_lists') |
||
| 2794 | |||
| 2795 | _add_filter(cmd, filter, filter_id) |
||
| 2796 | |||
| 2797 | if not details is None: |
||
| 2798 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2799 | |||
| 2800 | if not targets is None: |
||
| 2801 | cmd.set_attribute('targets', _to_bool(targets)) |
||
| 2802 | |||
| 2803 | if not trash is None: |
||
| 2804 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2805 | |||
| 2806 | return self._send_xml_command(cmd) |
||
| 2807 | |||
| 2808 | def get_port_list(self, port_list_id): |
||
| 2809 | """Request a single port list |
||
| 2810 | |||
| 2811 | Arguments: |
||
| 2812 | port_list_id (str): UUID of an existing port list |
||
| 2813 | |||
| 2814 | Returns: |
||
| 2815 | The response. See :py:meth:`send_command` for details. |
||
| 2816 | """ |
||
| 2817 | cmd = XmlCommand('get_port_lists') |
||
| 2818 | cmd.set_attribute('port_list_id', port_list_id) |
||
| 2819 | |||
| 2820 | # for single entity always request all details |
||
| 2821 | cmd.set_attribute('details', '1') |
||
| 2822 | return self._send_xml_command(cmd) |
||
| 2823 | |||
| 2824 | def get_preferences(self, *, nvt_oid=None, config_id=None, preference=None): |
||
| 2825 | """Request a list of preferences |
||
| 2826 | |||
| 2827 | When the command includes a config_id attribute, the preference element |
||
| 2828 | includes the preference name, type and value, and the NVT to which the |
||
| 2829 | preference applies. Otherwise, the preference element includes just the |
||
| 2830 | name and value, with the NVT and type built into the name. |
||
| 2831 | |||
| 2832 | Arguments: |
||
| 2833 | nvt_oid (str, optional): OID of nvt |
||
| 2834 | config_id (str, optional): UUID of scan config of which to show |
||
| 2835 | preference values |
||
| 2836 | preference (str, optional): name of a particular preference to get |
||
| 2837 | |||
| 2838 | Returns: |
||
| 2839 | The response. See :py:meth:`send_command` for details. |
||
| 2840 | """ |
||
| 2841 | cmd = XmlCommand('get_preferences') |
||
| 2842 | |||
| 2843 | if nvt_oid: |
||
| 2844 | cmd.set_attribute('nvt_oid', nvt_oid) |
||
| 2845 | |||
| 2846 | if config_id: |
||
| 2847 | cmd.set_attribute('config_id', config_id) |
||
| 2848 | |||
| 2849 | if preference: |
||
| 2850 | cmd.set_attribute('preference', preference) |
||
| 2851 | |||
| 2852 | return self._send_xml_command(cmd) |
||
| 2853 | |||
| 2854 | def get_reports(self, *, filter=None, filter_id=None, note_details=None, |
||
| 2855 | override_details=None): |
||
| 2856 | """Request a list of reports |
||
| 2857 | |||
| 2858 | Arguments: |
||
| 2859 | filter (str, optional): Filter term to use for the query |
||
| 2860 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2861 | the query |
||
| 2862 | note_details (boolean, optional): If notes are included, whether to |
||
| 2863 | include note details |
||
| 2864 | override_details (boolean, optional): If overrides are included, |
||
| 2865 | whether to include override details |
||
| 2866 | |||
| 2867 | Returns: |
||
| 2868 | The response. See :py:meth:`send_command` for details. |
||
| 2869 | """ |
||
| 2870 | cmd = XmlCommand('get_reports') |
||
| 2871 | |||
| 2872 | if filter: |
||
| 2873 | cmd.set_attribute('report_filter', filter) |
||
| 2874 | |||
| 2875 | if filter_id: |
||
| 2876 | cmd.set_attribute('report_filt_id', filter_id) |
||
| 2877 | |||
| 2878 | if not note_details is None: |
||
| 2879 | cmd.set_attribute('note_details', _to_bool(note_details)) |
||
| 2880 | |||
| 2881 | if not override_details is None: |
||
| 2882 | cmd.set_attribute('override_details', _to_bool(override_details)) |
||
| 2883 | |||
| 2884 | cmd.set_attribute('ignore_pagination', '1') |
||
| 2885 | |||
| 2886 | return self._send_xml_command(cmd) |
||
| 2887 | |||
| 2888 | def get_report(self, report_id, *, filter=None, filter_id=None, |
||
| 2889 | delta_report_id=None, report_format_id=None): |
||
| 2890 | """Request a single report |
||
| 2891 | |||
| 2892 | Arguments: |
||
| 2893 | report_id (str): UUID of an existing report |
||
| 2894 | filter (str, optional): Filter term to use to filter results in the |
||
| 2895 | report |
||
| 2896 | filter_id (str, optional): UUID of filter to use to filter results |
||
| 2897 | in the report |
||
| 2898 | delta_report_id (str, optional): UUID of an existing report to |
||
| 2899 | compare report to. |
||
| 2900 | report_format_id (str, optional): UUID of report format to use |
||
| 2901 | |||
| 2902 | Returns: |
||
| 2903 | The response. See :py:meth:`send_command` for details. |
||
| 2904 | """ |
||
| 2905 | if not report_id: |
||
| 2906 | raise RequiredArgument('get_report requires a report_id argument') |
||
| 2907 | |||
| 2908 | cmd = XmlCommand('get_reports') |
||
| 2909 | cmd.set_attribute('report_id', report_id) |
||
| 2910 | |||
| 2911 | _add_filter(cmd, filter, filter_id) |
||
| 2912 | |||
| 2913 | if delta_report_id: |
||
| 2914 | cmd.set_attribute('delta_report_id', delta_report_id) |
||
| 2915 | |||
| 2916 | if report_format_id: |
||
| 2917 | cmd.set_attribute('format_id', report_format_id) |
||
| 2918 | |||
| 2919 | return self._send_xml_command(cmd) |
||
| 2920 | |||
| 2921 | def get_report_formats(self, *, filter=None, filter_id=None, trash=None, |
||
| 2922 | alerts=None, params=None, details=None): |
||
| 2923 | """Request a list of report formats |
||
| 2924 | |||
| 2925 | Arguments: |
||
| 2926 | filter (str, optional): Filter term to use for the query |
||
| 2927 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2928 | the query |
||
| 2929 | trash (boolean, optional): Whether to get the trashcan report |
||
| 2930 | formats instead |
||
| 2931 | alerts (boolean, optional): Whether to include alerts that use the |
||
| 2932 | report format |
||
| 2933 | params (boolean, optional): Whether to include report format |
||
| 2934 | parameters |
||
| 2935 | details (boolean, optional): Include report format file, signature |
||
| 2936 | and parameters |
||
| 2937 | |||
| 2938 | Returns: |
||
| 2939 | The response. See :py:meth:`send_command` for details. |
||
| 2940 | """ |
||
| 2941 | cmd = XmlCommand('get_report_formats') |
||
| 2942 | |||
| 2943 | _add_filter(cmd, filter, filter_id) |
||
| 2944 | |||
| 2945 | if not details is None: |
||
| 2946 | cmd.set_attribute('details', _to_bool(details)) |
||
| 2947 | |||
| 2948 | if not alerts is None: |
||
| 2949 | cmd.set_attribute('alerts', _to_bool(alerts)) |
||
| 2950 | |||
| 2951 | if not params is None: |
||
| 2952 | cmd.set_attribute('params', _to_bool(params)) |
||
| 2953 | |||
| 2954 | if not trash is None: |
||
| 2955 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 2956 | |||
| 2957 | return self._send_xml_command(cmd) |
||
| 2958 | |||
| 2959 | def get_report_format(self, report_format_id): |
||
| 2960 | """Request a single report format |
||
| 2961 | |||
| 2962 | Arguments: |
||
| 2963 | report_format_id (str): UUID of an existing report format |
||
| 2964 | |||
| 2965 | Returns: |
||
| 2966 | The response. See :py:meth:`send_command` for details. |
||
| 2967 | """ |
||
| 2968 | cmd = XmlCommand('get_report_formats') |
||
| 2969 | cmd.set_attribute('report_format_id', report_format_id) |
||
| 2970 | |||
| 2971 | # for single entity always request all details |
||
| 2972 | cmd.set_attribute('details', '1') |
||
| 2973 | return self._send_xml_command(cmd) |
||
| 2974 | |||
| 2975 | def get_results(self, *, filter=None, filter_id=None, task_id=None, |
||
| 2976 | note_details=None, override_details=None, details=None): |
||
| 2977 | """Request a list of results |
||
| 2978 | |||
| 2979 | Arguments: |
||
| 2980 | filter (str, optional): Filter term to use for the query |
||
| 2981 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 2982 | the query |
||
| 2983 | task_id (str, optional): UUID of task for note and override handling |
||
| 2984 | note_details (boolean, optional): If notes are included, whether to |
||
| 2985 | include note details |
||
| 2986 | override_details (boolean, optional): If overrides are included, |
||
| 2987 | whether to include override details |
||
| 2988 | details (boolean, optional): Whether to include additional details |
||
| 2989 | of the results |
||
| 2990 | |||
| 2991 | Returns: |
||
| 2992 | The response. See :py:meth:`send_command` for details. |
||
| 2993 | """ |
||
| 2994 | cmd = XmlCommand('get_results') |
||
| 2995 | |||
| 2996 | _add_filter(cmd, filter, filter_id) |
||
| 2997 | |||
| 2998 | if task_id: |
||
| 2999 | cmd.set_attribute('task_id', task_id) |
||
| 3000 | |||
| 3001 | if not details is None: |
||
| 3002 | cmd.set_attribute('details', _to_bool(details)) |
||
| 3003 | |||
| 3004 | if not note_details is None: |
||
| 3005 | cmd.set_attribute('note_details', _to_bool(note_details)) |
||
| 3006 | |||
| 3007 | if not override_details is None: |
||
| 3008 | cmd.set_attribute('override_details', _to_bool(override_details)) |
||
| 3009 | |||
| 3010 | return self._send_xml_command(cmd) |
||
| 3011 | |||
| 3012 | def get_result(self, result_id): |
||
| 3013 | """Request a single result |
||
| 3014 | |||
| 3015 | Arguments: |
||
| 3016 | result_id (str): UUID of an existing result |
||
| 3017 | |||
| 3018 | Returns: |
||
| 3019 | The response. See :py:meth:`send_command` for details. |
||
| 3020 | """ |
||
| 3021 | cmd = XmlCommand('get_results') |
||
| 3022 | cmd.set_attribute('result_id', result_id) |
||
| 3023 | |||
| 3024 | # for single entity always request all details |
||
| 3025 | cmd.set_attribute('details', '1') |
||
| 3026 | return self._send_xml_command(cmd) |
||
| 3027 | |||
| 3028 | def get_roles(self, *, filter=None, filter_id=None, trash=None): |
||
| 3029 | """Request a list of roles |
||
| 3030 | |||
| 3031 | Arguments: |
||
| 3032 | filter (str, optional): Filter term to use for the query |
||
| 3033 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3034 | the query |
||
| 3035 | trash (boolean, optional): Whether to get the trashcan roles instead |
||
| 3036 | |||
| 3037 | Returns: |
||
| 3038 | The response. See :py:meth:`send_command` for details. |
||
| 3039 | """ |
||
| 3040 | cmd = XmlCommand('get_roles') |
||
| 3041 | |||
| 3042 | _add_filter(cmd, filter, filter_id) |
||
| 3043 | |||
| 3044 | if not trash is None: |
||
| 3045 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 3046 | |||
| 3047 | return self._send_xml_command(cmd) |
||
| 3048 | |||
| 3049 | def get_role(self, role_id): |
||
| 3050 | """Request a single role |
||
| 3051 | |||
| 3052 | Arguments: |
||
| 3053 | role_id (str): UUID of an existing role |
||
| 3054 | |||
| 3055 | Returns: |
||
| 3056 | The response. See :py:meth:`send_command` for details. |
||
| 3057 | """ |
||
| 3058 | cmd = XmlCommand('get_roles') |
||
| 3059 | cmd.set_attribute('role_id', role_id) |
||
| 3060 | return self._send_xml_command(cmd) |
||
| 3061 | |||
| 3062 | def get_scanners(self, *, filter=None, filter_id=None, trash=None, |
||
| 3063 | details=None): |
||
| 3064 | """Request a list of scanners |
||
| 3065 | |||
| 3066 | Arguments: |
||
| 3067 | filter (str, optional): Filter term to use for the query |
||
| 3068 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3069 | the query |
||
| 3070 | trash (boolean, optional): Whether to get the trashcan scanners |
||
| 3071 | instead |
||
| 3072 | details (boolean, optional): Whether to include extra details like |
||
| 3073 | tasks using this scanner |
||
| 3074 | |||
| 3075 | Returns: |
||
| 3076 | The response. See :py:meth:`send_command` for details. |
||
| 3077 | """ |
||
| 3078 | cmd = XmlCommand('get_scanners') |
||
| 3079 | |||
| 3080 | _add_filter(cmd, filter, filter_id) |
||
| 3081 | |||
| 3082 | if not trash is None: |
||
| 3083 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 3084 | |||
| 3085 | if not details is None: |
||
| 3086 | cmd.set_attribute('details', _to_bool(details)) |
||
| 3087 | |||
| 3088 | return self._send_xml_command(cmd) |
||
| 3089 | |||
| 3090 | def get_scanner(self, scanner_id): |
||
| 3091 | """Request a single scanner |
||
| 3092 | |||
| 3093 | Arguments: |
||
| 3094 | scanner_id (str): UUID of an existing scanner |
||
| 3095 | |||
| 3096 | Returns: |
||
| 3097 | The response. See :py:meth:`send_command` for details. |
||
| 3098 | """ |
||
| 3099 | cmd = XmlCommand('get_scanners') |
||
| 3100 | cmd.set_attribute('scanner_id', scanner_id) |
||
| 3101 | |||
| 3102 | # for single entity always request all details |
||
| 3103 | cmd.set_attribute('details', '1') |
||
| 3104 | return self._send_xml_command(cmd) |
||
| 3105 | |||
| 3106 | View Code Duplication | def get_schedules(self, *, filter=None, filter_id=None, trash=None, |
|
| 3107 | tasks=None): |
||
| 3108 | """Request a list of schedules |
||
| 3109 | |||
| 3110 | Arguments: |
||
| 3111 | filter (str, optional): Filter term to use for the query |
||
| 3112 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3113 | the query |
||
| 3114 | trash (boolean, optional): Whether to get the trashcan schedules |
||
| 3115 | instead |
||
| 3116 | tasks (boolean, optional): Whether to include tasks using the |
||
| 3117 | schedules |
||
| 3118 | |||
| 3119 | Returns: |
||
| 3120 | The response. See :py:meth:`send_command` for details. |
||
| 3121 | """ |
||
| 3122 | cmd = XmlCommand('get_schedules') |
||
| 3123 | |||
| 3124 | _add_filter(cmd, filter, filter_id) |
||
| 3125 | |||
| 3126 | if not trash is None: |
||
| 3127 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 3128 | |||
| 3129 | if not tasks is None: |
||
| 3130 | cmd.set_attribute('tasks', _to_bool(tasks)) |
||
| 3131 | |||
| 3132 | return self._send_xml_command(cmd) |
||
| 3133 | |||
| 3134 | def get_schedule(self, schedule_id): |
||
| 3135 | """Request a single schedule |
||
| 3136 | |||
| 3137 | Arguments: |
||
| 3138 | schedule_id (str): UUID of an existing schedule |
||
| 3139 | |||
| 3140 | Returns: |
||
| 3141 | The response. See :py:meth:`send_command` for details. |
||
| 3142 | """ |
||
| 3143 | cmd = XmlCommand('get_schedules') |
||
| 3144 | cmd.set_attribute('schedule_id', schedule_id) |
||
| 3145 | return self._send_xml_command(cmd) |
||
| 3146 | |||
| 3147 | def get_settings(self, *, filter=None): |
||
| 3148 | """Request a list of user settings |
||
| 3149 | |||
| 3150 | Arguments: |
||
| 3151 | filter (str, optional): Filter term to use for the query |
||
| 3152 | |||
| 3153 | Returns: |
||
| 3154 | The response. See :py:meth:`send_command` for details. |
||
| 3155 | """ |
||
| 3156 | cmd = XmlCommand('get_settings') |
||
| 3157 | |||
| 3158 | if filter: |
||
| 3159 | cmd.set_attribute('filter', filter) |
||
| 3160 | |||
| 3161 | return self._send_xml_command(cmd) |
||
| 3162 | |||
| 3163 | def get_setting(self, setting_id): |
||
| 3164 | """Request a single setting |
||
| 3165 | |||
| 3166 | Arguments: |
||
| 3167 | setting_id (str): UUID of an existing setting |
||
| 3168 | |||
| 3169 | Returns: |
||
| 3170 | The response. See :py:meth:`send_command` for details. |
||
| 3171 | """ |
||
| 3172 | cmd = XmlCommand('get_settings') |
||
| 3173 | cmd.set_attribute('setting_id', setting_id) |
||
| 3174 | return self._send_xml_command(cmd) |
||
| 3175 | |||
| 3176 | def get_system_reports(self, *, name=None, duration=None, start_time=None, |
||
| 3177 | end_time=None, brief=None, slave_id=None): |
||
| 3178 | """Request a list of system reports |
||
| 3179 | |||
| 3180 | Arguments: |
||
| 3181 | name (str, optional): A string describing the required system report |
||
| 3182 | duration (int, optional): The number of seconds into the past that |
||
| 3183 | the system report should include |
||
| 3184 | start_time (str, optional): The start of the time interval the |
||
| 3185 | system report should include in ISO time format |
||
| 3186 | end_time (str, optional): The end of the time interval the system |
||
| 3187 | report should include in ISO time format |
||
| 3188 | brief (boolean, optional): Whether to include the actual system |
||
| 3189 | reports |
||
| 3190 | slave_id (str, optional): UUID of GMP scanner from which to get the |
||
| 3191 | system reports |
||
| 3192 | |||
| 3193 | Returns: |
||
| 3194 | The response. See :py:meth:`send_command` for details. |
||
| 3195 | """ |
||
| 3196 | cmd = XmlCommand('get_system_reports') |
||
| 3197 | |||
| 3198 | if name: |
||
| 3199 | cmd.set_attribute('name', name) |
||
| 3200 | |||
| 3201 | if not duration is None: |
||
| 3202 | cmd.set_attribute('duration', str(duration)) |
||
| 3203 | |||
| 3204 | if start_time: |
||
| 3205 | cmd.set_attribute('start_time', str(start_time)) |
||
| 3206 | |||
| 3207 | if end_time: |
||
| 3208 | cmd.set_attribute('end_time', str(end_time)) |
||
| 3209 | |||
| 3210 | if not brief is None: |
||
| 3211 | cmd.set_attribute('brief', _to_bool(brief)) |
||
| 3212 | |||
| 3213 | if slave_id: |
||
| 3214 | cmd.set_attribute('slave_id', slave_id) |
||
| 3215 | |||
| 3216 | return self._send_xml_command(cmd) |
||
| 3217 | |||
| 3218 | def get_tags(self, *, filter=None, filter_id=None, trash=None, |
||
| 3219 | names_only=None): |
||
| 3220 | """Request a list of tags |
||
| 3221 | |||
| 3222 | Arguments: |
||
| 3223 | filter (str, optional): Filter term to use for the query |
||
| 3224 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3225 | the query |
||
| 3226 | trash (boolean, optional): Whether to get tags from the trashcan |
||
| 3227 | instead |
||
| 3228 | names_only (boolean, optional): Whether to get only distinct tag |
||
| 3229 | names |
||
| 3230 | |||
| 3231 | Returns: |
||
| 3232 | The response. See :py:meth:`send_command` for details. |
||
| 3233 | """ |
||
| 3234 | cmd = XmlCommand('get_tags') |
||
| 3235 | |||
| 3236 | _add_filter(cmd, filter, filter_id) |
||
| 3237 | |||
| 3238 | if not trash is None: |
||
| 3239 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 3240 | |||
| 3241 | if not names_only is None: |
||
| 3242 | cmd.set_attribute('names_only', _to_bool(names_only)) |
||
| 3243 | |||
| 3244 | return self._send_xml_command(cmd) |
||
| 3245 | |||
| 3246 | def get_tag(self, tag_id): |
||
| 3247 | """Request a single tag |
||
| 3248 | |||
| 3249 | Arguments: |
||
| 3250 | tag_id (str): UUID of an existing tag |
||
| 3251 | |||
| 3252 | Returns: |
||
| 3253 | The response. See :py:meth:`send_command` for details. |
||
| 3254 | """ |
||
| 3255 | cmd = XmlCommand('get_tags') |
||
| 3256 | cmd.set_attribute('tag_id', tag_id) |
||
| 3257 | return self._send_xml_command(cmd) |
||
| 3258 | |||
| 3259 | View Code Duplication | def get_targets(self, *, filter=None, filter_id=None, trash=None, |
|
| 3260 | tasks=None): |
||
| 3261 | """Request a list of targets |
||
| 3262 | |||
| 3263 | Arguments: |
||
| 3264 | filter (str, optional): Filter term to use for the query |
||
| 3265 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3266 | the query |
||
| 3267 | trash (boolean, optional): Whether to get the trashcan targets |
||
| 3268 | instead |
||
| 3269 | tasks (boolean, optional): Whether to include list of tasks that |
||
| 3270 | use the target |
||
| 3271 | |||
| 3272 | Returns: |
||
| 3273 | The response. See :py:meth:`send_command` for details. |
||
| 3274 | """ |
||
| 3275 | cmd = XmlCommand('get_targets') |
||
| 3276 | |||
| 3277 | _add_filter(cmd, filter, filter_id) |
||
| 3278 | |||
| 3279 | if not trash is None: |
||
| 3280 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 3281 | |||
| 3282 | if not tasks is None: |
||
| 3283 | cmd.set_attribute('tasks', _to_bool(tasks)) |
||
| 3284 | |||
| 3285 | return self._send_xml_command(cmd) |
||
| 3286 | |||
| 3287 | def get_target(self, target_id): |
||
| 3288 | """Request a single target |
||
| 3289 | |||
| 3290 | Arguments: |
||
| 3291 | target_id (str): UUID of an existing target |
||
| 3292 | |||
| 3293 | Returns: |
||
| 3294 | The response. See :py:meth:`send_command` for details. |
||
| 3295 | """ |
||
| 3296 | cmd = XmlCommand('get_targets') |
||
| 3297 | cmd.set_attribute('target_id', target_id) |
||
| 3298 | return self._send_xml_command(cmd) |
||
| 3299 | |||
| 3300 | View Code Duplication | def get_tasks(self, *, filter=None, filter_id=None, trash=None, |
|
| 3301 | details=None, schedules_only=None): |
||
| 3302 | """Request a list of tasks |
||
| 3303 | |||
| 3304 | Arguments: |
||
| 3305 | filter (str, optional): Filter term to use for the query |
||
| 3306 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3307 | the query |
||
| 3308 | trash (boolean, optional): Whether to get the trashcan tasks instead |
||
| 3309 | details (boolean, optional): Whether to include full task details |
||
| 3310 | schedules_only (boolean, optional): Whether to only include id, name |
||
| 3311 | and schedule details |
||
| 3312 | |||
| 3313 | Returns: |
||
| 3314 | The response. See :py:meth:`send_command` for details. |
||
| 3315 | """ |
||
| 3316 | cmd = XmlCommand('get_tasks') |
||
| 3317 | |||
| 3318 | _add_filter(cmd, filter, filter_id) |
||
| 3319 | |||
| 3320 | if not trash is None: |
||
| 3321 | cmd.set_attribute('trash', _to_bool(trash)) |
||
| 3322 | |||
| 3323 | if not details is None: |
||
| 3324 | cmd.set_attribute('details', _to_bool(details)) |
||
| 3325 | |||
| 3326 | if not schedules_only is None: |
||
| 3327 | cmd.set_attribute('schedules_only', _to_bool(schedules_only)) |
||
| 3328 | |||
| 3329 | return self._send_xml_command(cmd) |
||
| 3330 | |||
| 3331 | def get_task(self, task_id): |
||
| 3332 | """Request a single task |
||
| 3333 | |||
| 3334 | Arguments: |
||
| 3335 | task_id (str): UUID of an existing task |
||
| 3336 | |||
| 3337 | Returns: |
||
| 3338 | The response. See :py:meth:`send_command` for details. |
||
| 3339 | """ |
||
| 3340 | if not task_id: |
||
| 3341 | raise RequiredArgument('get_task requires task_id argument') |
||
| 3342 | |||
| 3343 | cmd = XmlCommand('get_tasks') |
||
| 3344 | cmd.set_attribute('task_id', task_id) |
||
| 3345 | |||
| 3346 | # for single entity always request all details |
||
| 3347 | cmd.set_attribute('details', '1') |
||
| 3348 | return self._send_xml_command(cmd) |
||
| 3349 | |||
| 3350 | def get_users(self, *, filter=None, filter_id=None): |
||
| 3351 | """Request a list of users |
||
| 3352 | |||
| 3353 | Arguments: |
||
| 3354 | filter (str, optional): Filter term to use for the query |
||
| 3355 | filter_id (str, optional): UUID of an existing filter to use for |
||
| 3356 | the query |
||
| 3357 | |||
| 3358 | Returns: |
||
| 3359 | The response. See :py:meth:`send_command` for details. |
||
| 3360 | """ |
||
| 3361 | cmd = XmlCommand('get_users') |
||
| 3362 | |||
| 3363 | _add_filter(cmd, filter, filter_id) |
||
| 3364 | |||
| 3365 | return self._send_xml_command(cmd) |
||
| 3366 | |||
| 3367 | def get_user(self, user_id): |
||
| 3368 | """Request a single user |
||
| 3369 | |||
| 3370 | Arguments: |
||
| 3371 | user_id (str): UUID of an existing user |
||
| 3372 | |||
| 3373 | Returns: |
||
| 3374 | The response. See :py:meth:`send_command` for details. |
||
| 3375 | """ |
||
| 3376 | cmd = XmlCommand('get_users') |
||
| 3377 | cmd.set_attribute('user_id', user_id) |
||
| 3378 | return self._send_xml_command(cmd) |
||
| 3379 | |||
| 3380 | def get_version(self): |
||
| 3381 | """Get the Greenbone Manager Protocol version used by the remote gvmd |
||
| 3382 | |||
| 3383 | Returns: |
||
| 3384 | The response. See :py:meth:`send_command` for details. |
||
| 3385 | """ |
||
| 3386 | return self._send_xml_command(XmlCommand('get_version')) |
||
| 3387 | |||
| 3388 | def help(self, *, format=None, help_type=''): |
||
| 3389 | """Get the help text |
||
| 3390 | |||
| 3391 | Arguments: |
||
| 3392 | format (str, optional): One of "html", "rnc", "text" or "xml |
||
| 3393 | type (str, optional): One of "brief" or "". Default "" |
||
| 3394 | |||
| 3395 | Returns: |
||
| 3396 | The response. See :py:meth:`send_command` for details. |
||
| 3397 | """ |
||
| 3398 | cmd = XmlCommand('help') |
||
| 3399 | |||
| 3400 | if help_type not in ('', 'brief'): |
||
| 3401 | raise InvalidArgument( |
||
| 3402 | 'help_type argument must be an empty string or "brief"') |
||
| 3403 | |||
| 3404 | cmd.set_attribute('type', help_type) |
||
| 3405 | |||
| 3406 | if format: |
||
| 3407 | if not format.lower() in ('html', 'rnc', 'text', 'xml'): |
||
| 3408 | raise InvalidArgument( |
||
| 3409 | 'help format Argument must be one of html, rnc, text or ' |
||
| 3410 | 'xml') |
||
| 3411 | |||
| 3412 | cmd.set_attribute('format', format) |
||
| 3413 | |||
| 3414 | return self._send_xml_command(cmd) |
||
| 3415 | |||
| 3416 | def modify_agent(self, agent_id, *, name=None, comment=None): |
||
| 3417 | """Modifies an existing agent |
||
| 3418 | |||
| 3419 | Arguments: |
||
| 3420 | agent_id (str) UUID of the agent to be modified. |
||
| 3421 | name (str, optional): Name of the new credential |
||
| 3422 | comment (str, optional): Comment for the credential |
||
| 3423 | |||
| 3424 | Returns: |
||
| 3425 | The response. See :py:meth:`send_command` for details. |
||
| 3426 | """ |
||
| 3427 | if not agent_id: |
||
| 3428 | raise RequiredArgument('modify_agent requires agent_id argument') |
||
| 3429 | |||
| 3430 | cmd = XmlCommand('modify_agent') |
||
| 3431 | cmd.set_attribute('agent_id', str(agent_id)) |
||
| 3432 | if name: |
||
| 3433 | cmd.add_element('name', name) |
||
| 3434 | if comment: |
||
| 3435 | cmd.add_element('comment', comment) |
||
| 3436 | |||
| 3437 | return self._send_xml_command(cmd) |
||
| 3438 | |||
| 3439 | def modify_alert(self, alert_id, *, name=None, comment=None, |
||
| 3440 | filter_id=None, event=None, event_data=None, |
||
| 3441 | condition=None, condition_data=None, method=None, |
||
| 3442 | method_data=None): |
||
| 3443 | """Modifies an existing alert. |
||
| 3444 | |||
| 3445 | Arguments: |
||
| 3446 | alert_id (str) UUID of the alert to be modified. |
||
| 3447 | name (str, optional): Name of the Alert. |
||
| 3448 | condition (str, optional): The condition that must be satisfied |
||
| 3449 | for the alert to occur. |
||
| 3450 | condition_data (dict, optional): Data that defines the condition |
||
| 3451 | event (str, optional): The event that must happen for the alert |
||
| 3452 | to occur. |
||
| 3453 | event_data (dict, optional): Data that defines the event |
||
| 3454 | method (str, optional): The method by which the user is alerted |
||
| 3455 | method_data (dict, optional): Data that defines the method |
||
| 3456 | filter_id (str, optional): Filter to apply when executing alert |
||
| 3457 | comment (str, optional): Comment for the alert |
||
| 3458 | |||
| 3459 | Returns: |
||
| 3460 | The response. See :py:meth:`send_command` for details. |
||
| 3461 | """ |
||
| 3462 | |||
| 3463 | if not alert_id: |
||
| 3464 | raise RequiredArgument('modify_alert requires an alert_id argument') |
||
| 3465 | |||
| 3466 | cmd = XmlCommand('modify_alert') |
||
| 3467 | cmd.set_attribute('alert_id', str(alert_id)) |
||
| 3468 | |||
| 3469 | if name: |
||
| 3470 | cmd.add_element('name', name) |
||
| 3471 | |||
| 3472 | if comment: |
||
| 3473 | cmd.add_element('comment', comment) |
||
| 3474 | |||
| 3475 | if filter_id: |
||
| 3476 | cmd.add_element('filter', attrs={'id': filter_id}) |
||
| 3477 | |||
| 3478 | conditions = cmd.add_element('condition', condition) |
||
| 3479 | |||
| 3480 | if not condition_data is None: |
||
| 3481 | for value, key in condition_data.items(): |
||
| 3482 | _data = conditions.add_element('data', value) |
||
| 3483 | _data.add_element('name', key) |
||
| 3484 | |||
| 3485 | events = cmd.add_element('event', event) |
||
| 3486 | |||
| 3487 | if not event_data is None: |
||
| 3488 | for value, key in event_data.items(): |
||
| 3489 | _data = events.add_element('data', value) |
||
| 3490 | _data.add_element('name', key) |
||
| 3491 | |||
| 3492 | methods = cmd.add_element('method', method) |
||
| 3493 | |||
| 3494 | if not method_data is None: |
||
| 3495 | for value, key in method_data.items(): |
||
| 3496 | _data = methods.add_element('data', value) |
||
| 3497 | _data.add_element('name', key) |
||
| 3498 | |||
| 3499 | return self._send_xml_command(cmd) |
||
| 3500 | |||
| 3501 | def modify_asset(self, asset_id, comment): |
||
| 3502 | """Modifies an existing asset. |
||
| 3503 | |||
| 3504 | Arguments: |
||
| 3505 | asset_id (str) UUID of the asset to be modified. |
||
| 3506 | comment (str, optional): Comment for the asset. |
||
| 3507 | |||
| 3508 | Returns: |
||
| 3509 | The response. See :py:meth:`send_command` for details. |
||
| 3510 | """ |
||
| 3511 | if not asset_id: |
||
| 3512 | raise RequiredArgument('modify_asset requires an asset_id argument') |
||
| 3513 | |||
| 3514 | cmd = XmlCommand('modify_asset') |
||
| 3515 | cmd.set_attribute('asset_id', asset_id) |
||
| 3516 | cmd.add_element('comment', comment) |
||
| 3517 | |||
| 3518 | return self._send_xml_command(cmd) |
||
| 3519 | |||
| 3520 | def modify_auth(self, group_name, auth_conf_settings): |
||
| 3521 | """Modifies an existing auth. |
||
| 3522 | |||
| 3523 | Arguments: |
||
| 3524 | group_name (str) Name of the group to be modified. |
||
| 3525 | auth_conf_settings (dict): The new auth config. |
||
| 3526 | |||
| 3527 | Returns: |
||
| 3528 | The response. See :py:meth:`send_command` for details. |
||
| 3529 | """ |
||
| 3530 | if not group_name: |
||
| 3531 | raise RequiredArgument('modify_auth requires a group_name argument') |
||
| 3532 | if not auth_conf_settings: |
||
| 3533 | raise RequiredArgument('modify_auth requires an ' |
||
| 3534 | 'auth_conf_settings argument') |
||
| 3535 | cmd = XmlCommand('modify_auth') |
||
| 3536 | _xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)}) |
||
| 3537 | |||
| 3538 | for key, value in auth_conf_settings.items(): |
||
| 3539 | _xmlauthconf = _xmlgroup.add_element('auth_conf_setting') |
||
| 3540 | _xmlauthconf.add_element('key', key) |
||
| 3541 | _xmlauthconf.add_element('value', value) |
||
| 3542 | |||
| 3543 | return self._send_xml_command(cmd) |
||
| 3544 | |||
| 3545 | def modify_config(self, config_id, selection, *, nvt_oids=None, name=None, |
||
| 3546 | value=None, family=None): |
||
| 3547 | """Modifies an existing scan config. |
||
| 3548 | |||
| 3549 | Arguments: |
||
| 3550 | config_id (str): UUID of scan config to modify. |
||
| 3551 | selection (str): one of 'nvt_pref', nvt_selection or |
||
| 3552 | family_selection' |
||
| 3553 | name (str, optional): New name for preference. |
||
| 3554 | value(str, optional): New value for preference. |
||
| 3555 | nvt_oids (list, optional): List of NVTs associated with preference |
||
| 3556 | to modify. |
||
| 3557 | family (str,optional): Name of family to modify. |
||
| 3558 | |||
| 3559 | Returns: |
||
| 3560 | The response. See :py:meth:`send_command` for details. |
||
| 3561 | """ |
||
| 3562 | if not config_id: |
||
| 3563 | raise RequiredArgument('modify_config required config_id argument') |
||
| 3564 | |||
| 3565 | if selection not in ('nvt_pref', 'scan_pref', |
||
| 3566 | 'family_selection', 'nvt_selection'): |
||
| 3567 | raise InvalidArgument('selection must be one of nvt_pref, ' |
||
| 3568 | 'scan_pref, family_selection or ' |
||
| 3569 | 'nvt_selection') |
||
| 3570 | |||
| 3571 | cmd = XmlCommand('modify_config') |
||
| 3572 | cmd.set_attribute('config_id', str(config_id)) |
||
| 3573 | |||
| 3574 | if selection == 'nvt_pref': |
||
| 3575 | _xmlpref = cmd.add_element('preference') |
||
| 3576 | if not nvt_oids: |
||
| 3577 | raise InvalidArgument('modify_config requires a nvt_oids ' |
||
| 3578 | 'argument') |
||
| 3579 | _xmlpref.add_element('nvt', attrs={'oid': nvt_oids[0]}) |
||
| 3580 | _xmlpref.add_element('name', name) |
||
| 3581 | _xmlpref.add_element('value', value) |
||
| 3582 | |||
| 3583 | elif selection == 'nvt_selection': |
||
| 3584 | _xmlnvtsel = cmd.add_element('nvt_selection') |
||
| 3585 | _xmlnvtsel.add_element('family', family) |
||
| 3586 | |||
| 3587 | if nvt_oids: |
||
| 3588 | for nvt in nvt_oids: |
||
| 3589 | _xmlnvtsel.add_element('nvt', attrs={'oid': nvt}) |
||
| 3590 | else: |
||
| 3591 | raise InvalidArgument('modify_config requires a nvt_oid ' |
||
| 3592 | 'argument') |
||
| 3593 | |||
| 3594 | elif selection == 'family_selection': |
||
| 3595 | _xmlfamsel = cmd.add_element('family_selection') |
||
| 3596 | _xmlfamsel.add_element('growing', '1') |
||
| 3597 | _xmlfamily = _xmlfamsel.add_element('family') |
||
| 3598 | _xmlfamily.add_element('name', family) |
||
| 3599 | _xmlfamily.add_element('all', '1') |
||
| 3600 | _xmlfamily.add_element('growing', '1') |
||
| 3601 | |||
| 3602 | return self._send_xml_command(cmd) |
||
| 3603 | |||
| 3604 | def modify_credential(self, credential_id, credential_type=None, *, |
||
| 3605 | name=None, comment=None, allow_insecure=None, |
||
| 3606 | certificate=None, key_phrase=None, private_key=None, |
||
| 3607 | login=None, password=None, auth_algorithm=None, |
||
| 3608 | community=None, privacy_algorithm=None, |
||
| 3609 | privacy_password=None): |
||
| 3610 | """Modifies an existing credential. |
||
| 3611 | |||
| 3612 | Arguments: |
||
| 3613 | credential_id (str): UUID of the credential |
||
| 3614 | credential_type (str, optional): The credential type. One of 'cc', |
||
| 3615 | 'snmp', 'up', 'usk' |
||
| 3616 | name (str, optional): Name of the credential |
||
| 3617 | comment (str, optional): Comment for the credential |
||
| 3618 | allow_insecure (boolean, optional): Whether to allow insecure use of |
||
| 3619 | the credential |
||
| 3620 | certificate (str, optional): Certificate for the credential |
||
| 3621 | key_phrase (str, optional): Key passphrase for the private key |
||
| 3622 | private_key (str, optional): Private key to use for login |
||
| 3623 | login (str, optional): Username for the credential |
||
| 3624 | password (str, optional): Password for the credential |
||
| 3625 | auth_algorithm (str, optional): The auth_algorithm, |
||
| 3626 | either md5 or sha1. |
||
| 3627 | community (str, optional): The SNMP community |
||
| 3628 | privacy_algorithm (str, optional): The SNMP privacy algorithm, |
||
| 3629 | either aes or des. |
||
| 3630 | privacy_password (str, optional): The SNMP privacy password |
||
| 3631 | |||
| 3632 | Returns: |
||
| 3633 | The response. See :py:meth:`send_command` for details. |
||
| 3634 | """ |
||
| 3635 | if not credential_id: |
||
| 3636 | raise RequiredArgument('modify_credential requires ' |
||
| 3637 | 'a credential_id attribute') |
||
| 3638 | |||
| 3639 | cmd = XmlCommand('modify_credential') |
||
| 3640 | cmd.set_attribute('credential_id', credential_id) |
||
| 3641 | |||
| 3642 | if credential_type: |
||
| 3643 | if credential_type not in ('cc', 'snmp', 'up', 'usk'): |
||
| 3644 | raise RequiredArgument('modify_credential requires type ' |
||
| 3645 | 'to be either cc, snmp, up or usk') |
||
| 3646 | |||
| 3647 | cmd.add_element('type', credential_type) |
||
| 3648 | |||
| 3649 | if comment: |
||
| 3650 | cmd.add_element('comment', comment) |
||
| 3651 | |||
| 3652 | if name: |
||
| 3653 | cmd.add_element('name', name) |
||
| 3654 | |||
| 3655 | if allow_insecure: |
||
| 3656 | cmd.add_element('allow_insecure', allow_insecure) |
||
| 3657 | |||
| 3658 | if certificate: |
||
| 3659 | cmd.add_element('certificate', certificate) |
||
| 3660 | |||
| 3661 | if key_phrase or private_key: |
||
| 3662 | if not key_phrase or not private_key: |
||
| 3663 | raise RequiredArgument('modify_credential requires ' |
||
| 3664 | 'a key_phrase and private_key arguments') |
||
| 3665 | _xmlkey = cmd.add_element('key') |
||
| 3666 | _xmlkey.add_element('phrase', key_phrase) |
||
| 3667 | _xmlkey.add_element('private', private_key) |
||
| 3668 | |||
| 3669 | if login: |
||
| 3670 | cmd.add_element('login', login) |
||
| 3671 | |||
| 3672 | if password: |
||
| 3673 | cmd.add_element('password', password) |
||
| 3674 | |||
| 3675 | if auth_algorithm: |
||
| 3676 | if auth_algorithm not in ('md5', 'sha1'): |
||
| 3677 | raise RequiredArgument('modify_credential requires ' |
||
| 3678 | 'auth_algorithm to be either ' |
||
| 3679 | 'md5 or sha1') |
||
| 3680 | cmd.add_element('auth_algorithm', auth_algorithm) |
||
| 3681 | |||
| 3682 | if community: |
||
| 3683 | cmd.add_element('community', community) |
||
| 3684 | |||
| 3685 | if privacy_algorithm: |
||
| 3686 | if privacy_algorithm not in ('aes', 'des'): |
||
| 3687 | raise RequiredArgument('modify_credential requires ' |
||
| 3688 | 'privacy_algorithm to be either' |
||
| 3689 | 'aes or des') |
||
| 3690 | _xmlprivacy = cmd.add_element('privacy') |
||
| 3691 | _xmlprivacy.add_element('algorithm', privacy_algorithm) |
||
| 3692 | _xmlprivacy.add_element('password', privacy_password) |
||
| 3693 | |||
| 3694 | return self._send_xml_command(cmd) |
||
| 3695 | |||
| 3696 | def modify_filter(self, filter_id, *, comment=None, name=None, term=None, |
||
| 3697 | filter_type=None): |
||
| 3698 | """Modifies an existing filter. |
||
| 3699 | |||
| 3700 | Arguments: |
||
| 3701 | filter_id (str): UUID of the filter to be modified |
||
| 3702 | comment (str, optional): Comment on filter. |
||
| 3703 | name (str, optional): Name of filter. |
||
| 3704 | term (str, optional): Filter term. |
||
| 3705 | filter_type (str, optional): Resource type filter applies to. |
||
| 3706 | |||
| 3707 | Returns: |
||
| 3708 | The response. See :py:meth:`send_command` for details. |
||
| 3709 | """ |
||
| 3710 | if not filter_id: |
||
| 3711 | raise RequiredArgument('modify_filter requires a filter_id ' |
||
| 3712 | 'attribute') |
||
| 3713 | |||
| 3714 | cmd = XmlCommand('modify_filter') |
||
| 3715 | cmd.set_attribute('filter_id', filter_id) |
||
| 3716 | |||
| 3717 | if comment: |
||
| 3718 | cmd.add_element('comment', comment) |
||
| 3719 | |||
| 3720 | if name: |
||
| 3721 | cmd.add_element('name', name) |
||
| 3722 | |||
| 3723 | if term: |
||
| 3724 | cmd.add_element('term', term) |
||
| 3725 | |||
| 3726 | if filter_type: |
||
| 3727 | filter_type = filter_type.lower() |
||
| 3728 | if filter_type not in FILTER_TYPES: |
||
| 3729 | raise InvalidArgument( |
||
| 3730 | 'modify_filter requires type to be one of {0} but ' |
||
| 3731 | 'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
||
| 3732 | cmd.add_element('type', filter_type) |
||
| 3733 | |||
| 3734 | return self._send_xml_command(cmd) |
||
| 3735 | |||
| 3736 | def modify_group(self, group_id, *, comment=None, name=None, |
||
| 3737 | users=None): |
||
| 3738 | """Modifies an existing group. |
||
| 3739 | |||
| 3740 | Arguments: |
||
| 3741 | group_id (str): UUID of group to modify. |
||
| 3742 | comment (str, optional): Comment on group. |
||
| 3743 | name (str, optional): Name of group. |
||
| 3744 | users (list, optional): List of user names to be in the group |
||
| 3745 | |||
| 3746 | Returns: |
||
| 3747 | The response. See :py:meth:`send_command` for details. |
||
| 3748 | """ |
||
| 3749 | if not group_id: |
||
| 3750 | raise RequiredArgument('modify_group requires a group_id argument') |
||
| 3751 | |||
| 3752 | cmd = XmlCommand('modify_group') |
||
| 3753 | cmd.set_attribute('group_id', group_id) |
||
| 3754 | |||
| 3755 | if comment: |
||
| 3756 | cmd.add_element('comment', comment) |
||
| 3757 | |||
| 3758 | if name: |
||
| 3759 | cmd.add_element('name', name) |
||
| 3760 | |||
| 3761 | if users: |
||
| 3762 | cmd.add_element('users', ','.join(users)) |
||
| 3763 | |||
| 3764 | return self._send_xml_command(cmd) |
||
| 3765 | |||
| 3766 | def modify_note(self, note_id, text, *, seconds_active=None, hosts=None, |
||
| 3767 | port=None, result_id=None, severity=None, task_id=None, |
||
| 3768 | threat=None): |
||
| 3769 | """Modifies an existing note. |
||
| 3770 | |||
| 3771 | Arguments: |
||
| 3772 | note_id (str): UUID of note to modify. |
||
| 3773 | text (str): The text of the note. |
||
| 3774 | seconds_active (int, optional): Seconds note will be active. |
||
| 3775 | -1 on always, 0 off. |
||
| 3776 | hosts (list, optional): A list of hosts addresses |
||
| 3777 | port (str, optional): Port to which note applies. |
||
| 3778 | result_id (str, optional): Result to which note applies. |
||
| 3779 | severity (str, optional): Severity to which note applies. |
||
| 3780 | task_id (str, optional): Task to which note applies. |
||
| 3781 | threat (str, optional): Threat level to which note applies. |
||
| 3782 | |||
| 3783 | Returns: |
||
| 3784 | The response. See :py:meth:`send_command` for details. |
||
| 3785 | """ |
||
| 3786 | if not note_id: |
||
| 3787 | raise RequiredArgument('modify_note requires a note_id attribute') |
||
| 3788 | if not text: |
||
| 3789 | raise RequiredArgument('modify_note requires a text element') |
||
| 3790 | |||
| 3791 | cmd = XmlCommand('modify_note') |
||
| 3792 | cmd.set_attribute('note_id', note_id) |
||
| 3793 | cmd.add_element('text', text) |
||
| 3794 | |||
| 3795 | if not seconds_active is None: |
||
| 3796 | cmd.add_element('active', str(seconds_active)) |
||
| 3797 | |||
| 3798 | if hosts: |
||
| 3799 | cmd.add_element('hosts', ', '.join(hosts)) |
||
| 3800 | |||
| 3801 | if port: |
||
| 3802 | cmd.add_element('port', port) |
||
| 3803 | |||
| 3804 | if result_id: |
||
| 3805 | cmd.add_element('result', attrs={'id': result_id}) |
||
| 3806 | |||
| 3807 | if severity: |
||
| 3808 | cmd.add_element('severity', severity) |
||
| 3809 | |||
| 3810 | if task_id: |
||
| 3811 | cmd.add_element('task', attrs={'id': task_id}) |
||
| 3812 | |||
| 3813 | if threat: |
||
| 3814 | cmd.add_element('threat', threat) |
||
| 3815 | |||
| 3816 | return self._send_xml_command(cmd) |
||
| 3817 | |||
| 3818 | View Code Duplication | def modify_override(self, override_id, text, *, seconds_active=None, |
|
| 3819 | hosts=None, port=None, result_id=None, severity=None, |
||
| 3820 | new_severity=None, task_id=None, threat=None, |
||
| 3821 | new_threat=None): |
||
| 3822 | """Modifies an existing override. |
||
| 3823 | |||
| 3824 | Arguments: |
||
| 3825 | override_id (str): UUID of override to modify. |
||
| 3826 | text (str): The text of the override. |
||
| 3827 | seconds_active (int, optional): Seconds override will be active. |
||
| 3828 | -1 on always, 0 off. |
||
| 3829 | hosts (list, optional): A list of host addresses |
||
| 3830 | port (str, optional): Port to which override applies. |
||
| 3831 | result_id (str, optional): Result to which override applies. |
||
| 3832 | severity (str, optional): Severity to which override applies. |
||
| 3833 | new_severity (str, optional): New severity score for result. |
||
| 3834 | task_id (str, optional): Task to which override applies. |
||
| 3835 | threat (str, optional): Threat level to which override applies. |
||
| 3836 | new_threat (str, optional): New threat level for results. |
||
| 3837 | |||
| 3838 | Returns: |
||
| 3839 | The response. See :py:meth:`send_command` for details. |
||
| 3840 | """ |
||
| 3841 | if not override_id: |
||
| 3842 | raise RequiredArgument('modify_override requires a override_id ' |
||
| 3843 | 'argument') |
||
| 3844 | if not text: |
||
| 3845 | raise RequiredArgument('modify_override requires a text argument') |
||
| 3846 | |||
| 3847 | cmd = XmlCommand('modify_override') |
||
| 3848 | cmd.set_attribute('override_id', override_id) |
||
| 3849 | cmd.add_element('text', text) |
||
| 3850 | |||
| 3851 | if not seconds_active is None: |
||
| 3852 | cmd.add_element('active', str(seconds_active)) |
||
| 3853 | |||
| 3854 | if hosts: |
||
| 3855 | cmd.add_element('hosts', ', '.join(hosts)) |
||
| 3856 | |||
| 3857 | if port: |
||
| 3858 | cmd.add_element('port', port) |
||
| 3859 | |||
| 3860 | if result_id: |
||
| 3861 | cmd.add_element('result', attrs={'id': result_id}) |
||
| 3862 | |||
| 3863 | if severity: |
||
| 3864 | cmd.add_element('severity', severity) |
||
| 3865 | |||
| 3866 | if new_severity: |
||
| 3867 | cmd.add_element('new_severity', new_severity) |
||
| 3868 | |||
| 3869 | if task_id: |
||
| 3870 | cmd.add_element('task', attrs={'id': task_id}) |
||
| 3871 | |||
| 3872 | if threat: |
||
| 3873 | cmd.add_element('threat', threat) |
||
| 3874 | |||
| 3875 | if new_threat: |
||
| 3876 | cmd.add_element('new_threat', new_threat) |
||
| 3877 | |||
| 3878 | return self._send_xml_command(cmd) |
||
| 3879 | |||
| 3880 | def modify_permission(self, permission_id, *, comment=None, name=None, |
||
| 3881 | resource_id=None, resource_type=None, |
||
| 3882 | subject_id=None, subject_type=None): |
||
| 3883 | """Modifies an existing permission. |
||
| 3884 | |||
| 3885 | Arguments: |
||
| 3886 | permission_id (str): UUID of permission to be modified. |
||
| 3887 | comment (str, optional): The comment on the permission. |
||
| 3888 | name (str, optional): Permission name, currently the name of |
||
| 3889 | a command. |
||
| 3890 | subject_id (str, optional): UUID of subject to whom the permission |
||
| 3891 | is granted |
||
| 3892 | subject_type (str, optional): Type of the subject user, group or |
||
| 3893 | role |
||
| 3894 | resource_id (str, optional): UUID of entity to which the permission |
||
| 3895 | applies |
||
| 3896 | resource_type (str, optional): Type of the resource. For Super |
||
| 3897 | permissions user, group or role |
||
| 3898 | |||
| 3899 | Returns: |
||
| 3900 | The response. See :py:meth:`send_command` for details. |
||
| 3901 | """ |
||
| 3902 | if not permission_id: |
||
| 3903 | raise RequiredArgument('modify_permission requires ' |
||
| 3904 | 'a permission_id element') |
||
| 3905 | |||
| 3906 | cmd = XmlCommand('modify_permission') |
||
| 3907 | cmd.set_attribute('permission_id', permission_id) |
||
| 3908 | |||
| 3909 | if comment: |
||
| 3910 | cmd.add_element('comment', comment) |
||
| 3911 | |||
| 3912 | if name: |
||
| 3913 | cmd.add_element('name', name) |
||
| 3914 | |||
| 3915 | if resource_id and resource_type: |
||
| 3916 | _xmlresource = cmd.add_element('resource', |
||
| 3917 | attrs={'id': resource_id}) |
||
| 3918 | _xmlresource.add_element('type', resource_type) |
||
| 3919 | |||
| 3920 | if subject_id and subject_type: |
||
| 3921 | _xmlsubject = cmd.add_element('subject', |
||
| 3922 | attrs={'id': subject_id}) |
||
| 3923 | _xmlsubject.add_element('type', subject_type) |
||
| 3924 | |||
| 3925 | return self._send_xml_command(cmd) |
||
| 3926 | |||
| 3927 | def modify_port_list(self, port_list_id, *, comment=None, name=None): |
||
| 3928 | """Modifies an existing port list. |
||
| 3929 | |||
| 3930 | Arguments: |
||
| 3931 | port_list_id (str): UUID of port list to modify. |
||
| 3932 | name (str, optional): Name of port list. |
||
| 3933 | comment (str, optional): Comment on port list. |
||
| 3934 | |||
| 3935 | Returns: |
||
| 3936 | The response. See :py:meth:`send_command` for details. |
||
| 3937 | """ |
||
| 3938 | if not port_list_id: |
||
| 3939 | raise RequiredArgument('modify_port_list requires ' |
||
| 3940 | 'a port_list_id attribute') |
||
| 3941 | cmd = XmlCommand('modify_port_list') |
||
| 3942 | cmd.set_attribute('port_list_id', port_list_id) |
||
| 3943 | |||
| 3944 | if comment: |
||
| 3945 | cmd.add_element('comment', comment) |
||
| 3946 | |||
| 3947 | if name: |
||
| 3948 | cmd.add_element('name', name) |
||
| 3949 | |||
| 3950 | return self._send_xml_command(cmd) |
||
| 3951 | |||
| 3952 | def modify_report(self, report_id, comment): |
||
| 3953 | """Modifies an existing report. |
||
| 3954 | |||
| 3955 | Arguments: |
||
| 3956 | report_id (str): UUID of report to modify. |
||
| 3957 | comment (str): The comment on the report. |
||
| 3958 | |||
| 3959 | Returns: |
||
| 3960 | The response. See :py:meth:`send_command` for details. |
||
| 3961 | """ |
||
| 3962 | if not report_id: |
||
| 3963 | raise RequiredArgument('modify_report requires ' |
||
| 3964 | 'a report_id attribute') |
||
| 3965 | if not comment: |
||
| 3966 | raise RequiredArgument('modify_report requires ' |
||
| 3967 | 'a comment attribute') |
||
| 3968 | cmd = XmlCommand('modify_report') |
||
| 3969 | cmd.set_attribute('report_id', report_id) |
||
| 3970 | cmd.add_element('comment', comment) |
||
| 3971 | |||
| 3972 | return self._send_xml_command(cmd) |
||
| 3973 | |||
| 3974 | def modify_report_format(self, report_format_id, *, active=None, name=None, |
||
| 3975 | summary=None, param_name=None, param_value=None): |
||
| 3976 | """Modifies an existing report format. |
||
| 3977 | |||
| 3978 | Arguments: |
||
| 3979 | report_format_id (str) UUID of report format to modify. |
||
| 3980 | active (boolean, optional): Whether the report format is active. |
||
| 3981 | name (str, optional): The name of the report format. |
||
| 3982 | summary (str, optional): A summary of the report format. |
||
| 3983 | param_name (str, optional): The name of the param. |
||
| 3984 | param_value (str, optional): The value of the param. |
||
| 3985 | |||
| 3986 | Returns: |
||
| 3987 | The response. See :py:meth:`send_command` for details. |
||
| 3988 | """ |
||
| 3989 | if not report_format_id: |
||
| 3990 | raise RequiredArgument('modify_report requires ' |
||
| 3991 | 'a report_format_id attribute') |
||
| 3992 | cmd = XmlCommand('modify_report_format') |
||
| 3993 | cmd.set_attribute('report_format_id', report_format_id) |
||
| 3994 | |||
| 3995 | if not active is None: |
||
| 3996 | cmd.add_element('active', '1' if active else '0') |
||
| 3997 | |||
| 3998 | if name: |
||
| 3999 | cmd.add_element('name', name) |
||
| 4000 | |||
| 4001 | if summary: |
||
| 4002 | cmd.add_element('summary', summary) |
||
| 4003 | |||
| 4004 | if param_name and param_value: |
||
| 4005 | _xmlparam = cmd.add_element('param') |
||
| 4006 | _xmlparam.add_element('name', param_name) |
||
| 4007 | _xmlparam.add_element('value', param_value) |
||
| 4008 | |||
| 4009 | return self._send_xml_command(cmd) |
||
| 4010 | |||
| 4011 | def modify_role(self, role_id, *, comment=None, name=None, users=None): |
||
| 4012 | """Modifies an existing role. |
||
| 4013 | |||
| 4014 | Arguments: |
||
| 4015 | role_id (str): UUID of role to modify. |
||
| 4016 | comment (str, optional): Name of role. |
||
| 4017 | name (str, optional): Comment on role. |
||
| 4018 | users (list, optional): List of user names. |
||
| 4019 | |||
| 4020 | Returns: |
||
| 4021 | The response. See :py:meth:`send_command` for details. |
||
| 4022 | """ |
||
| 4023 | if not role_id: |
||
| 4024 | raise RequiredArgument('modify_role requires a role_id argument') |
||
| 4025 | |||
| 4026 | cmd = XmlCommand('modify_role') |
||
| 4027 | cmd.set_attribute('role_id', role_id) |
||
| 4028 | |||
| 4029 | if comment: |
||
| 4030 | cmd.add_element('comment', comment) |
||
| 4031 | |||
| 4032 | if name: |
||
| 4033 | cmd.add_element('name', name) |
||
| 4034 | |||
| 4035 | if users: |
||
| 4036 | cmd.add_element('users', ",".join(users)) |
||
| 4037 | |||
| 4038 | return self._send_xml_command(cmd) |
||
| 4039 | |||
| 4040 | View Code Duplication | def modify_scanner(self, scanner_id, host, port, scanner_type, *, |
|
| 4041 | comment=None, name=None, ca_pub=None, |
||
| 4042 | credential_id=None): |
||
| 4043 | """Modifies an existing scanner. |
||
| 4044 | |||
| 4045 | Arguments: |
||
| 4046 | scanner_id (str): UUID of scanner to modify. |
||
| 4047 | host (str): Host of the scanner. |
||
| 4048 | port (str): Port of the scanner. |
||
| 4049 | scanner_type (str): Type of the scanner. |
||
| 4050 | '1' for OSP, '2' for OpenVAS (classic) Scanner. |
||
| 4051 | comment (str, optional): Comment on scanner. |
||
| 4052 | name (str, optional): Name of scanner. |
||
| 4053 | ca_pub (str, optional): Certificate of CA to verify scanner's |
||
| 4054 | certificate. |
||
| 4055 | credential_id (str, optional): UUID of the client certificate |
||
| 4056 | credential for the Scanner. |
||
| 4057 | |||
| 4058 | Returns: |
||
| 4059 | The response. See :py:meth:`send_command` for details. |
||
| 4060 | """ |
||
| 4061 | if not scanner_id: |
||
| 4062 | raise RequiredArgument( |
||
| 4063 | 'modify_scanner requires a scanner_id argument') |
||
| 4064 | if not host: |
||
| 4065 | raise RequiredArgument('modify_scanner requires a host argument') |
||
| 4066 | if not port: |
||
| 4067 | raise RequiredArgument('modify_scanner requires a port argument') |
||
| 4068 | if not scanner_type: |
||
| 4069 | raise RequiredArgument('modify_scanner requires a scanner_type ' |
||
| 4070 | 'argument') |
||
| 4071 | |||
| 4072 | cmd = XmlCommand('modify_scanner') |
||
| 4073 | cmd.set_attribute('scanner_id', scanner_id) |
||
| 4074 | cmd.add_element('host', host) |
||
| 4075 | cmd.add_element('port', port) |
||
| 4076 | |||
| 4077 | if scanner_type not in SCANNER_TYPES: |
||
| 4078 | raise InvalidArgument('modify_scanner requires a scanner_type ' |
||
| 4079 | 'argument which must be either "1" for OSP ' |
||
| 4080 | 'or "2" OpenVAS (Classic).') |
||
| 4081 | |||
| 4082 | cmd.add_element('type', scanner_type) |
||
| 4083 | |||
| 4084 | if comment: |
||
| 4085 | cmd.add_element('comment', comment) |
||
| 4086 | |||
| 4087 | if name: |
||
| 4088 | cmd.add_element('name', name) |
||
| 4089 | |||
| 4090 | if ca_pub: |
||
| 4091 | cmd.add_element('ca_pub', ca_pub) |
||
| 4092 | |||
| 4093 | if credential_id: |
||
| 4094 | cmd.add_element('credential', attrs={'id': str(credential_id)}) |
||
| 4095 | |||
| 4096 | return self._send_xml_command(cmd) |
||
| 4097 | |||
| 4098 | def modify_schedule(self, schedule_id, *, comment=None, name=None, |
||
| 4099 | first_time_minute=None, first_time_hour=None, |
||
| 4100 | first_time_day_of_month=None, first_time_month=None, |
||
| 4101 | first_time_year=None, duration=None, duration_unit=None, |
||
| 4102 | period=None, period_unit=None, timezone=None): |
||
| 4103 | """Modifies an existing schedule. |
||
| 4104 | |||
| 4105 | Arguments: |
||
| 4106 | schedule_id (str): UUID of schedule to modify. |
||
| 4107 | name (str, optional): Name of the schedule |
||
| 4108 | comment (str, optional): Comment for the schedule |
||
| 4109 | first_time_minute (int, optional): First time minute the schedule |
||
| 4110 | will run |
||
| 4111 | first_time_hour (int, optional): First time hour the schedule |
||
| 4112 | will run |
||
| 4113 | first_time_day_of_month (int, optional): First time day of month the |
||
| 4114 | schedule will run |
||
| 4115 | first_time_month (int, optional): First time month the schedule |
||
| 4116 | will run |
||
| 4117 | first_time_year (int, optional): First time year the schedule |
||
| 4118 | will run |
||
| 4119 | duration (int, optional): How long the Manager will run the |
||
| 4120 | scheduled task for until it gets paused if not finished yet. |
||
| 4121 | duration_unit (str, optional): Unit of the duration. One of second, |
||
| 4122 | minute, hour, day, week, month, year, decade. Required if |
||
| 4123 | duration is set. |
||
| 4124 | period (int, optional): How often the Manager will repeat the |
||
| 4125 | scheduled task |
||
| 4126 | period_unit (str, optional): Unit of the period. One of second, |
||
| 4127 | minute, hour, day, week, month, year, decade. Required if |
||
| 4128 | period is set. |
||
| 4129 | timezone (str, optional): The timezone the schedule will follow |
||
| 4130 | |||
| 4131 | Returns: |
||
| 4132 | The response. See :py:meth:`send_command` for details. |
||
| 4133 | """ |
||
| 4134 | if not schedule_id: |
||
| 4135 | raise RequiredArgument('modify_schedule requires a schedule_id' |
||
| 4136 | 'argument') |
||
| 4137 | |||
| 4138 | cmd = XmlCommand('modify_schedule') |
||
| 4139 | cmd.set_attribute('schedule_id', schedule_id) |
||
| 4140 | |||
| 4141 | if comment: |
||
| 4142 | cmd.add_element('comment', comment) |
||
| 4143 | |||
| 4144 | if name: |
||
| 4145 | cmd.add_element('name', name) |
||
| 4146 | |||
| 4147 | View Code Duplication | if first_time_minute or first_time_hour or first_time_day_of_month or \ |
|
| 4148 | first_time_month or first_time_year: |
||
| 4149 | |||
| 4150 | if not first_time_minute: |
||
| 4151 | raise RequiredArgument( |
||
| 4152 | 'Setting first_time requires first_time_minute argument') |
||
| 4153 | if not first_time_hour: |
||
| 4154 | raise RequiredArgument( |
||
| 4155 | 'Setting first_time requires first_time_hour argument') |
||
| 4156 | if not first_time_day_of_month: |
||
| 4157 | raise RequiredArgument( |
||
| 4158 | 'Setting first_time requires first_time_day_of_month ' |
||
| 4159 | 'argument') |
||
| 4160 | if not first_time_month: |
||
| 4161 | raise RequiredArgument( |
||
| 4162 | 'Setting first_time requires first_time_month argument') |
||
| 4163 | if not first_time_year: |
||
| 4164 | raise RequiredArgument( |
||
| 4165 | 'Setting first_time requires first_time_year argument') |
||
| 4166 | |||
| 4167 | _xmlftime = cmd.add_element('first_time') |
||
| 4168 | _xmlftime.add_element('minute', str(first_time_minute)) |
||
| 4169 | _xmlftime.add_element('hour', str(first_time_hour)) |
||
| 4170 | _xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
||
| 4171 | _xmlftime.add_element('month', str(first_time_month)) |
||
| 4172 | _xmlftime.add_element('year', str(first_time_year)) |
||
| 4173 | |||
| 4174 | View Code Duplication | if duration: |
|
| 4175 | if not duration_unit: |
||
| 4176 | raise RequiredArgument( |
||
| 4177 | 'Setting duration requires duration_unit argument') |
||
| 4178 | |||
| 4179 | if not duration_unit in TIME_UNITS: |
||
| 4180 | raise InvalidArgument( |
||
| 4181 | 'duration_unit must be one of {units} but {actual} has ' |
||
| 4182 | 'been passed'.format( |
||
| 4183 | units=', '.join(TIME_UNITS), actual=duration_unit)) |
||
| 4184 | |||
| 4185 | _xmlduration = cmd.add_element('duration', str(duration)) |
||
| 4186 | _xmlduration.add_element('unit', duration_unit) |
||
| 4187 | |||
| 4188 | View Code Duplication | if period: |
|
| 4189 | if not period_unit: |
||
| 4190 | raise RequiredArgument( |
||
| 4191 | 'Setting period requires period_unit argument') |
||
| 4192 | |||
| 4193 | if not period_unit in TIME_UNITS: |
||
| 4194 | raise InvalidArgument( |
||
| 4195 | 'period_unit must be one of {units} but {actual} has ' |
||
| 4196 | 'been passed'.format( |
||
| 4197 | units=', '.join(TIME_UNITS), actual=period_unit)) |
||
| 4198 | |||
| 4199 | _xmlperiod = cmd.add_element('period', str(period)) |
||
| 4200 | _xmlperiod.add_element('unit', period_unit) |
||
| 4201 | |||
| 4202 | if timezone: |
||
| 4203 | cmd.add_element('timezone', str(timezone)) |
||
| 4204 | |||
| 4205 | return self._send_xml_command(cmd) |
||
| 4206 | |||
| 4207 | def modify_setting(self, setting_id, name, value): |
||
| 4208 | """Modifies an existing setting. |
||
| 4209 | |||
| 4210 | Arguments: |
||
| 4211 | setting_id (str): UUID of the setting to be changed. |
||
| 4212 | name (str): The name of the setting. |
||
| 4213 | value (str): The value of the setting. |
||
| 4214 | |||
| 4215 | Returns: |
||
| 4216 | The response. See :py:meth:`send_command` for details. |
||
| 4217 | """ |
||
| 4218 | if not setting_id: |
||
| 4219 | raise RequiredArgument('modify_setting requires a setting_id' |
||
| 4220 | 'argument') |
||
| 4221 | if not name: |
||
| 4222 | raise RequiredArgument('modify_setting requires a name argument') |
||
| 4223 | |||
| 4224 | if not value: |
||
| 4225 | raise RequiredArgument('modify_setting requires a value argument') |
||
| 4226 | |||
| 4227 | cmd = XmlCommand('modify_setting') |
||
| 4228 | cmd.set_attribute('setting_id', setting_id) |
||
| 4229 | cmd.add_element('name', name) |
||
| 4230 | cmd.add_element('value', value) |
||
| 4231 | |||
| 4232 | return self._send_xml_command(cmd) |
||
| 4233 | |||
| 4234 | def modify_tag(self, tag_id, *, comment=None, name=None, value=None, |
||
| 4235 | active=None, resource_id=None, resource_type=None): |
||
| 4236 | """Modifies an existing tag. |
||
| 4237 | |||
| 4238 | Arguments: |
||
| 4239 | tag_id (str): UUID of the tag. |
||
| 4240 | comment (str, optional): Comment to add to the tag. |
||
| 4241 | name (str, optional): Name of the tag. |
||
| 4242 | value (str, optional): Value of the tag. |
||
| 4243 | active (boolean, optional): Whether the tag is active. |
||
| 4244 | resource_id (str, optional): IDs of the resource to which to |
||
| 4245 | attach the tag. |
||
| 4246 | resource_type (str, optional): Type of the resource to which to |
||
| 4247 | attach the tag. |
||
| 4248 | |||
| 4249 | Returns: |
||
| 4250 | The response. See :py:meth:`send_command` for details. |
||
| 4251 | """ |
||
| 4252 | if not tag_id: |
||
| 4253 | raise RequiredArgument('modify_tag requires a tag_id element') |
||
| 4254 | |||
| 4255 | cmd = XmlCommand('modify_tag') |
||
| 4256 | cmd.set_attribute('tag_id', str(tag_id)) |
||
| 4257 | |||
| 4258 | if comment: |
||
| 4259 | cmd.add_element('comment', comment) |
||
| 4260 | |||
| 4261 | if name: |
||
| 4262 | cmd.add_element('name', name) |
||
| 4263 | |||
| 4264 | if value: |
||
| 4265 | cmd.add_element('value', value) |
||
| 4266 | |||
| 4267 | if not active is None: |
||
| 4268 | if active: |
||
| 4269 | cmd.add_element('active', '1') |
||
| 4270 | else: |
||
| 4271 | cmd.add_element('active', '0') |
||
| 4272 | |||
| 4273 | if resource_id and resource_type: |
||
| 4274 | _xmlresource = cmd.add_element('resource', |
||
| 4275 | attrs={'resource_id': resource_id}) |
||
| 4276 | _xmlresource.add_element('type', resource_type) |
||
| 4277 | |||
| 4278 | return self._send_xml_command(cmd) |
||
| 4279 | |||
| 4280 | def modify_target(self, target_id, *, name=None, comment=None, |
||
| 4281 | hosts=None, hosts_ordering=None, |
||
| 4282 | exclude_hosts=None, ssh_credential_id=None, |
||
| 4283 | smb_credential_id=None, esxi_credential_id=None, |
||
| 4284 | snmp_credential_id=None, alive_tests=None, |
||
| 4285 | reverse_lookup_only=None, reverse_lookup_unify=None, |
||
| 4286 | port_list_id=None): |
||
| 4287 | """Modifies an existing target. |
||
| 4288 | |||
| 4289 | Arguments: |
||
| 4290 | target_id (uuid) ID of target to modify. |
||
| 4291 | comment (str, optional): Comment on target. |
||
| 4292 | name (str, optional): Name of target. |
||
| 4293 | hosts (list, optional): List of target hosts. |
||
| 4294 | hosts_ordering (str, optional): The order hosts are scanned in. |
||
| 4295 | exclude_hosts (list, optional): A list of hosts to exclude. |
||
| 4296 | ssh_credential (str, optional): UUID of SSH credential to |
||
| 4297 | use on target. |
||
| 4298 | smb_credential (str, optional): UUID of SMB credential to use |
||
| 4299 | on target. |
||
| 4300 | esxi_credential (str, optional): UUID of ESXi credential to use |
||
| 4301 | on target. |
||
| 4302 | snmp_credential (str, optional): UUID of SNMP credential to use |
||
| 4303 | on target. |
||
| 4304 | port_list (str, optional): UUID of port list describing ports to |
||
| 4305 | scan. |
||
| 4306 | alive_tests (str, optional): Which alive tests to use. |
||
| 4307 | reverse_lookup_only (boolean, optional): Whether to scan only hosts |
||
| 4308 | that have names. |
||
| 4309 | reverse_lookup_unify (boolean, optional): Whether to scan only one |
||
| 4310 | IP when multiple IPs have the same name. |
||
| 4311 | |||
| 4312 | Returns: |
||
| 4313 | The response. See :py:meth:`send_command` for details. |
||
| 4314 | """ |
||
| 4315 | if not target_id: |
||
| 4316 | raise RequiredArgument('modify_target requires a ' |
||
| 4317 | 'target_id argument') |
||
| 4318 | |||
| 4319 | cmd = XmlCommand('modify_target') |
||
| 4320 | cmd.set_attribute('target_id', target_id) |
||
| 4321 | |||
| 4322 | if comment: |
||
| 4323 | cmd.add_element('comment', comment) |
||
| 4324 | |||
| 4325 | if name: |
||
| 4326 | cmd.add_element('name', name) |
||
| 4327 | |||
| 4328 | if hosts: |
||
| 4329 | cmd.add_element('hosts', ', '.join(hosts)) |
||
| 4330 | |||
| 4331 | if hosts_ordering: |
||
| 4332 | cmd.add_element('hosts_ordering', ', '.join(hosts_ordering)) |
||
| 4333 | |||
| 4334 | if exclude_hosts: |
||
| 4335 | cmd.add_element('exclude_hosts', ', '.join(exclude_hosts)) |
||
| 4336 | |||
| 4337 | if alive_tests: |
||
| 4338 | if not alive_tests in ALIVE_TESTS: |
||
| 4339 | raise InvalidArgument( |
||
| 4340 | 'alive_tests must be one of {tests} but ' |
||
| 4341 | '{actual} has been passed'.format( |
||
| 4342 | tests='|'.join(ALIVE_TESTS), actual=alive_tests)) |
||
| 4343 | cmd.add_element('alive_tests', alive_tests) |
||
| 4344 | |||
| 4345 | if ssh_credential_id: |
||
| 4346 | cmd.add_element('ssh_credential', attrs={'id': ssh_credential_id}) |
||
| 4347 | |||
| 4348 | if smb_credential_id: |
||
| 4349 | cmd.add_element('smb_credential', attrs={'id': smb_credential_id}) |
||
| 4350 | |||
| 4351 | if esxi_credential_id: |
||
| 4352 | cmd.add_element('esxi_credential', attrs={'id': esxi_credential_id}) |
||
| 4353 | |||
| 4354 | if snmp_credential_id: |
||
| 4355 | cmd.add_element('snmp_credential', attrs={'id': snmp_credential_id}) |
||
| 4356 | |||
| 4357 | if not reverse_lookup_only is None: |
||
| 4358 | if reverse_lookup_only: |
||
| 4359 | cmd.add_element('reverse_lookup_only', '1') |
||
| 4360 | else: |
||
| 4361 | cmd.add_element('reverse_lookup_only', '0') |
||
| 4362 | |||
| 4363 | if not reverse_lookup_unify is None: |
||
| 4364 | if reverse_lookup_unify: |
||
| 4365 | cmd.add_element('reverse_lookup_unify', '1') |
||
| 4366 | else: |
||
| 4367 | cmd.add_element('reverse_lookup_unify', '0') |
||
| 4368 | |||
| 4369 | if port_list_id: |
||
| 4370 | cmd.add_element('port_list', attrs={'id': port_list_id}) |
||
| 4371 | |||
| 4372 | return self._send_xml_command(cmd) |
||
| 4373 | |||
| 4374 | def modify_task(self, task_id, *, name=None, comment=None, alert=None, |
||
| 4375 | observers=None, preferences=None, schedule=None, |
||
| 4376 | schedule_periods=None, scanner=None, file_name=None, |
||
| 4377 | file_action=None): |
||
| 4378 | """Modifies an existing task. |
||
| 4379 | |||
| 4380 | Arguments: |
||
| 4381 | task_id (str) UUID of task to modify. |
||
| 4382 | comment (str, optional):The comment on the task. |
||
| 4383 | alert (str, optional): UUID of Task alert. |
||
| 4384 | name (str, optional): The name of the task. |
||
| 4385 | observers (list, optional): Users allowed to observe this task. |
||
| 4386 | preferences (dict, optional): Compact name of preference, from |
||
| 4387 | scanner and its value |
||
| 4388 | schedule (str, optional): UUID of Task schedule. |
||
| 4389 | schedule_periods (int, optional): A limit to the number of times |
||
| 4390 | the task will be scheduled, or 0 for no limit. |
||
| 4391 | scanner (str, optional): UUID of Task scanner. |
||
| 4392 | file_name (str, optional): File to attach to task. |
||
| 4393 | file_action (str, optional): Action for the file: |
||
| 4394 | one of "update" or "remove" |
||
| 4395 | |||
| 4396 | Returns: |
||
| 4397 | The response. See :py:meth:`send_command` for details. |
||
| 4398 | """ |
||
| 4399 | if not task_id: |
||
| 4400 | raise RequiredArgument('modify_task requires a task_id argument') |
||
| 4401 | |||
| 4402 | cmd = XmlCommand('modify_task') |
||
| 4403 | cmd.set_attribute('task_id', task_id) |
||
| 4404 | |||
| 4405 | if name: |
||
| 4406 | cmd.add_element('name', name) |
||
| 4407 | |||
| 4408 | if comment: |
||
| 4409 | cmd.add_element('comment', comment) |
||
| 4410 | |||
| 4411 | if scanner: |
||
| 4412 | cmd.add_element('scanner', attrs={'id': scanner}) |
||
| 4413 | |||
| 4414 | if schedule_periods: |
||
| 4415 | cmd.add_element('schedule_periods', str(schedule_periods)) |
||
| 4416 | |||
| 4417 | if schedule: |
||
| 4418 | cmd.add_element('schedule', attrs={'id': schedule}) |
||
| 4419 | |||
| 4420 | if alert: |
||
| 4421 | cmd.add_element('alert', attrs={'id': alert}) |
||
| 4422 | |||
| 4423 | if observers: |
||
| 4424 | cmd.add_element('observers', ', '.join(observers)) |
||
| 4425 | |||
| 4426 | if preferences: |
||
| 4427 | _xmlprefs = cmd.add_element('preferences') |
||
| 4428 | for pref_name, pref_value in preferences.items(): |
||
| 4429 | _xmlpref = _xmlprefs.add_element('preference') |
||
| 4430 | _xmlpref.add_element('scanner_name', pref_name) |
||
| 4431 | _xmlpref.add_element('value', pref_value) |
||
| 4432 | |||
| 4433 | if file_name and file_action: |
||
| 4434 | if file_action not in ('update', 'remove'): |
||
| 4435 | raise InvalidArgument('action can only be ' |
||
| 4436 | '"update" or "remove"!') |
||
| 4437 | cmd.add_element('file', attrs={'name': file_name, |
||
| 4438 | 'action': file_action}) |
||
| 4439 | |||
| 4440 | return self._send_xml_command(cmd) |
||
| 4441 | |||
| 4442 | def modify_user(self, user_id, name, *, new_name=None, password=None, |
||
| 4443 | role_ids=None, hosts=None, hosts_allow=None, |
||
| 4444 | ifaces=None, ifaces_allow=None, sources=None): |
||
| 4445 | """Modifies an existing user. |
||
| 4446 | |||
| 4447 | Arguments: |
||
| 4448 | user_id (str): UUID of the user to be modified. Overrides |
||
| 4449 | NAME element. |
||
| 4450 | name (str): The name of the user to be modified. |
||
| 4451 | new_name (str, optional): The new name for the user. |
||
| 4452 | password (str, optional): The password for the user. |
||
| 4453 | roles_id (list, optional): List of roles UUIDs for the user. |
||
| 4454 | hosts (list, optional): User access rules: List of hosts. |
||
| 4455 | hosts_allow (boolean,optional): If True, allow only listed, |
||
| 4456 | otherwise forbid listed. |
||
| 4457 | ifaces (list, optional): User access rules: List |
||
| 4458 | of ifaces. |
||
| 4459 | ifaces_allow (boolean, optional): If True, allow only listed, |
||
| 4460 | otherwise forbid listed. |
||
| 4461 | sources (list, optional): List of authentication sources for |
||
| 4462 | this user. |
||
| 4463 | |||
| 4464 | Returns: |
||
| 4465 | The response. See :py:meth:`send_command` for details. |
||
| 4466 | """ |
||
| 4467 | if not user_id: |
||
| 4468 | raise RequiredArgument('modify_user requires a user_id argument') |
||
| 4469 | |||
| 4470 | if not name: |
||
| 4471 | raise RequiredArgument('modify_user requires a name argument') |
||
| 4472 | |||
| 4473 | cmd = XmlCommand('modify_user') |
||
| 4474 | cmd.set_attribute('user_id', user_id) |
||
| 4475 | |||
| 4476 | if new_name: |
||
| 4477 | cmd.add_element('new_name', new_name) |
||
| 4478 | |||
| 4479 | if password: |
||
| 4480 | cmd.add_element('password', password) |
||
| 4481 | |||
| 4482 | if role_ids: |
||
| 4483 | for role in role_ids: |
||
| 4484 | cmd.add_element('role', attrs={'id': role}) |
||
| 4485 | |||
| 4486 | if hosts or hosts_allow: |
||
| 4487 | cmd.add_element('hosts', ', '.join(hosts), |
||
| 4488 | attrs={'allow': '1' if hosts_allow else '0'}) |
||
| 4489 | |||
| 4490 | if ifaces or ifaces_allow: |
||
| 4491 | cmd.add_element('ifaces', ', '.join(ifaces), |
||
| 4492 | attrs={'allow': '1' if ifaces_allow else '0'}) |
||
| 4493 | |||
| 4494 | if sources: |
||
| 4495 | cmd.add_element('sources', ', '.join(sources)) |
||
| 4496 | |||
| 4497 | return self._send_xml_command(cmd) |
||
| 4498 | |||
| 4499 | def move_task(self, task_id, *, slave_id=None): |
||
| 4500 | """Move an existing task to another GMP slave scanner or the master |
||
| 4501 | |||
| 4502 | Arguments: |
||
| 4503 | task_id (str): UUID of the task to be moved |
||
| 4504 | slave_id (str, optional): UUID of slave to reassign the task to, |
||
| 4505 | empty for master. |
||
| 4506 | |||
| 4507 | Returns: |
||
| 4508 | The response. See :py:meth:`send_command` for details. |
||
| 4509 | """ |
||
| 4510 | if not task_id: |
||
| 4511 | raise InvalidArgument('move_task requires an task_id argument') |
||
| 4512 | |||
| 4513 | cmd = XmlCommand('move_task') |
||
| 4514 | cmd.set_attribute('task_id', task_id) |
||
| 4515 | |||
| 4516 | if not slave_id is None: |
||
| 4517 | cmd.set_attribute('slave_id', slave_id) |
||
| 4518 | |||
| 4519 | return self._send_xml_command(cmd) |
||
| 4520 | |||
| 4521 | def restore(self, entity_id): |
||
| 4522 | """Restore an entity from the trashcan |
||
| 4523 | |||
| 4524 | Arguments: |
||
| 4525 | entity_id (str): ID of the entity to be restored from the trashcan |
||
| 4526 | |||
| 4527 | Returns: |
||
| 4528 | The response. See :py:meth:`send_command` for details. |
||
| 4529 | """ |
||
| 4530 | if not entity_id: |
||
| 4531 | raise InvalidArgument('restore requires an entity_id argument') |
||
| 4532 | |||
| 4533 | cmd = XmlCommand('restore') |
||
| 4534 | cmd.set_attribute('id', entity_id) |
||
| 4535 | |||
| 4536 | return self._send_xml_command(cmd) |
||
| 4537 | |||
| 4538 | def resume_task(self, task_id): |
||
| 4539 | """Resume an existing stopped task |
||
| 4540 | |||
| 4541 | Arguments: |
||
| 4542 | task_id (str): UUID of the task to be resumed |
||
| 4543 | |||
| 4544 | Returns: |
||
| 4545 | The response. See :py:meth:`send_command` for details. |
||
| 4546 | """ |
||
| 4547 | if not task_id: |
||
| 4548 | raise InvalidArgument('resume_task requires an task_id argument') |
||
| 4549 | |||
| 4550 | cmd = XmlCommand('resume_task') |
||
| 4551 | cmd.set_attribute('task_id', task_id) |
||
| 4552 | |||
| 4553 | return self._send_xml_command(cmd) |
||
| 4554 | |||
| 4555 | def start_task(self, task_id): |
||
| 4556 | """Start an existing task |
||
| 4557 | |||
| 4558 | Arguments: |
||
| 4559 | task_id (str): UUID of the task to be started |
||
| 4560 | |||
| 4561 | Returns: |
||
| 4562 | The response. See :py:meth:`send_command` for details. |
||
| 4563 | """ |
||
| 4564 | if not task_id: |
||
| 4565 | raise InvalidArgument('start_task requires an task_id argument') |
||
| 4566 | |||
| 4567 | cmd = XmlCommand('start_task') |
||
| 4568 | cmd.set_attribute('task_id', task_id) |
||
| 4569 | |||
| 4570 | return self._send_xml_command(cmd) |
||
| 4571 | |||
| 4572 | def stop_task(self, task_id): |
||
| 4573 | """Stop an existing running task |
||
| 4574 | |||
| 4575 | Arguments: |
||
| 4576 | task_id (str): UUID of the task to be stopped |
||
| 4577 | |||
| 4578 | Returns: |
||
| 4579 | The response. See :py:meth:`send_command` for details. |
||
| 4580 | """ |
||
| 4581 | if not task_id: |
||
| 4582 | raise InvalidArgument('stop_task requires an task_id argument') |
||
| 4583 | |||
| 4584 | cmd = XmlCommand('stop_task') |
||
| 4585 | cmd.set_attribute('task_id', task_id) |
||
| 4586 | |||
| 4587 | return self._send_xml_command(cmd) |
||
| 4588 | |||
| 4589 | def sync_cert(self): |
||
| 4590 | """Request a synchronization with the CERT feed service |
||
| 4591 | |||
| 4592 | Returns: |
||
| 4593 | The response. See :py:meth:`send_command` for details. |
||
| 4594 | """ |
||
| 4595 | return self._send_xml_command(XmlCommand('sync_cert')) |
||
| 4596 | |||
| 4597 | def sync_config(self): |
||
| 4598 | """Request an OSP config synchronization with scanner |
||
| 4599 | |||
| 4600 | Returns: |
||
| 4601 | The response. See :py:meth:`send_command` for details. |
||
| 4602 | """ |
||
| 4603 | return self._send_xml_command(XmlCommand('sync_config')) |
||
| 4604 | |||
| 4605 | def sync_feed(self): |
||
| 4606 | """Request a synchronization with the NVT feed service |
||
| 4607 | |||
| 4608 | Returns: |
||
| 4609 | The response. See :py:meth:`send_command` for details. |
||
| 4610 | """ |
||
| 4611 | return self._send_xml_command(XmlCommand('sync_feed')) |
||
| 4612 | |||
| 4613 | def sync_scap(self): |
||
| 4614 | """Request a synchronization with the SCAP feed service |
||
| 4615 | |||
| 4616 | Returns: |
||
| 4617 | The response. See :py:meth:`send_command` for details. |
||
| 4618 | """ |
||
| 4619 | return self._send_xml_command(XmlCommand('sync_scap')) |
||
| 4620 | |||
| 4621 | def test_alert(self, alert_id): |
||
| 4622 | """Run an alert |
||
| 4623 | |||
| 4624 | Invoke a test run of an alert |
||
| 4625 | |||
| 4626 | Arguments: |
||
| 4627 | alert_id (str): UUID of the alert to be tested |
||
| 4628 | |||
| 4629 | Returns: |
||
| 4630 | The response. See :py:meth:`send_command` for details. |
||
| 4631 | """ |
||
| 4632 | if not alert_id: |
||
| 4633 | raise InvalidArgument('test_alert requires an alert_id argument') |
||
| 4634 | |||
| 4635 | cmd = XmlCommand('test_alert') |
||
| 4636 | cmd.set_attribute('alert_id', alert_id) |
||
| 4637 | |||
| 4638 | return self._send_xml_command(cmd) |
||
| 4639 | |||
| 4640 | def trigger_alert(self, alert_id, report_id, *, filter=None, filter_id=None, |
||
| 4641 | report_format_id=None, delta_report_id=None): |
||
| 4642 | """Run an alert by ignoring its event and conditions |
||
| 4643 | |||
| 4644 | The alert is triggered to run immediately with the provided filtered |
||
| 4645 | report by ignoring the even and condition settings. |
||
| 4646 | |||
| 4647 | Arguments: |
||
| 4648 | alert_id (str): UUID of the alert to be run |
||
| 4649 | report_id (str): UUID of the report to be provided to the alert |
||
| 4650 | filter (str, optional): Filter term to use to filter results in the |
||
| 4651 | report |
||
| 4652 | filter_id (str, optional): UUID of filter to use to filter results |
||
| 4653 | in the report |
||
| 4654 | report_format_id (str, optional): UUID of report format to use |
||
| 4655 | delta_report_id (str, optional): UUID of an existing report to |
||
| 4656 | compare report to. |
||
| 4657 | |||
| 4658 | Returns: |
||
| 4659 | The response. See :py:meth:`send_command` for details. |
||
| 4660 | """ |
||
| 4661 | if not alert_id: |
||
| 4662 | raise RequiredArgument('run_alert requires a alert_id argument') |
||
| 4663 | |||
| 4664 | if not report_id: |
||
| 4665 | raise RequiredArgument('run_alert requires a report_id argument') |
||
| 4666 | |||
| 4667 | cmd = XmlCommand('get_reports') |
||
| 4668 | cmd.set_attribute('report_id', report_id) |
||
| 4669 | cmd.set_attribute('alert_id', alert_id) |
||
| 4670 | |||
| 4671 | if filter: |
||
| 4672 | cmd.set_attribute('filter', filter) |
||
| 4673 | |||
| 4674 | if filter_id: |
||
| 4675 | cmd.set_attribute('filt_id', filter_id) |
||
| 4676 | |||
| 4677 | if report_format_id: |
||
| 4678 | cmd.set_attribute('format_id', report_format_id) |
||
| 4679 | |||
| 4680 | if delta_report_id: |
||
| 4681 | cmd.set_attribute('delta_report_id', delta_report_id) |
||
| 4682 | |||
| 4683 | return self._send_xml_command(cmd) |
||
| 4684 | |||
| 4685 | def verify_agent(self, agent_id): |
||
| 4686 | """Verify an existing agent |
||
| 4687 | |||
| 4688 | Verifies the trust level of an existing agent. It will be checked |
||
| 4689 | whether signature of the agent currently matches the agent. This |
||
| 4690 | includes the agent installer file. It is *not* verified if the agent |
||
| 4691 | works as expected by the user. |
||
| 4692 | |||
| 4693 | Arguments: |
||
| 4694 | agent_id (str): UUID of the agent to be verified |
||
| 4695 | |||
| 4696 | Returns: |
||
| 4697 | The response. See :py:meth:`send_command` for details. |
||
| 4698 | """ |
||
| 4699 | if not agent_id: |
||
| 4700 | raise InvalidArgument('verify_agent requires an agent_id argument') |
||
| 4701 | |||
| 4702 | cmd = XmlCommand('verify_agent') |
||
| 4703 | cmd.set_attribute('agent_id', agent_id) |
||
| 4704 | |||
| 4705 | return self._send_xml_command(cmd) |
||
| 4706 | |||
| 4707 | def verify_report_format(self, report_format_id): |
||
| 4708 | """Verify an existing report format |
||
| 4709 | |||
| 4710 | Verifies the trust level of an existing report format. It will be |
||
| 4711 | checked whether the signature of the report format currently matches the |
||
| 4712 | report format. This includes the script and files used to generate |
||
| 4713 | reports of this format. It is *not* verified if the report format works |
||
| 4714 | as expected by the user. |
||
| 4715 | |||
| 4716 | Arguments: |
||
| 4717 | report_format_id (str): UUID of the report format to be verified |
||
| 4718 | |||
| 4719 | Returns: |
||
| 4720 | The response. See :py:meth:`send_command` for details. |
||
| 4721 | """ |
||
| 4722 | if not report_format_id: |
||
| 4723 | raise InvalidArgument( |
||
| 4724 | 'verify_report_format requires a report_format_id argument') |
||
| 4725 | |||
| 4726 | cmd = XmlCommand('verify_report_format') |
||
| 4727 | cmd.set_attribute('report_format_id', report_format_id) |
||
| 4728 | |||
| 4729 | return self._send_xml_command(cmd) |
||
| 4730 | |||
| 4731 | def verify_scanner(self, scanner_id): |
||
| 4732 | """Verify an existing scanner |
||
| 4733 | |||
| 4734 | Verifies if it is possible to connect to an existing scanner. It is |
||
| 4735 | *not* verified if the scanner works as expected by the user. |
||
| 4736 | |||
| 4737 | Arguments: |
||
| 4738 | scanner_id (str): UUID of the scanner to be verified |
||
| 4739 | |||
| 4740 | Returns: |
||
| 4741 | The response. See :py:meth:`send_command` for details. |
||
| 4742 | """ |
||
| 4743 | if not scanner_id: |
||
| 4744 | raise InvalidArgument( |
||
| 4745 | 'verify_scanner requires a scanner_id argument') |
||
| 4746 | |||
| 4747 | cmd = XmlCommand('verify_scanner') |
||
| 4748 | cmd.set_attribute('scanner_id', scanner_id) |
||
| 4749 | |||
| 4750 | return self._send_xml_command(cmd) |
||
| 4751 |