zabgrab.services.session¶
Connecting and logging in to a Zabbix server.
- zabgrab.services.session.UpdateServerUrl¶
Changes a configured server’s URL (name, new URL) in the config file that defines it.
- Type:
Functions
|
Ask for a token until the server accepts one. |
|
Connect to a server and log in. |
|
Find the token to use for a server. |
|
Parse an answer that can't be empty, stripping spaces. |
|
Connect to a server (without logging in) and check its version. |
|
Explain how to give zabgrab a token for a server without being asked. |
Classes
|
A server's token, and where it comes from. |
- class zabgrab.services.session.TokenLookup(token, source)[source]¶
Bases:
objectA server’s token, and where it comes from.
- zabgrab.services.session.find_token(server, secrets, env)[source]¶
Find the token to use for a server.
- Parameters:
server (Server) – The server.
secrets (SecretStore) – The stored tokens.
env (mapping of str to str) – Environment variables.
- Returns:
TokenLookup – Its
token_envvariable’s value if set, otherwise the keyring’s token.- Return type:
- zabgrab.services.session.token_fix(server)[source]¶
Explain how to give zabgrab a token for a server without being asked.
- async zabgrab.services.session.ask_for_token(client, ui, *, fix='')[source]¶
Ask for a token until the server accepts one.
- Parameters:
client (ZabbixClient) – The server’s client; it’s logged in when this returns.
ui (UI) – Asks for the token.
fix (str, optional) – How to give the token without being asked.
- Returns:
str – The accepted token.
- Raises:
InputRequired – If the session isn’t interactive.
- Return type:
- zabgrab.services.session.non_empty(text)[source]¶
Parse an answer that can’t be empty, stripping spaces.
- async zabgrab.services.session.connect(server, *, factory, ui, secrets, env, update_url=None)[source]¶
Connect to a server and log in.
If the server redirects (e.g. from HTTP to HTTPS), interactive users are asked whether to follow, and whether to update the server’s URL in their config via
update_url; otherwise the redirect is an error.Tokens come from the server’s
token_envvariable, then the keyring. If there is none (or it’s rejected), interactive users can paste a token or log in with a password; otherwise an error explains how to provide one.- Parameters:
server (Server) – The server.
factory (ClientFactory) – Creates the client.
ui (UI) – Asks about redirects and logging in.
secrets (SecretStore) – The stored tokens.
env (mapping of str to str) – Environment variables (for
token_env).update_url (callable, optional) – Offered to update a configured server’s URL after a redirect.
- Returns:
ZabbixClient – The logged-in client (close it when done).
- Raises:
ConnectionFailed – If the server can’t be reached, or redirects non-interactively.
AuthenticationFailed – If the login is rejected non-interactively.
InputRequired – If credentials are needed and the session isn’t interactive.
- Return type:
- async zabgrab.services.session.open_client(server, *, factory, ui, update_url=None)[source]¶
Connect to a server (without logging in) and check its version.
Redirects are handled as described for
connect().- Parameters:
server (Server) – The server.
factory (ClientFactory) – Creates the client.
ui (UI) – Asks about redirects.
update_url (callable, optional) – Offered to update a configured server’s URL after a redirect.
- Returns:
ZabbixClient – The client, not logged in.
Server – The server, with its new URL if redirected.
str – The server’s Zabbix version.
- Raises:
ConnectionFailed – If the server can’t be reached, redirects too often, or redirects non-interactively.
UnsupportedServer – If its Zabbix version is too old.
- Return type: