diff --git a/config.yaml.exp b/config.yaml.exp index f91e69d..05209bd 100644 --- a/config.yaml.exp +++ b/config.yaml.exp @@ -7,4 +7,22 @@ host: 127.0.0.1 alert_rooms: - "#troy:matrix.org" - "#ithaca:matrix.org" +templates: + "Test": | + {% if alert['labels']['severity'] == 'critical' and alert['status'] == 'firing' %} + @room + {% elif alert['labels']['severity'] == 'warning' and alert['status'] == 'firing' %} + + {% elif alert['status'] == 'resolved' %} + End of alert + {% else %} + + {% endif %} + {{ alert['labels']['alertname'] }}: {{ alert['labels']['instance'] }}
+
+ {{ alert['annotations']['title'] }}
+ {{ alert['annotations']['description'] }}
+ + But this is a custom template for Cassandre, so, here is a warning:
+
Beware of greeks bearing gifts
... diff --git a/src/kassandra/format.py b/src/kassandra/format.py index 6305110..7a65d65 100644 --- a/src/kassandra/format.py +++ b/src/kassandra/format.py @@ -14,7 +14,12 @@ from typing import ( from jinja2 import BaseLoader, Environment, Template from .config import Config -default_template_raw = ( +@dataclasses.dataclass +class Message: + body: str + formated_body: Optional[str] + +DEFAULT_TEMPLATE_RAW: str = ( "{% if alert['labels']['severity'] == 'critical' and alert['status'] == 'firing' %}" "@room" "{% elif alert['labels']['severity'] == 'warning' and alert['status'] == 'firing' %}" @@ -30,24 +35,19 @@ default_template_raw = ( "{{ alert['annotations']['description'] }}
" ) -@dataclasses.dataclass -class Message: - body: str - formated_body: Optional[str] - def load_templates( config: Config )->defaultdict[str, Template]: """ Create a dict mapping alert names to the template to use from the config, with a default template either from the config file - or the default default_template_raw. + or the default DEFAULT_TEMPLATE_RAW. """ if config.default_template is None: default_template = Environment( loader=BaseLoader ).from_string( - default_template_raw + DEFAULT_TEMPLATE_RAW ) else: default_template = Environment(