fotoobo Module Documentation

Exceptions

This is the fotoobo exception module.

exception fotoobo.exceptions.exceptions.APIError(err: Any)

Exception for errors with the network API.

__init__(err: Any) None

init

exception fotoobo.exceptions.exceptions.GeneralError(message: str)

The exception to raise if a general error occurred.

The class does not have any methods as the only one (__init__) is inherited from its parent. Raise a GeneralError when it does not make sense to do further processing and the program should stop and exit.

exception fotoobo.exceptions.exceptions.GeneralException(message: str)

This is the generic fotoobo exception which can be used by any sub exception.

__init__(message: str) None

init

exception fotoobo.exceptions.exceptions.GeneralWarning(message: str)

The exception to raise if a general warning occurred.

The class does not have any methods as the only one (__init__) is inherited from its parent. Raise a GeneralWarning if a part of the program fails but it is safe to do further processing.

Fortinet Classes

Class view

class fotoobo.fortinet.fortinet.Fortinet(hostname: str, **kwargs: Any)

This is the Fortinet abstract base class. All other Fortinet product classes should inherit from this class. If there are methods which have to be defined in every subclass it has to be defined here with the abstractmethod decorator.

__init__(hostname: str, **kwargs: Any) None

Set some initial parameters for the Fortinet super class.

It also initializes a requests session. If you’re making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase. (https://docs.python-requests.org/en/master/user/advanced/)

Parameters:

hostname – The hostname of the Fortinet device to connect to

Keyword Arguments:
  • https_port – The tcp port number to connect to the https api If you do not specify a port number it is set to 443 by default.

  • proxy – The Proxy server to use to connect to the Fortinet device If you need to connect to your Fortinet device through a proxy server you can set it here as as string. If needed you may append the proxy server port with a column to the proxy server. e.g. “proxy.local:8000”.

  • ssl_verify – Enable or disable SSL certificate check When ssl_verify is enabled you have to install a trusted SSL certificate onto the device you wish to connect to. If you set ssl_verify to false it will also disable the warnings in urllib3. This prevents unwanted SSL warnings to be logged.

  • timeout – Connection timeout in seconds

api(method: str, url: str = '', headers: dict[str, str] | None = None, params: dict[str, str] | None = None, payload: dict[str, Any] | None = None, timeout: float | None = None) Response

API request to a Fortinet device.

Parameters:
  • method – HTTP request method

  • url – Rest API URL to request data from

  • headers – Dictionary with headers (if needed)

  • params – Dictionary with parameters (if needed)

  • payload – JSON body for post requests (if needed)

  • timeout – The requests read timeout

Returns:

Response from the request

static get_vendor() str

Returns the vendor of the product (which always is Fortinet).

Returns:

Always returns “Fortinet” (what a cool method ;-)

abstractmethod get_version() str

Gets the version of the corresponding system(s)

class fotoobo.fortinet.fortianalyzer.FortiAnalyzer(hostname: str, username: str, password: str, **kwargs: Any)

Represents one FortiAnalyzer (digital twin)

This class is inherited from FortiManager. Only the type of the object differs.

__init__(hostname: str, username: str, password: str, **kwargs: Any) None

Set some initial parameters.

Parameters:
  • hostname – The hostname of the FortiGate to connect to

  • username – Username

  • password – Password

  • **kwargs – See Fortinet class for available arguments

get_version() str

Get FortiAnalyzer version

Returns:

FortiAnalyzer version

class fotoobo.fortinet.forticlientems.FortiClientEMS(hostname: str, username: str, password: str, cookie_path: str = '', **kwargs: Any)

Represents one FortiClient EMS (digital twin)

__init__(hostname: str, username: str, password: str, cookie_path: str = '', **kwargs: Any) None

Set some initial parameters.

Parameters:
  • hostname – The hostname of the FortiClient EMS to connect to

  • username – Username

  • password – Password

  • cookie_path – Path to write the cookie files (no cookie if empty)

  • **kwargs – See Fortinet class for available arguments

api(method: str, url: str = '', headers: dict[str, str] | None = None, params: dict[str, str] | None = None, payload: dict[str, Any] | None = None, timeout: float | None = None) Response

API request to a FortiClientEMS device.

Parameters:
  • method – Request method from [get, post]

  • url – Rest API URL to request data from

  • headers – Additional headers (if needed)

  • params – Dictionary with parameters (if needed)

  • payload – JSON body for post requests (if needed)

  • timeout – The requests read timeout

Returns:

Response from the request

get_version() str

Get the FortiClient EMS version. According to Fortinet support the FortiClient EMS version may be read out of the endpoint /system/consts/get?system_update_time=1. This endpoint is not (yet) documented. Let’s hope they support it in case of any issue.

Returns:

FortiClient EMS version

login() int

Login to the FortiClientEMS.

Returns:

Status code from the FortiClient EMS logon

logout() int

Logout from FortiClient EMS.

Returns:

Status code from the FortiClient EMS logout

class fotoobo.fortinet.forticloudasset.FortiCloudAsset(username: str, password: str, **kwargs: Any)

Represents the FortiCloud Asset Management (digital twin)

Helpful documentation links: - https://fndn.fortinet.net/index.php?/fortiapi/55-asset-management-formerly-forticare-registration/4638/55/Folder/ # pylint: disable=line-too-long - https://docs.fortinet.com/document/forticloud/25.2.0/identity-access-management-iam/19322/accessing-fortiapis # pylint: disable=line-too-long

__init__(username: str, password: str, **kwargs: Any) None

Set some initial parameters.

Parameters:
  • username – The username

  • password – The password

Keyword Arguments:
  • token_path – The path where to load/save the access token

  • **kwargs – See Fortinet class for more available arguments

api(method: str, url: str = '', headers: dict[str, str] | None = None, params: dict[str, str] | None = None, payload: dict[str, Any] | None = None, timeout: float | None = None) Response

API request to a FortiManager device.

It uses the super.api method but it has to enrich the payload in post requests with the needed session key.

Parameters:
  • method – Request method from [get, post]

  • url – Rest API URL to request data from

  • headers – Dictionary with headers (if needed)

  • params – Dictionary with parameters (if needed)

  • payload – JSON body for post requests (if needed)

  • timeout – The requests read timeout in seconds

Returns:

Response – Response object from the request

get_version() str

Get FortiCloud API version.

Returns:

FortiCloud API version

login() int

Login to the FortiCloud.

If the login to the FortiCloud was successful it stores the access token in the object. We do not use requests.session as the access token is just a string which is saved directly.

Returns:

Status code from the FortiCloud login

post(url: str, payload: dict[str, Any] | None = None) Any

POST method to FortiCloud.

You can pass a single payload (dict) or a list of payloads (list of dict).

Parameters:

payload – The payload to send with the request

Returns:

The result of the request

class fotoobo.fortinet.fortigate.FortiGate(hostname: str = '', token: str = '', **kwargs: dict[str, str])

Represents one FortiGate (digital twin)

__init__(hostname: str = '', token: str = '', **kwargs: dict[str, str]) None

Set some initial parameters.

Parameters:
  • hostname – The hostname of the FortiGate to connect to

  • token – API access token from the FortiGate

  • **kwargs – See Fortinet class for available arguments

api(method: str, url: str = '', headers: dict[str, str] | None = None, params: dict[str, str] | None = None, payload: dict[str, Any] | None = None, timeout: float | None = None) Response

Native API request to a FortiGate.

It uses the super.api method but it has to enrich the payload in post requests with the needed session key.

Parameters:
  • method – Request method from [get, post]

  • url – Rest API URL to request data from

  • params – Dictionary with parameters (if needed)

  • payload – JSON body for post requests (if needed)

  • timeout – The requests read timeout

Returns:

Response from the request

api_get(url: str, vdom: str = '*', timeout: float | None = None) list[Any]

Low level GET request to a FortiGate.

This gets the response from a single API request to a FortiGate and returns it as a fotoobo Results object.

Parameters:
  • url – The API endpoint to access

  • vdom – The VDOM to access (“vdom1” or “vdom1,vdom2” or “*”)

  • timeout – The time to wait for a response from the FortiGate

Returns:

The Result object with all the results as list (even if only one result is returned)

backup(timeout: int = 60) str

Get the configuration backup from a FortiGate.

Parameters:

timeout – Timeout in sec to wait for the response

Returns:

Configuration backup as text

get_version() str

Get FortiGate version

Returns:

FortiGate version

class fotoobo.fortinet.fortimanager.FortiManager(hostname: str, username: str, password: str, **kwargs: Any)

Represents one FortiManager (digital twin)

__init__(hostname: str, username: str, password: str, **kwargs: Any) None

Set some initial parameters.

Parameters:
  • hostname – The hostname of the FortiGate to connect to

  • username – The username

  • password – The password

Keyword Arguments:
  • session_path – The path where to load/save the FortiManager session key

  • **kwargs – See Fortinet class for more available arguments

api(method: str, url: str = '', headers: dict[str, str] | None = None, params: dict[str, str] | None = None, payload: dict[str, Any] | None = None, timeout: float | None = None) Response

API request to a FortiManager device.

It uses the super.api method but it has to enrich the payload in post requests with the needed session key.

Parameters:
  • method – Request method from [get, post]

  • url – Rest API URL to request data from

  • headers – Dictionary with headers (if needed)

  • params – Dictionary with parameters (if needed)

  • payload – JSON body for post requests (if needed)

  • timeout – The requests read timeout in seconds

Returns:

Response from the request

api_delete(url: str) Response

DELETE method for API requests

Parameters:

url – API endpoint to access

Result:

FortiManager result item

api_get(url: str, params: dict[str, Any] | None = None, timeout: float | None = None) Response

GET method for API requests

Parameters:
  • url – API endpoint to access

  • params – Additional query parameters if needed

  • timeout – The requests read timeout in seconds

Result:

FortiManager result item

assign_all_objects(adoms: str, policy: str) int

Copies all objects from the global ADOM database to a given ADOM.

Parameters:
  • adoms – The ADOM to assign the global policy/objects to. If you specify an invalid ADOM name you’ll get a permission error. You can specify multiple ADOMs by separating them with a comma (no spaces)

  • policy – Specify the global policy to assign [Default: ‘default’].

Returns:

The id of the FortiManager task created or 0 (zero) if unsuccessful

delete_adom_address(adom: str, address: str, dry: bool = False) dict[str, Any]

Delete an address from an ADOM in FortiManager

Parameters:
  • adom – The ADOM to delete the address from

  • address – The address to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_adom_address_group(adom: str, group: str, dry: bool = False) dict[str, Any]

Delete an address group from an ADOM in FortiManager

Parameters:
  • adom – The ADOM to delete the address group from

  • group – The address group to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_adom_service(adom: str, service: str, dry: bool = False) dict[str, Any]

Delete a service from an ADOM in FortiManager

Parameters:
  • adom – The ADOM to delete the address from

  • service – The service to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_adom_service_group(adom: str, group: str, dry: bool = False) dict[str, Any]

Delete a service group from an ADOM in FortiManager

Parameters:
  • adom – The ADOM to delete the address group from

  • group – The address group to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_global_address(address: str, dry: bool = False) dict[str, Any]

Delete a global address from FortiManager

To be sure to not delete used objects we configure the FortiManager as follows:

config system admin setting

set objects-force-deletion disable

Before deleting a global address object we have to check if it’s in use in any ADOM. Only after we found that no ADOM uses the object we can safely delete it.

Fortinet documentation links:

https://docs.fortinet.com/document/fortimanager/7.0.12/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.2.7/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.4.3/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.6.0/administration-guide/322714

Parameters:
  • address – The global address to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_global_address_group(group: str, dry: bool = False) dict[str, Any]

Delete a global address group from FortiManager

To be sure to not delete used objects we configure the FortiManager as follows:

config system admin setting

set objects-force-deletion disable

Before deleting a global address group object we have to check if it’s in use in any ADOM. Only after we found that no ADOM uses the object we can safely delete it.

Fortinet documentation links:

https://docs.fortinet.com/document/fortimanager/7.0.12/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.2.7/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.4.3/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.6.0/administration-guide/322714

Parameters:
  • group – The global address group to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_global_service(service: str, dry: bool = False) dict[str, Any]

Delete a global service from FortiManager

To be sure to not delete used objects we configure the FortiManager as follows:

config system admin setting

set objects-force-deletion disable

Before deleting a global service object we have to check if it’s in use in any ADOM. Only after we found that no ADOM uses the object we can safely delete it.

Fortinet documentation links:

https://docs.fortinet.com/document/fortimanager/7.0.12/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.2.7/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.4.3/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.6.0/administration-guide/322714

Parameters:
  • service – The global service to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

delete_global_service_group(group: str, dry: bool = False) dict[str, Any]

Delete a global service group from FortiManager

To be sure to not delete used objects we configure the FortiManager as follows:

config system admin setting

set objects-force-deletion disable

Before deleting a global service group object we have to check if it’s in use in any ADOM. Only after we found that no ADOM uses the object we can safely delete it.

Fortinet documentation links:

https://docs.fortinet.com/document/fortimanager/7.0.12/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.2.7/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.4.3/administration-guide/322714 https://docs.fortinet.com/document/fortimanager/7.6.0/administration-guide/322714

Parameters:
  • group – The global service group to delete

  • dry – Set to True to enable dry-run (no changes on FortiManager)

Returns:

FortiManager result item

get_adoms(ignored_adoms: list[str] | None = None) list[Any]

Get FortiManager ADOM list

Some of the ADOMs are ignored by default as the are not used in most cases

Returns:

List of FortiManager ADOMs

get_global_address(address: str, scope_member: bool = False) dict[str, Any]

Get an address object from global ADOM

Parameters:
  • address – The address to get

  • scope_member – Whether the scope member attribute should be included in the response

Returns:

FortiManager result item

get_global_address_group(group: str, scope_member: bool = False) dict[str, Any]

Get an address group object from the global ADOM

Parameters:
  • group – The address group to get

  • scope_member – Whether the scope member attribute should be included in the response

Returns:

FortiManager result item

get_global_address_groups() dict[str, Any]

Get the global address group database

Returns:

FortiManager result item

get_global_addresses() dict[str, Any]

Get the global address database

Returns:

FortiManager result item

get_global_service(service: str, scope_member: bool = False) dict[str, Any]

Get a service object from global ADOM

Parameters:
  • service – The service to get

  • scope_member – Whether the scope member attribute should be included in the response

Returns:

FortiManager result item

get_global_service_group(group: str, scope_member: bool = False) dict[str, Any]

Get a service group object from the global ADOM

Parameters:
  • group – The address group to get

  • scope_member – Whether the scope member attribute should be included in the response

Returns:

FortiManager result item

get_global_service_groups() dict[str, Any]

Get the global network service group database

Returns:

FortiManager result item

get_global_services() dict[str, Any]

Get the global services database

Returns:

FortiManager result item

get_version() str

Get FortiManager version.

Returns:

FortiManager version

login() int

Login to the FortiManager.

If the login to the FortiManager was successful it stores the session key in the object. We do not use requests.session as the session key is just a string which is saved directly.

Returns:

Status code from the FortiManager login

logout() int

Logout from FortiManager.

Returns:

Status code from the FortiManager logout

post(adom: str, payloads: Any) list[str]

POST method to FortiManager.

You can pass a single payload (Dict) or a list of payloads (List of Dict).

Parameters:
  • adom – The ADOM name to issue the set commands to. If you wish to update the Global ADOM specify ‘global’ as ADOM.

  • payloads – One payload (Dict) or a list of payloads (List of Dict)

Returns:

Amount of errors occurred during the set command

wait_for_task(task_id: int, timeout: int = 60) list[Any]

Wait for a task with a given id for its end and returns the message(s).

Parameters:
  • id – Task id to wait for

  • timeout – Timeout in seconds

Returns:

Message list

Inventory

class fotoobo.inventory.inventory.Inventory(inventory_file: Path)

Represents an inventory full of Fortinet and generic devices. Instantiate the inventory by providing an inventory file in yaml format as described in the documentation at https://fotoobo.readthedocs.io/en/latest/usage/inventory.html

__init__(inventory_file: Path) None

Initialize the inventory

Parameters:

file (inventory) – The Path object to the inventory file.

get(name: str | None = None, type: str | None = None) dict[str, Any]

Get a dictionary of assets from the inventory with given ‘filters’.

Parameters:
  • name – Which asset to get. If blank get every asset. Wildcard * is supported in any position. E.g. “FortiGate”, “Gate”, “Forti*ate”, “Forti”.

  • type – Which asset type to get. If blank get every asset.

Returns:

Dictionary of assets with name as key

Raises:

GeneralWarning – If no asset was found in the inventory that matches name or type

get_item(name: str = '', type: str | None = None) Any

Get a single asset from the inventory. To be sure the item has the correct type you can specify the desired type and a GeneralWarning is raised if the type does not match.

Parameters:
  • name – Which exact asset to get.

  • type – If you specify a type it is checked if it matches the type of the asset

Returns:

Inventory asset

Raises:
  • GeneralWarning – If the asset was not found in the inventory

  • GeneralWarning – If the specified type does not match the type of the item

class fotoobo.inventory.generic.GenericDevice(**kwargs: str | int | bool)

This is the class for a generic device.

All kwarg will be unpacked and written to the instance as attributes. There are some mandatory attributes which will be filled with a default value.

__init__(**kwargs: str | int | bool) None

init

Helpers

cli

Helper functions for testing the cli

fotoobo.helpers.cli.walk_cli_info(info: dict[str, Any], tree: Tree, command_path: list[str] | None = None) Tree

Recursively create the cli command tree from a Typer info dict.

Parameters:
  • info – The Typer info dict from Typer.Context.to_info_dict() to walk through

  • tree – The rich tree object to build

  • command_path – The command path as a list

Returns:

The complete rich Tree object

config

The config helper is used to load and set basic configuration for fotoobo. Some configuration options may be set by the global configuration file which by default points to fotoobo.yaml in the local directory. Some configuration options may be set by command line parameters as described in the cli help system. If there are configuration options available in the global configuration file and also as a command line option, the command line option takes precedence over the global configuration file option.

class fotoobo.helpers.config.Config(inventory_file: Path = PosixPath('inventory.yaml'), logging: dict[str, ~typing.Any] | None=None, audit_logging: dict[str, ~typing.Any] | None=None, no_logo: bool = False, cli_info: dict[str, ~typing.Any]=<factory>, vault: dict[str, str]=<factory>)

This is the configuration dataclass for the global configuration options. First all the configuration options must be initialized. If an option is not defined here it is not guaranteed that it may be used later in the code.

load_configuration(config_file: Path | None = None) None

Load the global fotoobo configuration file. If the configuration file is not present it just will be ignored and all the options remain as they are. If a file is present it looks for configuration options to set. Keep in mind that it is not mandatory to define every option in the configuration file. For that case make sure that an option not present in the configuration file is set with its default.

Parameters:

config_file – fotoobo configuration file to load configuration from

files

Some helper functions for file manipulation.

fotoobo.helpers.files.create_dir(directory: Path) None

Try to create a given directory if it does not exist.

Parameters:

directory – The directory to create (in case it not already exists)

Raises:

OSError – Error with message

fotoobo.helpers.files.file_to_ftp(file: Path, server: Any) int

Upload a file to a ftp server.

Parameters:
  • file – The source file to upload

  • server – The ftp sever definition dict containing the following keys: * hostname * directory * username * password * protocol (default=”sftp”)

Returns:

Return code

fotoobo.helpers.files.file_to_zip(src: Path, dst: Path, level: int = 9) None

Zip (compress) a file.

Parameters:
  • src – The source file

  • dst – The destination file (zipfile). If the dst file ends with extension ‘.zip’ the inner file will omit the ‘.zip’ extension.

  • level – Compression level, as accepted by zipfile.ZipFile

Returns:

Return code

fotoobo.helpers.files.load_json_file(json_file: Path) list[Any] | dict[str, Any] | None

Loads the content of a json file into a list or dict.

Parameters:

json_file – The path to the json file to load

Returns:

List or dict with json data from filename or None if file is not found

fotoobo.helpers.files.load_yaml_file(yaml_file: Path) list[Any] | dict[str, Any] | None

Loads the content of a yaml file into a list or dict.

Parameters:

yaml_file – The file of the yaml file to load

Returns:

Yaml data from filename

fotoobo.helpers.files.save_json_file(json_file: Path, data: list[Any] | dict[Any, Any]) bool

Saves the content of a list or dict to a json file.

Parameters:
  • json_file – The file to write the data into

  • data – The data to save

Returns:

True if data was valid

fotoobo.helpers.files.save_txt_file(file: Path, data: str) bool

Saves the content of any data object to a text file.

Parameters:
  • file – The file to write the data into

  • data – The data to save

Returns:

True if data was valid

fotoobo.helpers.files.save_yaml_file(yaml_file: Path, data: list[Any] | dict[str, Any]) bool

Saves the content of a list or dict to a yaml file.

Parameters:
  • yaml_file – The file to write the data into

  • data – The data to save

Returns:

True if data was valid

log

The logging helper class is used if you want to write logs to the screen or a file. It is set up to do pretty printing screen output with rich and writing “normal” text to a logfile. Basic logging options can be configured in the main configuration file. See config_helper.py

class fotoobo.helpers.log.Log

The logger class for log control.

static audit(message: str) None

Create an audit log message

static configure_logging(quiet: bool | None, log_level: str | None) None

This function will configure the logging for fotoobo

Parameters:
  • quiet – Disables the console logging

  • log_level – The desired log_level (given by CLI argument)

Raises:

GeneralError – On unrecoverable errors (usually on non-existing/empty or invalid logging configuration file

class fotoobo.helpers.log.SysLogFormatter(facility: int, fmt: str = '%(message)s', datefmt: str | None = None)

Handles syslog formats

__init__(facility: int, fmt: str = '%(message)s', datefmt: str | None = None)

Initialize the logger

Parameters:

facility

format(record: LogRecord) str

Format the message

Parameters:

record

Returns:

A string

output

The beautiful output helper

Print the beautiful fotoobo logo

fotoobo.helpers.output.write_policy_to_html(data: list[dict[str, Any]], out_file: Path) None

Write a Firewall policy to a HTML file

Parameters:
  • data – List of Dicts with data

  • out_file – Filename to write the HTML output to

result

How To Use The Results Helper

The fotoobo Result class

class fotoobo.helpers.result.Result

This class represents a Result of an operation in fotoobo.

This dataset is meant to be the generic result structure for any tool inside fotoobo. It can then be rendered to some command line output (CLI) or JSON response (REST API).

__init__() None

Create the FotooboResult object

all_results() dict[str, T]

Return all results

Returns:

The results as a dictionary of the following form – { ‘<name of the host>’: <data> } where <data> may be of any type

get_messages(host: str) list[dict[str, str]]

Return all the messages for the host given

Parameters:

host – The host to get the messages for

Returns:

A list of the messages pushed for this host. If there are no messages for this host, it will return an empty list.

get_result(host: str) T

Return the result pushed by this

Parameters:

host – The name of the host to retrieve the result for

Returns:

The results stored before with push_results, or None if the host does not exist

Raises:

GeneralWarning – If there is no result for host

print_messages(only_host: str | None = None) None

Print the messages to the console

Parameters:

only_host – Only print the messages for host only_host. If None is given, print all messages.

print_raw(key: str | None = None) None

Print the raw data from Result() in pretty format.

Parameters:

key – Print only the result for the host given (default: print all results)

print_result_as_table(title: str = '', auto_header: bool = False, headers: list[str] | None = None) None

Print a table from given data as list or dict.

Parameters:
  • title – Set the preferred title for the table

  • auto_header – Whether to show the headers (default: off)

  • headers – Set the headers (if needed)

Raises:

GeneralWarning – If the data cannot be interpreted as a table

print_table_raw(data: list[dict[str, Any]], headers: list[str] | None = None, auto_header: bool = False, title: str = '') None

Print the data given as a rich table to the console

Parameters:
  • data – The data to print formatted as rich.table.Table will expect it

  • headers – The headers for the table

  • auto_header – Whether to show the headers or not

  • title – The title for the table

push_message(host: str, message: str, level: str = 'info') None

Add a message for the host

Parameters:
  • host – The host to add the message for

  • message – The message to add

  • level – The level to assign to this message, used for later filtering (use for example “info”, “warning”, “error”)

push_result(key: str, data: T, successful: bool = True) None

Add a result for the given key

Parameters:
  • key – The key to push the results for

  • data – The output data for this key

  • successful – Whether the call has been successful or not [default: True]

save_raw(file: Path, key: str | None = None) None

Save the raw data in defined format.

Parameters:

key – Print only the result for the host given (default: print all results)

save_with_template(host: str, template_file: Path, output_file: Path) None

Saves a data structure to a file with a given Jinja2 template. The data structure and the variables you can use in the template file depend on the utility the data comes from. See the docs of the used utility to see what variables you’re intended to use.

Parameters:
  • data – The data used in the template

  • template_file – Filename of the Jinja2 template file

  • output_file – The file to write the output to

send_messages_as_mail(smtp_server: Any, levels: list[str] | str | None = None, count: bool = False, command: bool = False) None

Send an e-mail with the messages collected up until the call

Parameters:
  • command – Whether to write the issued command into the message (default: false)

  • count – Whether to write the message count into the message (default: false)

  • smtp_server – The smtp server from inventory to use

  • levels – The levels to output: - None means all messages will be output (default) - ‘level’ means only messages with level=’level’ will be output - [‘level1’, ‘level2’] like 2nd option, but all levels given will get output