Alertmanager

  • By Dylan Stephano-Shachter
juju deploy alertmanager-k8s --channel edge
Show information
You will need Juju 2.9 to be able to run this command. Learn how to upgrade to Juju 2.9.
Channel Version Revision Published Runs on
latest/edge 7 7 29 Nov 2021
Ubuntu 20.04

Platform:

charms.alertmanager_k8s.v0.alertmanager_dispatch

Alertmanager library.

This library is designed to be used by a charm consuming or providing the alertmanager_dispatch relation interface.

This library is published as part of the Alertmanager charm.

You can file bugs here!

A typical example of including this library might be:

# ...
from charms.alertmanager_k8s.v0.alertmanager_dispatch import AlertmanagerConsumer

class SomeApplication(CharmBase):
  def __init__(self, *args):
    # ...
    self.alertmanager_consumer = AlertmanagerConsumer(self, relation_name="alertmanager")
    # ...

class ClusterChanged

Event raised when an alertmanager cluster is changed.

Description

If an alertmanager unit is added to or removed from a relation, then a :class:`ClusterChanged` event should be emitted.

class AlertmanagerConsumerEvents

Description

Event descriptor for events raised by `AlertmanagerConsumer`. None

class RelationManagerBase

Base class that represents relation ends ("provides" and "requires").

Methods

RelationManagerBase. __init__( self , charm , relation_name , relation_role )

RelationManagerBase. _validate_relation( self , relation_name , relation_role )

class AlertmanagerConsumer

A "consumer" handler to be used by charms that relate to Alertmanager (the 'requires' side).

Arguments

charm (CharmBase)
consumer charm
relation_name (str)
from consumer's metadata.yaml

Attributes

charm (CharmBase)
consumer charm

Description

To have your charm consume alertmanager cluster data, declare the interface's use in your charm's metadata.yaml file: ```yaml requires: alertmanager: interface: alertmanager_dispatch ``` A typical example of importing this library might be ```python from charms.alertmanager_k8s.v0.alertmanager_dispatch import AlertmanagerConsumer ``` In your charm's `__init__` method: ```python self.alertmanager_consumer = AlertmanagerConsumer(self, relation_name="alertmanager") ``` Every change in the alertmanager cluster emits a :class:`ClusterChanged` event that the consumer charm can register and handle, for example: ``` self.framework.observe(self.alertmanager_consumer.on.cluster_changed, self._on_alertmanager_cluster_changed) ``` The updated alertmanager cluster can then be obtained via the `get_cluster_info` method This consumer library expect the consumer charm to observe the `cluster_changed` event.

Methods

AlertmanagerConsumer. __init__( self , charm , relation_name )

AlertmanagerConsumer. _on_relation_changed( self , event )

Description

This hook notifies the charm that there may have been changes to the cluster. None

AlertmanagerConsumer. get_cluster_info( self )

Description

Returns a list of ip addresses of all the alertmanager units. None

AlertmanagerConsumer. _on_relation_departed( self , _ )

Description

This hook notifies the charm that there may have been changes to the cluster. None

AlertmanagerConsumer. _on_relation_broken( self , _ )

Description

This hook notifies the charm that a relation has been completely removed. None

class AlertmanagerProvider

A "provider" handler to be used by charms that relate to Alertmanager (the 'provides' side).

Arguments

charm (CharmBase)
consumer charm
relation_name (str)
relation name (not interface name)
api_port (int)
alertmanager server's api port; this is needed here to avoid accessing charm constructs directly

Attributes

charm (CharmBase)
the Alertmanager charm

Description

To have your charm provide alertmanager cluster data, declare the interface's use in your charm's metadata.yaml file: ```yaml provides: alerting: interface: alertmanager_dispatch ``` A typical example of importing this library might be ```python from charms.alertmanager_k8s.v0.alertmanager_dispatch import AlertmanagerProvider ``` In your charm's `__init__` method: ```python self.alertmanager_provider = AlertmanagerProvider(self, self._relation_name, self._api_port) ``` Then inform consumers on any update to alertmanager cluster data via ```python self.alertmanager_provider.update_relation_data() ``` This provider auto-registers relation events on behalf of the main Alertmanager charm.

Methods

AlertmanagerProvider. __init__( self , charm , relation_name , api_port )

AlertmanagerProvider. api_port( self )

Description

Get the API port number to use for alertmanager. None

AlertmanagerProvider. _on_relation_joined( self , event )

This hook stores the public address of the newly-joined "alerting" relation.

Description

This is needed for consumers such as prometheus, which should be aware of all alertmanager instances.

AlertmanagerProvider. _generate_relation_data( self , relation )

Description

Helper function to generate relation data in the correct format. None

AlertmanagerProvider. update_relation_data( self , event )

Helper function for updating relation data bags.

Description

This function can be used in two different ways: - update relation data bag of a given event (e.g. a newly joined relation); - update relation data for all relations Args: event: The event whose data bag needs to be updated. If it is None, update data bags of all relations.