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