zabgrab.services.ports¶
Interfaces between the services and the outside world.
Services receive implementations of these protocols as arguments, so that tests can substitute fakes (a scripted UI, a frozen clock, an in-memory Zabbix server, …). Services never print, prompt or perform I/O except through these.
- zabgrab.services.ports.ClientFactory¶
Creates an (unauthenticated) client for a server’s config.
- Type:
Classes
|
Source of the current time. |
|
Opens a file for the user to edit. |
|
One option offered by |
|
Reports progress of a download: an overall count plus one bar per item. |
|
Persistent storage for API tokens, keyed by server URL. |
|
User interaction. |
|
A connection to one Zabbix server. |
- class zabgrab.services.ports.Option(label, value, description=None)[source]¶
Bases:
Generic[T]One option offered by
UI.choose()orUI.choose_many().- value¶
What choosing it returns.
- Type:
T
- class zabgrab.services.ports.Progress(*args, **kwargs)[source]¶
Bases:
ProtocolReports progress of a download: an overall count plus one bar per item.
- class zabgrab.services.ports.UI(*args, **kwargs)[source]¶
Bases:
ProtocolUser interaction.
Messages are plain text; the implementation decides how to style them. They go to stderr, so stdout carries only data.
Every method that asks for input takes a
fixargument: a message telling the user how to provide the answer without being asked (e.g. a flag or config snippet). When the session is not interactive, yes/no questions take their default answer with a warning; other questions raisezabgrab.errors.InputRequiredcarryingfix, since there’s no answer to carry on with.- debug(message)[source]¶
Show a message only with
-vor--debug.- Parameters:
message (str)
- Return type:
None
- success(message)[source]¶
Show that something worked (hidden by
-q).- Parameters:
message (str)
- Return type:
None
- warning(message)[source]¶
Show a warning (hidden by
-qq).- Parameters:
message (str)
- Return type:
None
- error(message, *, details=(), hint=None)[source]¶
Show an error, with optional detail lines and a hint on how to fix it.
- confirm(question, *, fix, default=True)[source]¶
Ask a yes/no question.
Unlike the other questions, this doesn’t fail when the session isn’t interactive: it warns (including
fix) and returnsdefault.
- prompt(question, *, fix, parse, default=None, secret=False)[source]¶
Ask for free text.
- Parameters:
question (str) – The question.
fix (str) – How to give the answer without being asked.
parse (callable) – Converts the answer, raising
ValueError(whose message is shown before asking again) if it’s invalid.default (str, optional) – The answer if the user just presses Enter.
secret (bool, optional) – Hide the input (e.g. for passwords).
- Returns:
T – The parsed answer.
- Raises:
InputRequired – If the session isn’t interactive.
- Return type:
T
- choose(question, options, *, fix, default=None)[source]¶
Ask the user to pick one option.
- Parameters:
- Returns:
T – The chosen option’s value.
- Raises:
InputRequired – If the session isn’t interactive.
- Return type:
T
- choose_many(question, options, *, fix)[source]¶
Ask the user to pick one or more options (e.g.
1,3,5-8orall).- Parameters:
- Returns:
list of T – The chosen options’ values, in the order offered.
- Raises:
InputRequired – If the session isn’t interactive.
- Return type:
list[T]
- class zabgrab.services.ports.Clock(*args, **kwargs)[source]¶
Bases:
ProtocolSource of the current time.
- class zabgrab.services.ports.Editor(*args, **kwargs)[source]¶
Bases:
ProtocolOpens a file for the user to edit.
- class zabgrab.services.ports.SecretStore(*args, **kwargs)[source]¶
Bases:
ProtocolPersistent storage for API tokens, keyed by server URL.
- class zabgrab.services.ports.ZabbixClient(*args, **kwargs)[source]¶
Bases:
ProtocolA connection to one Zabbix server.
See
zabgrab.adapters.zabbix.ZabbixAPIfor the real one.- async check_version()[source]¶
Get the server’s version, raising if it isn’t supported.
- Return type:
- async login_token(token)[source]¶
Authenticate with an API token, raising if it’s rejected.
- Parameters:
token (str)
- Return type:
None
- async login_password(username, password)[source]¶
Authenticate with a username and password, raising if rejected.
- async hosts(*, pattern=None, group=None, limit=None)[source]¶
Find hosts by name pattern and host group pattern.
- async items(*, itemids=None, hostids=None, name=None, key=None, tag=None, limit=None)[source]¶
Find items matching all of the given filters.