Skip to main content

Python Api client for the Cyberwatch software

Project description

Cyberwatch API

Python Api client for the Cyberwatch software

Table of Contents

Installation

Prerequisites

Module installation

To install the Cyberwatch API module, use Python 3 with:

pip3 install cyberwatch_api

[!WARNING] Since pip 23.1, using pip in the system is disabled by defaut to prevent breaking system packages by overwriting dependencies. To avoid this, you can use a virtual environment (python3 -m venv env), or add the --break-system-packages to force the installation. More information regarding this in the documentation.

Configuration

To be able to authenticate to the Cyberwatch API, you need to configure the api.conf file. This client authenticates using basic auth.

All the information can be retrieved in your profile on the Cyberwatch interface while creating an API user as following:

"Profile > API keys > See my API keys > +Add"

You can download directly the api.conf file after clicking on "Create > Export" or copy/paste the information to an api.conf file in this directory.

api.conf file location

The library will search for the api.conf file in the current working directory and, if there is none, in its parent directory.

If the api.conf file is located elsewhere, you can specify the path as shown below:

Cyberwatch_Pyhelper(path_to_conf="your/path/to/api.conf/file/")

Ping

Create a ping.py script with the following content inside:

from cyberwatch_api import Cyberwatch_Pyhelper

output = Cyberwatch_Pyhelper().request(
    method="get",
    endpoint="/api/v3/ping"
    )

print(next(output).json())

Then to test it, type the following command:

$ python3 ping.py

The output should look like this:

{"uuid": "1ab2c3de-546f-789g-9f87-6ed5c4b3a210"}

Otherwise, check that there are no typing errors in your API_KEY, SECRET_KEY or API_URL in the api.conf file and that your Cyberwatch instance is up.

Examples

Run an example script

  1. Choose a script from the examples directory and copy it to your computer

  2. Run it with the following command:

$ python3 your_example_script_file.py

Usage

Swagger documentation

Cyberwatch API provides a Swagger documentation.

Using it, you can :

  • Select the action you want to perform in the documentation
  • Update the "method", "endpoint" and parameters ("body_params") in you script according to the documentation
  • Add any required logic

Note that the request method provided by this module always outputs a generator. This is intended to allow building of high performance scripts. If the request you perform returns a single result and not a list, you will find the result in the first row of this generator.

Location of the Swagger's documentation

You can find it while clicking on the </> logo on the top right of the Cyberwatch interface.

Request parameters

When using this API, you can use the body_params variable to send parameters to your endpoint.

output = Cyberwatch_Pyhelper().request(
    method="get",
    endpoint="/api/v3/vulnerabilities/servers/{id}",
    body_params={'id' : 7}
)
output = Cyberwatch_Pyhelper().request(
    method="put",
    endpoint="/api/v3/vulnerabilities/servers/{id}",
    body_params={'id' : 7,'description' : "this is a description", "groups":[3,4]}
)

Paginate the response

You can select how many elements are returned per-page using the per_page parameter. If you need only a single page to be returned, you may specify it using the page parameter.

output = Cyberwatch_Pyhelper().request(
    method="get",
    endpoint="/api/v3/agents",
    body_params={'per_page' : 50, 'page' : 3}
)

Command Line Documentation

See the command line interface documentation here

FAQs

What if I don't want to verify the SSL certificate?

Error example:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:997)

Certificate verification can be bypassed with the verify_ssl option.

For example, this option was added to the previous ping.py script as follows:

from cyberwatch_api import Cyberwatch_Pyhelper

output = Cyberwatch_Pyhelper().request(
    method="get",
    endpoint="/api/v3/ping",
    verify_ssl=False
    )

print(next(output).json())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cyberwatch_api-1.0.0.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cyberwatch_api-1.0.0-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file cyberwatch_api-1.0.0.tar.gz.

File metadata

  • Download URL: cyberwatch_api-1.0.0.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cyberwatch_api-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c4986384364ea0330abdbc56228cdc6e96e7b8278daac017214bcd098bc8d948
MD5 bbf3983ad9e64a732f5f08d1cd5c55fa
BLAKE2b-256 11d56597da5964b61a9fc9b46c04ac8f32219639173cf480f519e23c7faed78b

See more details on using hashes here.

File details

Details for the file cyberwatch_api-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cyberwatch_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cyberwatch_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30df8d9329a41f39d145d3c13e9be936a7b8a6153868a069577211ed102438f9
MD5 9bd9d0ad6ae161373d8bb927bd9566a8
BLAKE2b-256 087d65ef023afbd98e2e95c0c092ad0a616be5efccc16d0d1e43f7e54a862c2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page