<% macro make_alert(mgroup, extensions, tags, warn_threshold, crit_threshold) -%>
    <% set alert_base = {
        "juggler_host": "salt_{mgroups[0]}_{ctype}_{geo}",
        "juggler_tags": [
            "auto_downtime",
            "salt"
        ],
        "juggler_base": {
            "namespace": "RTC",
            "aggregator": "logic_or",
            "aggregator_kwargs": {
                "nodata_mode": "force_crit"
            },
            "flaps": {
                "boost": 0,
                "critical": 0,
                "stable": 600
            }
        },
        "abc": "srertc",
        "mgroups": [mgroup],
        "warn": [warn_threshold, crit_threshold],
        "crit": [crit_threshold, None]
    } %>
    <<Alert(base=alert_base|combine(extensions), tags=tags)>>
<%- endmacro %>

<% set salt_fail_count = {
    "signal": "hsum(push-salt-fail-count_thhh)",
    "name_tmpl": "{mgroups[0]}_{ctype}_{geo}_fail_count",
    "juggler_service": "fail_count",
    "description_tmpl": "fail count {mgroups[0]} {geo} {ctype}"
} %>

<% set salt_failed_host_count = {
    "signal": "hcount(hmerge(push-salt-init-fail_thhh,push-salt-compile-fail_thhh,push-salt-execute-fail_thhh),0.66,inf)",
    "name_tmpl": "{mgroups[0]}_{ctype}_{geo}_failed_host_count",
    "juggler_service": "failed_host_count",
    "description_tmpl": "failed host count {mgroups[0]} {geo} {ctype}"
} %>

[
<% for tags in list_tags_combinations('runtimecloud', ctype=['production', 'prestable'], fill_tags=['geo', 'ctype']) %>
    <% if not tags['geo'] or tags['geo'] == 'none' %>
    <% elif tags['ctype'] == 'production' %>
    << make_alert('ASEARCH', salt_fail_count, tags, 15000, 20000) >>,
    << make_alert('ASEARCH', salt_failed_host_count, tags, 1000, 2000) >>,
    << make_alert('QLOUD', salt_fail_count, tags, 5000, 10000) >>,
    << make_alert('QLOUD', salt_failed_host_count, tags, 500, 1000) >>,
    <% else %>
    << make_alert('ASEARCH', salt_fail_count, tags, 50, 100) >>,
    << make_alert('ASEARCH', salt_failed_host_count, tags, 10, 20) >>,
    <% endif %>
<% endfor %>
]
