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