zabgrab.services.servers

Choosing which Zabbix server(s) to use.

zabgrab.services.servers.SaveServer

Saves a new server (name, URL) to the user’s config.

Type:

type

zabgrab.services.servers.ADD_SERVER_SNIPPET

Config showing how to add a server, for hints.

Type:

str

Functions

parse_url(text)

Parse a server URL typed by the user, adding https:// if needed.

resolve_server(ref, config, ui, *[, save])

Resolve a server name or URL.

select_server(configured, config, ui, *[, save])

Resolve the one server to fetch from.

select_servers(cli, configured, config, ui, *)

Resolve the servers to search (hosts, items).

suggest_name(url, existing)

Suggest a name for a server from its URL's hostname.

zabgrab.services.servers.select_server(configured, config, ui, *, save=None)[source]

Resolve the one server to fetch from.

Parameters:
  • configured (str or Choice of str or None) – A server name or URL, a choice to ask about, or None to ask which of the configured servers to use.

  • config (Config) – The configuration.

  • ui (UI) – For questions and warnings.

  • save (SaveServer, optional) – If given, offered for custom URLs entered at a prompt.

Returns:

Server – The server.

Raises:
  • ZabgrabError – If a server name is unknown and the user can’t be asked.

  • InputRequired – If a question is needed but the session isn’t interactive.

Return type:

Server

zabgrab.services.servers.select_servers(cli, configured, config, ui, *, save=None)[source]

Resolve the servers to search (hosts, items).

Parameters:
  • cli (sequence of str) – The --server names or URLs given; each is used if there are any.

  • configured (str or Choice of str or None) – Otherwise, the one server to use (see select_server()).

  • config (Config) – The configuration.

  • ui (UI) – For questions and warnings.

  • save (SaveServer, optional) – If given, offered for custom URLs entered at a prompt.

Returns:

list of Server – The servers.

Return type:

list[Server]

zabgrab.services.servers.resolve_server(ref, config, ui, *, save=None)[source]

Resolve a server name or URL.

Unknown names get a “did you mean” suggestion: a question if the session is interactive (falling back to asking which server to use), else a hint.

Parameters:
  • ref (str) – A configured server’s name, or a URL.

  • config (Config) – The configuration.

  • ui (UI) – For questions and warnings.

  • save (SaveServer, optional) – If given, offered for custom URLs entered at a prompt.

Returns:

Server – The server.

Raises:

ZabgrabError – If the name is unknown and the session isn’t interactive.

Return type:

Server

zabgrab.services.servers.parse_url(text)[source]

Parse a server URL typed by the user, adding https:// if needed.

Parameters:

text (str) – What the user typed.

Returns:

str – The URL.

Raises:

ValueError – If it isn’t a URL.

Return type:

str

zabgrab.services.servers.suggest_name(url, existing)[source]

Suggest a name for a server from its URL’s hostname.

The first hostname label that isn’t zabbix or www is used, made into a valid name and numbered if needed to avoid clashes.

Parameters:
  • url (str) – The server’s URL.

  • existing (sequence of str) – Names already taken.

Returns:

str – The name.

Return type:

str

Examples

>>> suggest_name("https://zabbix.demo.example.org", ["demo"])
'demo-2'