some tests and reformating

master
histausse 3 years ago
parent 2352626598
commit 8165f2b1c0
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -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<b><font color='red'>
{% elif alert['labels']['severity'] == 'warning' and alert['status'] == 'firing' %}
<b><font color='orange'>
{% elif alert['status'] == 'resolved' %}
<b><font color='green'> End of alert
{% else %}
<b><font>
{% endif %}
{{ alert['labels']['alertname'] }}: {{ alert['labels']['instance'] }} <br/>
</font></b>
{{ alert['annotations']['title'] }}<br/>
{{ alert['annotations']['description'] }}<br/>
But this is a custom template for Cassandre, so, here is a warning:<br/>
<blockquote>Beware of greeks bearing gifts</blockquote>
...

@ -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(

Loading…
Cancel
Save