alertmanager

Alertmanager module.

exception spicerack.alertmanager.AlertmanagerError[source]

Bases: spicerack.exceptions.SpicerackError

Custom exception class for errors of this module.

class spicerack.alertmanager.AlertmanagerHosts(target_hosts: spicerack.typing.TypeHosts, *, verbatim_hosts: bool = False)[source]

Bases: object

Operate on Alertmanager via its APIs.

Initialize the instance.

Parameters
  • target_hosts (spicerack.typing.TypeHosts) -- the target hosts either as a NodeSet instance or a sequence of strings.

  • verbatim_hosts (bool, optional) -- if True use the hosts passed verbatim as is, if instead False, the default, consider the given target hosts as FQDNs and extract their hostnames to be used in Alertmanager.

When using Alertmanager in high availability (cluster) make sure to pass all hosts in your cluster as alertmanager_urls.

downtime(reason: spicerack.administrative.Reason, *, duration: datetime.timedelta = datetime.timedelta(seconds=14400)) str[source]

Issue a new downtime.

Parameters
Returns

the downtime ID.

Return type

str

Raises

AlertmanagerError -- if none of the alertmanager_urls API returned a success.

downtimed(reason: spicerack.administrative.Reason, *, duration: datetime.timedelta = datetime.timedelta(seconds=14400), remove_on_error: bool = False) Iterator[None][source]

Context manager to perform actions while the hosts are downtimed on Alertmanager.

Parameters
  • reason (spicerack.administrative.Reason) -- the reason to set for the downtime on Alertmanager.

  • duration (datetime.timedelta, optional) -- the length of the downtime period.

  • remove_on_error -- should the downtime be removed even if an exception was raised.

Yields

None -- it just yields control to the caller once Alertmanager has received the downtime and deletes the downtime once getting back the control.

remove_downtime(downtime_id: str) None[source]

Remove a downtime.

Parameters

downtime_id (str) -- the downtime ID to remove.

Raises

AlertmanagerError -- if none of the alertmanager_urls API returned a success.