<% set projects = fetch("https://api.wall-e.yandex-team.ru/v1/projects?tags=rtc,rtc.automation-enabled&fields=id", parse="json").result|map(attribute="id")|list %>
<% set prestable_project = "search-yt-testing" %>

<% set alert_base = {
    "juggler_tags": [
        "walle_automation",
    ],
    "juggler_base": {
        "namespace": "RTC",
        "aggregator": "logic_or",
        "aggregator_kwargs": {
            "nodata_mode": "force_crit"
        },
    },
    "mgroups": ["ASEARCH"]
} %>

<% set tags = {
    "itype": "wallecron",
    "ctype": "prod"
} %>



<% set enabled_plots = ["rtc", "rtc-gpu", "rtc-gpu-yati", "rtc-qyp", "rtc-incoming", "qloud"] %>
<% set plots = fetch("https://api.wall-e.yandex-team.ru/v1/automation-plot/?fields=id,checks", parse="json").result %>

[
<% for project in projects + [prestable_project] %>
    <% set project_url = "https://wall-e.yandex-team.ru/project/{}/".format(project) %>
    <% set tag_override = {} %>
    <% if project == prestable_project %>
        <% set tag_override = {"ctype": "test"} %>
        <% set project_url = "https://wall-e-test.yandex-team.ru/project/{}/".format(project) %>
    <% endif %>

    <% set juggler_meta = {
        "urls": [
            {
                "title": "Wall-E",
                "url": project_url,
                "type": "walle"
            }
        ]
    } %>
    <% set dns_automation = {
        "signal": "automation-project-{}-dns-automation-enabled_attt".format(project),
        "abc": "srertc",
        "name_tmpl": "{}_dns_automation".format(project),
        "juggler_host": project,
        "juggler_service": "dns_automation",
        "warn": [None, None],
        "crit": [0, 0],
        "description": "DNS automation status for project '{}'.".format(project),
        "juggler_base": {
            "meta": juggler_meta,
            "aggregator_kwargs": {
                "ok_desc": "DNS automation enabled in '{}' project.".format(project),
                "crit_desc": "DNS automation disabled in '{}' project.".format(project)
            }
        }
    } %>

    <% set healing_automation = {
        "signal": "automation-project-{}-healing-automation-enabled_attt".format(project),
        "abc": "srertc",
        "name_tmpl": "{}_healing_automation".format(project),
        "juggler_host": project,
        "juggler_service": "healing_automation",
        "warn": [None, None],
        "crit": [0, 0],
        "description": "Healing automation status for project '{}'.".format(project),
        "juggler_base": {
            "meta": juggler_meta,
            "aggregator_kwargs": {
                "ok_desc": "Healing automation enabled in '{}' project.".format(project),
                "crit_desc": "Healing automation disabled in '{}' project.".format(project)
            }
        }
    } %>

    << Alert(base=alert_base|combine(dns_automation), tags=tags|combine(tag_override)) >> ,
    << Alert(base=alert_base|combine(healing_automation), tags=tags|combine(tag_override)) >> ,
<% endfor %>

<% for plot in plots %>
    <% if plot.id in enabled_plots %>
        <% set juggler_meta = {
            "urls": [
                {
                    "title": "Wall-E",
                    "url": "https://wall-e.yandex-team.ru/automation-plots/{}".format(plot.id),
                    "type": "walle"
                }
            ]
        } %>
        <% for check in plot.checks %>
            <% set healing_automation = {
                "signal": "automation-automation-plot-{}-{}--healing-automation-enabled_attt".format(plot.id, check.name|replace("_", "-")),
                "abc": "srertc",
                "name_tmpl": "automation-plot_{}_{}_healing_automation".format(plot.id, check.name),
                "juggler_host": "automation-plot_{}_{}".format(plot.id, check.name),
                "juggler_service": "healing_automation",
                "warn": [None, None],
                "crit": [0, 0],
                "description": "Status of check '{}' in automation-plot '{}'.".format(check.name, plot.id),
                "juggler_base": {
                    "meta": juggler_meta,
                    "aggregator_kwargs": {
                        "ok_desc": "Check '{}' enabled in automation-plot '{}'.".format(check.name, plot.id),
                        "crit_desc": "Check '{}' disabled in automation-plot '{}'.".format(check.name, plot.id)
                    }
                }
            } %>
            << Alert(base=alert_base|combine(healing_automation), tags=tags) >> ,
        <% endfor %>
    <% endif %>
<% endfor %>

]
