Alertmanager
- Canonical Observability
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 128 | 03 Dec 2024 | |
latest/candidate | 138 | 03 Dec 2024 | |
latest/beta | 138 | 19 Nov 2024 | |
latest/edge | 144 | 20 Dec 2024 | |
1.0/stable | 96 | 12 Dec 2023 | |
1.0/candidate | 96 | 22 Nov 2023 | |
1.0/beta | 96 | 22 Nov 2023 | |
1.0/edge | 96 | 22 Nov 2023 |
juju deploy alertmanager-k8s
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
charms.alertmanager_k8s.v0.alertmanager_remote_configuration
-
- Last updated 10 May 2023
- Revision Library version 0.3
Alertmanager Remote Configuration library.
This library offers the option of configuring Alertmanager via relation data.
It has been created with the alertmanager-k8s
and the alertmanager-k8s-configurer
(https://charmhub.io/alertmanager-configurer-k8s) charms in mind, but can be used by any charms
which require functionalities implemented by this library.
To get started using the library, you just need to fetch the library using charmcraft
.
cd some-charm
charmcraft fetch-lib charms.alertmanager_k8s.v0.alertmanager_remote_configuration
Charms that need to push Alertmanager configuration to a charm exposing relation using
the alertmanager_remote_configuration
interface, should use the RemoteConfigurationProvider
.
Charms that need to can utilize the Alertmanager configuration provided from the external source
through a relation using the alertmanager_remote_configuration
interface, should use
the RemoteConfigurationRequirer
.
Index
class ConfigReadError
Description
Raised if Alertmanager configuration can't be read. None
Methods
ConfigReadError. __init__( self , config_file: str )
def config_main_keys_are_valid(config)
Checks whether main keys in the Alertmanager's config file are valid.
Arguments
Alertmanager config dictionary
Returns
True/False
Description
This method facilitates the basic sanity check of Alertmanager's configuration. It checks
whether given configuration contains only allowed main keys or not. templates
have been
removed from the list of allowed main keys to reflect the fact that alertmanager-k8s
doesn't
accept it as part of config (see alertmanager-k8s
description for more details).
Full validation of the config is done on the alertmanager-k8s
charm side.
class AlertmanagerRemoteConfigurationChangedEvent
Description
Event emitted when Alertmanager remote_configuration relation data bag changes. None
class AlertmanagerRemoteConfigurationRequirerEvents
Description
Event descriptor for events raised by AlertmanagerRemoteConfigurationRequirer
. None
class RemoteConfigurationRequirer
API that manages a required alertmanager_remote_configuration
relation.
Description
The RemoteConfigurationRequirer
object can be instantiated as follows in your charm:
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import (
RemoteConfigurationRequirer,
)
def __init__(self, *args):
...
self.remote_configuration = RemoteConfigurationRequirer(self)
...
The RemoteConfigurationRequirer
assumes that, in the metadata.yaml
of your charm,
you declare a required relation as follows:
requires:
remote-configuration: # Relation name
interface: alertmanager_remote_configuration # Relation interface
limit: 1
The RemoteConfigurationRequirer
provides a public config
method for exposing the data
from the relation data bag. Typical usage of these methods in the provider charm would look
something like:
def get_config(self, *args):
...
configuration, templates = self.remote_configuration.config()
...
self.container.push("/alertmanager/config/file.yml", configuration)
self.container.push("/alertmanager/templates/file.tmpl", templates)
...
Separation of the main configuration and the templates is dictated by the assumption that
the default provider of the alertmanager_remote_configuration
relation will be
alertmanager-k8s
charm, which requires such separation.
Methods
RemoteConfigurationRequirer. __init__( self , charm: CharmBase , relation_name: str )
API that manages a required remote-configuration
relation.
Arguments
The charm object that instantiated this class.
Name of the relation with the alertmanager_remote_configuration
interface as defined in metadata.yaml. Defaults to remote-configuration
.
RemoteConfigurationRequirer. config( self )
Exposes Alertmanager configuration sent inside the relation data bag.
Returns
Alertmanager configuration (dict) and templates (list)
Description
Charm which requires Alertmanager configuration, can access it like below:
def get_config(self, *args):
...
configuration, templates = self.remote_configuration.config()
...
self.container.push("/alertmanager/config/file.yml", configuration)
self.container.push("/alertmanager/templates/file.tmpl", templates)
...
class AlertmanagerConfigurationBrokenEvent
Description
Event emitted when configuration provided by the Provider charm is invalid. None
class AlertmanagerRemoteConfigurationProviderEvents
Description
Event descriptor for events raised by AlertmanagerRemoteConfigurationProvider
. None
class RemoteConfigurationProvider
API that manages a provided alertmanager_remote_configuration
relation.
Description
The RemoteConfigurationProvider
is intended to be used by charms that need to push data
to other charms over the alertmanager_remote_configuration
interface.
The RemoteConfigurationProvider
object can be instantiated as follows in your charm:
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import
RemoteConfigurationProvider,
)
def __init__(self, *args):
...
config = RemoteConfigurationProvider.load_config_file(FILE_PATH)
self.remote_configuration_provider = RemoteConfigurationProvider(
charm=self,
alertmanager_config=config,
)
...
Alternatively, RemoteConfigurationProvider can be instantiated using a factory, which allows using a configuration file path directly instead of a configuration string:
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import
RemoteConfigurationProvider,
)
def __init__(self, *args):
...
self.remote_configuration_provider = RemoteConfigurationProvider.with_config_file(
charm=self,
config_file=FILE_PATH,
)
...
The RemoteConfigurationProvider
assumes that, in the metadata.yaml
of your charm,
you declare a required relation as follows:
provides:
remote-configuration: # Relation name
interface: alertmanager_remote_configuration # Relation interface
The RemoteConfigurationProvider
provides handling of the most relevant charm
lifecycle events. On each of the defined Juju events, Alertmanager configuration and templates
from a specified file will be pushed to the relation data bag.
Inside the relation data bag, Alertmanager configuration will be stored under
alertmanager_configuration
key, while the templates under the alertmanager_templates
key.
Separation of the main configuration and the templates is dictated by the assumption that
the default provider of the alertmanager_remote_configuration
relation will be
alertmanager-k8s
charm, which requires such separation.
Methods
RemoteConfigurationProvider. __init__( self , charm: CharmBase , alertmanager_config , relation_name: str )
API that manages a provided remote-configuration
relation.
Arguments
The charm object that instantiated this class.
Alertmanager configuration dictionary.
Name of the relation with the alertmanager_remote_configuration
interface as defined in metadata.yaml. Defaults to remote-configuration
.
RemoteConfigurationProvider. with_config_file( cls , charm: CharmBase , config_file: str , relation_name: str )
The RemoteConfigurationProvider object factory.
Arguments
The charm object that instantiated this class.
Path to the Alertmanager configuration file.
Name of the relation with the alertmanager_remote_configuration
interface as defined in metadata.yaml. Defaults to remote-configuration
.
Returns
RemoteConfigurationProvider object
Description
This factory provides an alternative way of instantiating the RemoteConfigurationProvider. While the default constructor requires passing a config dict, the factory allows using a configuration file path.
RemoteConfigurationProvider. load_config_file( path: str )
Reads given Alertmanager configuration file and turns it into a dictionary.
Arguments
Path to the Alertmanager configuration file
Returns
Alertmanager configuration file in a form of a dictionary
RemoteConfigurationProvider. update_relation_data_bag( self , alertmanager_config )
Updates relation data bag with Alertmanager config and templates.
Arguments
Alertmanager configuration dictionary.
Description
Before updating relation data bag, basic sanity check of given configuration is done.