Reference

lib_alert_tree

Library for creating and manipulating hierarchies of Prometheus alerts.

lib_alert_tree.__version__ = '0.1.0'

The version of this project.

lib_alert_tree.models

Classes for manipulating tree-like hierarchies of alerts.

class lib_alert_tree.models.BaseAlert

Base-class for alert models.

abstract property alert_rule

Generate a ‘prometheus.AlertRule’ corresponding to this model.

create_node(tree, parent=None)

Add this alert to a tree.

classmethod critical(name, **kwargs)

Helper to generate an alert with “critical” severity.

property json_path

A JSON Path filter to retrieve the alert represented by this model.

property pretty_str

A colored string (based on severity), if Click is available.

property query

A PromQL query to retrieve the alert represented by this model.

classmethod warning(name, **kwargs)

Helper to generate an alert with “warning” severity.

class lib_alert_tree.models.DerivedAlert(name, children, relationship, group_by=None, **params)

A non-leaf node (logical) in a tree of alerts.

This is a computed alert rule, which maps a list of weighted edges towards other nodes (leaves or not) with a single alert.

In practice, one can fully build up a tree using a DerivedAlert instance as the root, using the build_tree method.

property alert_rule

Generate a ‘prometheus.AlertRule’ corresponding to this model.

build_rules_group(name)

Build a ‘prometheus.RulesGroup’ from all linked DerivedAlerts.

build_tree(parent=None, tree=None)

Build a ‘treelib.Tree’ object by recursing through children.

class lib_alert_tree.models.ExistingAlert(name, severity=None, **labels)

A leaf in a tree of logical alerts.

In essence, this represents an already existing alert rule in some Prometheus configuration, from which we will build composition rules. It only stores a name and a sufficient set of labels for querying.

property alert_rule

Generate a ‘prometheus.AlertRule’ corresponding to this model.

class lib_alert_tree.models.Relationship(value)

The type of relationship a parent has towards its children.

static build_json_path(children, group_by=None)

Build a JSON Path to retrieve alert children.

build_query(children, group_by=None)

Build a query to derive an alert rule from its children.

lib_alert_tree.models.severity_pair(name, summary_name=None, summary_plural=False, warning_children=None, critical_children=None, **kwargs)

Generate a pair of DerivedAlerts with ‘warning’ and ‘critical’ severity.

lib_alert_tree.prometheus

Classes for storing and serializing Prometheus alert rules.

class lib_alert_tree.prometheus.AlertRule(name, expr=None, duration=None, annotations=None, labels=None, severity=None, summary=None)

A single alerting rule.

property child_id

A short representation of this alert, for use in annotations.

property child_json_path

A JSONPath filter expression for selecting this alert as a child.

This expression will be combined into a full JSONPath query for retrieving all children of a derived alert, exposed in an annotation for consumption by clients (such as UIs).

format_labels(**updates)

Format labels (and optional updates) as a string.

labels_to_json_path_filters(**updates)

Build JSON Path filters matching the labels.

property query

The PromQL query for selecting this alert.

serialize()

Serialize this data container into a dict.

class lib_alert_tree.prometheus.PrometheusRule(name, namespace, labels=None, groups=None)

A complete PrometheusRule custom resource.

serialize()

Serialize this data container into a dict.

class lib_alert_tree.prometheus.RulesGroup(name, rules=None)

A group of alerting rules.

serialize()

Serialize this data container into a dict.

class lib_alert_tree.prometheus.Serializable

Base-class for data serializable into YAML strings.

dump(out=None)

Dump the serialized data in YAML format.

abstract serialize()

Serialize this data container into a dict.

lib_alert_tree.kubernetes

Helpers for defining lists of alerts on usual Kubernetes objects.

lib_alert_tree.kubernetes.daemonset_alerts(name, severity='warning', namespace='default')

Common alerts for DaemonSets.

lib_alert_tree.kubernetes.deployment_alerts(name, severity='warning', namespace='default')

Common alerts for Deployments.

lib_alert_tree.kubernetes.job_alerts(name, severity='warning', namespace='default')

Common alerts for Jobs.

lib_alert_tree.kubernetes.pod_alerts(name, severity='warning', namespace='default')

Common alerts for Pods.

lib_alert_tree.kubernetes.statefulset_alerts(name, severity='warning', namespace='default')

Common alerts for StatefulSets.

lib_alert_tree.cli

Generate a Click command-line interface from alert trees.

lib_alert_tree.cli.generate_cli(roots, prometheus_rule_labels=None)

Generate a CLI from a dict of root alerts (keys are used for root selection).