<% set destination = [
    "input",
    "output"
] %>

<% set datacenter = [
    "man",
    "sas",
    "vla",
    "msk"
] %>

<% set mgroups = [
    "ASEARCH",
    "QLOUD"
] %>

<% set limits = {
    "man": {
        "input": {
            "warn":[300000,1000000],
            "crit":[1000000,None]
        },
        "output": {
            "warn":[200000,800000],
            "crit":[800000,None]
        }
    },
    "sas": {
        "input": {
            "warn":[300000,1000000],
            "crit":[1000000,None]
        },
        "output": {
            "warn":[200000,1000000],
            "crit":[1000000,None]
        }
    },
    "vla": {
        "input": {
            "warn":[300000,1000000],
            "crit":[1000000,None]
        },
        "output": {
            "warn":[50000,500000],
            "crit":[500000,None]
        }
    },
    "msk": {
        "input": {
            "warn":[150000,500000],
            "crit":[500000,None]
        },
        "output": {
            "warn":[200000,500000],
            "crit":[500000,None]
        }
    }
} %>

<% set notifications = [
    {
        "template_name": "on_status_change",
        "template_kwargs": {
            "status": [
                "CRIT"
            ],
            "login": [
                "rtc-networking",
                "Runtime_Monitoring_HBF"
            ],
            "method": [
                "telegram"
            ]
        }
    }
] %>

[
<% for mgroup in mgroups %>
<% for dst in destination %>
<% for dc in datacenter %>

<% set service = "{}_hbf_drops_geowide_{}_{}".format(mgroup|lower(), dc, dst) %>
<% set yasm_name = "yasm_{}".format(service) %>
<% set signal_name = {
    "input": "hbf6-packets_drop_summ",
    "output": "hbf6-packets_output_reject_summ",
} %>

<% set base = {
    "name": yasm_name,
    "signal": signal_name[dst],
    "tags": {
        "itype": "runtimecloud",
        "geo": dc
    },
    "description": "{} {} {} drops".format(mgroup|upper(), dc|upper(), dst|upper()),
    "warn": limits[dc][dst]["warn"],
    "crit": limits[dc][dst]["crit"]
} %>

<% set common = {
    "mgroups": [mgroup]
} %>

<< Alert(
    base = base|merge_with_dict(common),
    juggler_check = {
        "namespace": "RTC",
        "host": yasm_name,
        "service": service,
        "notifications": notifications,
        "aggregator": "logic_or",
        "ttl": 900,
        "refresh_time": 5,
        "aggregator_kwargs": {
            "nodata_mode": "force_crit"
        },
        "tags": [
            "hbf",
            mgroup
        ],
        "flaps": {
            "critical": 0,
            "stable": 60,
            "boost": 0
        },
        "meta": {
            "urls": [
                {
                    "title": "Docs",
                    "url": "https://wiki.yandex-team.ru/runtime-cloud/yandex-hbf-agent/",
                    "type": "wiki"
                }
            ]
        }
    }
) >> ,

<% endfor %>
<% endfor %>
<% endfor %>
]

