|
|
|
@ -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<b><font color='red'>"
|
|
|
|
|
"{% elif alert['labels']['severity'] == 'warning' and alert['status'] == 'firing' %}"
|
|
|
|
@ -30,24 +35,19 @@ default_template_raw = (
|
|
|
|
|
"{{ alert['annotations']['description'] }}<br/>"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@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(
|
|
|
|
|