qualyspy package

Subpackages

Submodules

qualyspy.base module

Base classes for intereacting with the Qualys API and the database where information is being stored. Primarily used internally by the QualysPy library, but can be used to call APIs which the library does not yet support.

Typical usage example: api = QualysAPIBase() api.get(“/msp/about.php”)

class qualyspy.base.QualysAPIBase(config_file: str = '/home/docs/.qualyspy', x_requested_with: str = 'QualysPy Python Library')

Bases: object

Base class for interacting with the Qualys API. This class is not intended to be used directly, but rather to be subclassed by other classes which implement specific Qualys API calls.

config_file

Path to the config file. See config-example.ini for an example.

Type:

str

api_root

Root URL of the Qualys API.

Type:

str

username

Username to use when authenticating to the Qualys API.

Type:

str

password

Password to use when authenticating to the Qualys API.

Type:

str

x_requested_with

Value to send in the X-Requested-With header.

Type:

str

ratelimit_limit

Maximum number of requests allowed in the current window. Updated after every API call.

Type:

int

ratelimit_window_sec

Length of the current window in seconds. Updated after every API call.

Type:

int

ratelimit_remaining

Number of requests remaining in the current window. Updated after every API call.

Type:

int

ratelimit_towait_sec

Number of seconds to wait before making another API call. Updated after every API call.

Type:

int

concurrency_limit_limit

Maximum number of concurrent requests allowed. Updated after every API call.

Type:

int

get(url: str, params: dict[str, str] | None = None) Response

Send a GET request to the Qualys API.

Parameters:
  • url (str) – URL to send the request to.

  • params (dict[str, str], optional) – Parameters to send with the request. Defaults to None, which means the API call will use the default parameters.

Returns:

The text of the response.

Raises:

exceptions.QualysAPIError – Raised if the Qualys API returns a non-200 response.

post(url: str, *, params: dict[str, str] | None = None, data: str | None = None, content_type: str = 'application/json', accept: str = 'application/json') Response

Send a POST request to the Qualys API.

Parameters:
  • url (str) – URL to send the request to.

  • data (dict[str, str], optional) – Data to send with the request. Defaults to None, which means the API call will use the default parameters.

Returns:

The text of the response.

Raises:

exceptions.QualysAPIError – Raised if the Qualys API returns a non-200 response.

class qualyspy.base.QualysORMMixin(api: QualysAPIBase, *, echo: bool = False)

Bases: ABC

Mixin class for Qualys API classes that use SQLAlchemy ORM.

api

Instance of the QualysAPIBase class.

Type:

QualysAPIBase

orm_base

Base class for all ORM classes.

Type:

sqlalchemy.ext.declarative.api.DeclarativeMeta

db_host

Hostname of the PostgreSQL database.

Type:

str

db_name

Name of the PostgreSQL database.

Type:

str

db_username

Username to use to connect to the PostgreSQL database.

Type:

str

db_password

Password to use to connect to the PostgreSQL database.

Type:

str

e_url

SQLAlchemy engine URL.

Type:

str

engine

SQLAlchemy engine.

Type:

sqlalchemy.engine.base.Engine

echo

Whether or not to echo SQL statements to stdout. Defaults to False. If changed after the engine is created, the engine will automatically update with the new value.

Type:

bool

init_db() None

Initialize the database. Creates the schema and tables if they don’t already exist.

abstract load() None

Load data into the database.

query(stmt: Any, *, echo: bool = False) list[_C]

Execute a query against the database.

Parameters:
  • stmt (Any) – SQLAlchemy statement to execute.

  • echo (bool, optional) – Whether or not to echo SQL statements to stdout. Defaults to False.

Returns:

List of objects returned by the query.

Return type:

list[_C]

safe_load(loader: Callable[[...], Any], load_func: Any, **kwargs: dict[str, Any]) None

Safely load data into the database. If an exception is raised, the database is reverted to its previous state.

Parameters:
  • loader (Callable[..., Any]) – Function which loads data into the database.

  • load_func (Any) – Function which returns the data to load into the database.

  • **kwargs (dict[str, Any]) – Keyword arguments to pass to the loader function.

qualyspy.exceptions module

Exceptions for QualysPy.

exception qualyspy.exceptions.ConfigError

Bases: Exception

Indicates an error with the configuration file.

exception qualyspy.exceptions.QualysAPIError

Bases: Exception

Indicates an error with the Qualys API.

exception qualyspy.exceptions.ValidationError

Bases: Exception

Wrapper for pydantic.error_wrappers.ValidationError

qualyspy.vmdr module

Qualys VMDR API Module

Typical usage example: vmdr_orm = vmdr.HostListDetectionORM() vmdr_orm.load() session = orm.Session(vmdr_orm.engine): host_list = session.query(HostORM).all() stmt = session.query(HostORM) hosts = vmdr_orm.query(stmt)[0] host = hosts.host[0] session.close()

class qualyspy.vmdr.HostListDetectionORM(echo: bool = False)

Bases: VmdrAPI, QualysORMMixin

Qualys VMDR Host List Detection ORM Class. Contains methods for loading host detections into an ORM database.

load(**kwargs: Any) None

Load host detections into the ORM database.

Parameters:

**kwargs (Any) – Keyword arguments to pass to VmdrAPI.host_list_detection().

class qualyspy.vmdr.HostListORM(echo: bool = False)

Bases: VmdrAPI, QualysORMMixin

Qualys VMDR Host List ORM Class. Contains methods for loading hosts into an ORM database.

load(**kwargs: Any) None

Load hosts into the ORM database.

Parameters:

**kwargs (Any) – Keyword arguments to pass to VmdrAPI.host_list().

class qualyspy.vmdr.VmdrAPI(config_file: str = '/home/docs/.qualyspy', x_requested_with: str = 'QualysPy Python Library')

Bases: QualysAPIBase

Qualys VMDR API Class. Contains methods for interacting with the VMDR API.

host_list(*, truncation_limit: int | None = None, ips: list[str | IPv4Address | IPv6Address] | None = None, ids: int | list[int] | None = None, id_min: int | None = None) tuple[HostList, bool, int]
Get a list of hosts from the VMDR API. A value of None for the parameters will use their

default values in the API.

Parameters:

ids (int | list[int] | None, optional) – Host IDs to query. Defaults to None.

Returns:

A tuple containing the

host_list_vm_detection_output.HostList object, a boolean indicating whether the results were truncated, and the next id_min to use for the next call.

Return type:

tuple[host_list_vm_detection_output.HostList, bool, int]

host_list_detection(*, ids: int | list[int] | None = None, truncation_limit: int | None = None, id_min: int | None = None, qids: int | list[int] | None = None, show_qds: bool | None = None, qds_min: int | None = None, qds_max: int | None = None, arf_kernel_filter: int | None = None) tuple[HostList, bool, int]

Get a list of hosts with associated vulnerability detections from the VMDR API. A value of None for the parameters will use their default values in the API.

Parameters:
  • ids (int | list[int] | None, optional) – Host IDs to query. Defaults to None.

  • truncation_limit (int | None, optional) – Maximum number of hosts to return. Defaults to None.

  • id_min (int | None, optional) – Minimum host list ID to return. Defaults to None.

Returns:

A tuple containing the

host_list_vm_detection_output.HostList object, a boolean indicating whether the results were truncated, and the next id_min to use for the next call.

Return type:

tuple[host_list_vm_detection_output.HostList, bool, int]

ignore_vuln(qids: list[int], comments: str, *, action: str | None = None, reopen_ignored_days: int | None = None, reopen_ignored_date: datetime | None = None, asset_groups: list[str] | None = None, ips: list[str | IPv4Address | IPv6Address] | None = None, dns_contains: str | None = None) None

Ignore a list of vulnerabilities for a set of assets.

knowledgebase(*, details: str | None = None, ids: int | list[int] | None = None) VulnList

Get a list of vulnerabilities from the VMDR API. A value of None for the parameters will use their default values in the API.

Parameters:
  • details (str | None, optional) – Details to return. Defaults to None.

  • ids (int | list[int] | None, optional) – Vulnerability IDs to query. Defaults to None.

Returns:

A VulnList object containing the list of

vulnerabilities.

Return type:

knowledge_base_vuln_list_output.VulnList

Module contents