cgroup: "{{ host | default(omit) }}"
children: "CGROUP%{{ cgroup }}"
jcheck_mark: "{{ host }}"
def_crit_limit: 0
def_warn_limit: 0
def_unreach_crit: 0
def_unreach_night_crit: 1
cron_crit: 1
dns_crit: 1
group_checker_crit: 1
grub_crit: 1
hbf_agent_check_crit: "10%"
iptruler_crit: "10%"
logrotate_crit: "25%"
monitoring_alive_crit: "15%"
mtu_diff_crit: 0
network_load_crit: "30%"
oom_crit: "10%"
raid_crit: "0%"
ssh_crit: 1
ubic_restarts_crit: "5%"
unispace_crit: 1
watchdog_crit: "20%"

group_checker_night_crit: "25%"
grub_night_crit: "40%"
hbf_agent_check_night_crit: "70%"
iptruler_night_crit: "30%"
mtu_diff_night_crit: "101%"
oom_night_crit: "25%"
raid_night_crit: "20%"
ubic_restarts_night_crit: "30%"
watchdog_night_crit: "100%"

disk_env_production: "{{ production|default(False) or (not (testing|default(False)) and not (prestable|default(False)) and (host is defined and ('_test' not in host))) }}"
qloud_env_production: "{{ (qloud_env|default(None)) in qloud_production_envs or (qloud_app|default(None)) == 'balancer' or 'router' in (qloud_env|default('')) or 'balancer' in (qloud_env|default('')) }}"
yp_env_production: "{{ '-prod' in (yp_project|default('')) or '_stable' in (yp_project|default('')) or '-stable' in (yp_project|default('')) or '_prod' in (yp_project|default('')) }}"

default_tags:
  - disk
  - "{{ disk_env_production | ternary('production','not_production') }}"

disk_admin_resps:
 - robot-disk-duty-adm
 - yandex_mnt_person_mailservice_service

default_check:
  host: "{{ host | default(omit) }}"
  children: "{{ children }}"
  jcheck_mark: "{{ jcheck_mark }}"
  flap:
    stable: 120
    critical: 300
  aggregator: logic_or
  refresh_time: 300
  ttl: 900
  namespace: "{{ juggler_namespace | default('disk') }}"
  tags: "{{ (check_tags | default([])) + (host_tags | default([])) + default_tags }}"
  notifications: "{{ default_notifications | default((disk_env_production or qloud_env_production or yp_env_production) | ternary(PHONE_ESCALATION, [])) }}"

no_report:
  notifications: []

SMS:
  - template: "on_status_change"
    description: "СМС в полминуты"
    method:
      - sms
    status:
      - from: "OK"
        to: "CRIT"
      - from: "CRIT"
        to: "OK"
      - from: "CRIT"
        to: "WARN"
      - from: "WARN"
        to: "CRIT"
    min_interval: 30
    login: "{{ service_phone_escalation_logins | default(phone_escalation_logins | default(disk_admin_logins, true), true) }}"

SMS_CRIT_ONLY:
  - template: "on_status_change"
    description: "СМС в полминуты"
    method:
      - sms
    status:
      - CRIT
    min_interval: 30
    login: "{{ service_phone_escalation_logins | default(phone_escalation_logins | default(disk_admin_logins, true), true) }}"

DISK_JAVA_TELEGRAM:
  - template: "on_status_change"
    description: "Telegram Disk.Java"
    status:
      - to: CRIT
        from: OK
      - to: CRIT
        from: WARN
      - to: OK
        from: CRIT
      - to: WARN
        from: CRIT
    login:
      - DiskJava
    method:
      - telegram

disk_admin_logins:
  - robot-disk-duty-adm
  - robot-disk-duty-jun
  - ivanov-d-s
  - kolyann
  - vadzay
  - ignition

TELEGRAM_EVENTS_MIRROR:
  - template: "on_status_change"
    description: "Telegram mirror for robot-disk-duty-adm events"
    status:
      - to: CRIT
        from: OK
      - to: CRIT
        from: WARN
      - to: OK
        from: CRIT
      - to: WARN
        from: CRIT
    login:
      - robot-disk-duty-adm-events
    method:
      - telegram

_PHONE_ESCALATION:
  - template: "phone_escalation"
    description: "disk phone escalation"
    logins: "{{ service_phone_escalation_logins | default(phone_escalation_logins | default(disk_admin_logins, true), true) }}"
    delay: "{{ escalation_delay | default(900) }}"
    repeat: 100
    on_success_next_call_delay: "{{ escalation_next_call_delay | default(120) }}"

PHONE_ESCALATION: "{{ _PHONE_ESCALATION + (('robot-disk-duty-adm' in _PHONE_ESCALATION.0.logins) | ternary(TELEGRAM_EVENTS_MIRROR, [])) }}"

PHONE_ESCALATION_SMS: "{{ PHONE_ESCALATION + SMS }}"

qloud_platform: "qloud-ext"
qloud_project: "disk"

qloud_production_envs:
  corp-production: true
  corp-stable: true
  disk-notifier: true
  disk-support: true
  idm: true
  pg-stable: true
  preview-stable: true
  production-worker: true
  production: true
  stable-l: true
  stable-m: true
  stable-s: true
  stable: true
  video-stable: true
  zip-stable: true

default_qloud_tags:
  - disk
  - "{{ qloud_env_production | ternary('production','not_production') }}"
  - "{{ qloud_platform }}.{{ qloud_project }}"
  - "{{ qloud_platform }}.{{ qloud_project }}.{{ qloud_app }}"
  - "{{ qloud_platform }}.{{ qloud_project }}.{{ qloud_app }}.{{ qloud_env }}"

qloud_check:
  host: "{{ qloud_platform }}.{{ qloud_project}}.{{ qloud_app }}.{{ qloud_env }}.{{ qloud_component }}"
  children:
    - instance: ''
      host: "{{ qloud_project }}.{{ qloud_app }}.{{ qloud_env }}.{{ qloud_component }}@type=ext{{ (persistent_dns | default(False)) | ternary(';persistent=true', '') }}"
      type: QLOUD
      service: "{{ qloud_children_service }}"
  tags: "{{ (check_tags | default([])) + default_qloud_tags }}"
  meta:
    urls:
      - type: qloud
        url: "https://{{ qloud_platform }}.yandex-team.ru/projects/{{ qloud_project }}/{{ qloud_app }}/{{ qloud_env }}"

default_yp_tags:
  - disk
  - disk-deploy
  - "{{ yp_project.split('@')[0] | default(yp_project) }}"
  - "{{ yp_project.split('@stage=')[1].replace(';deploy_unit=', '.') | default(yp_project) }}"
  - "{{ yp_env_production | ternary('production','not_production') }}"


yp_check:
  host: "{{ yp_project.replace('@', '.').replace(';','.').replace('=','.') }}"
  tags: "{{ (check_tags | default([])) + default_yp_tags }}"
  children: "DEPLOY%{{ yp_project }}"
  meta:
    urls:
      - type: qloud
        title: "{{ yp_project }}"
        url: "https://deploy.yandex-team.ru/stage/{{ yp_project.split('@stage=')[1].split(';deploy_unit=')[0] | default(yp_project) }}"


mdb_check:
  meta:
    urls:
      - type: qloud
        title: "{{ mdb_database }}"
        url: "https://yc.yandex-team.ru/folders/{{ mdb_cloud }}/managed-postgresql/cluster/{{ host[3:] | replace('_', '-') }}"


mdb_mongodb_check:
  host: "mdb-{{ mdb_database }}"
  children: "CGROUP%{{ mdb_cluster_cgroup }}"
  meta:
    urls:
      - type: qloud
        title: "{{ mdb_database }}"
        url: "https://yc.yandex-team.ru/folders/{{ mdb_cloud }}/managed-mongodb/cluster/{{ host }}"


default_day_time_end: 20

custom_limits:
  aggregator: timed_more_than_limit_is_problem
  aggregator_kwargs:
    ignore_nodata: "{{ ignore_nodata | default('yes') }}"
    limits:
      - time_start: 11
        time_end: "{{ day_time_end | default(default_day_time_end) | int }}"
        day_start: 1
        day_end: 5
        crit: "{{ crit_limit | default(def_crit_limit) }}"
        warn: "{{ warn_limit | default(def_warn_limit) }}"
      - time_start: "{{ (day_time_end | default(default_day_time_end) | int) + 1 }}"
        time_end: 11
        day_start: 1
        day_end: 7
        crit: "{{ night_crit_limit | default(def_crit_limit) }}"
        warn: "{{ warn_limit | default(def_warn_limit) }}"
      - time_start: 11
        time_end: "{{ day_time_end | default(default_day_time_end) | int }}"
        day_start: 6
        day_end: 7
        crit: "{{ weekend_crit_limit | default(night_crit_limit | default(def_crit_limit)) }}"
        warn: "{{ warn_limit | default(def_warn_limit) }}"

self_unreach_check:
  - check: ":UNREACHABLE"

cloud_unreach_checks:
  - check: ":service-status"

stable_unreach_check:
  - check: "disk_stable_unreach:UNREACHABLE"

testing_unreach_check:
  - check: "disk_test_unreach:UNREACHABLE"

unreach_ok:
  aggregator_kwargs:
    unreach_mode: force_ok
    unreach_service: "{{ unreach_checks }}"

only_daytime:
  aggregator: timed_more_than_limit_is_problem
  aggregator_kwargs:
    ignore_nodata: "no"
    limits:
      - time_start: 11
        time_end: "{{ day_time_end | default(default_day_time_end) | int }}"
        day_start: 1
        day_end: 7
        crit: "{{ crit_limit | default(def_crit_limit) }}"
        warn: "{{ warn_limit | default(def_warn_limit) }}"
      - time_start: "{{ (day_time_end | default(default_day_time_end) | int) + 1 }}"
        time_end: 11
        day_start: 1
        day_end: 7
        crit: "146%"
        warn: "{{ warn_limit | default(def_warn_limit) }}"

warning:
  aggregator: timed_more_than_limit_is_problem
  aggregator_kwargs:
    ignore_nodata: "no"
    limits:
      - time_start: 0
        time_end: 23
        day_start: 1
        day_end: 7
        crit: "146%"
        warn: "{{ warn_limit | default(def_warn_limit) }}"

jserver_api: "http://juggler-api.search.yandex.net/api"
graphite_endpoint: "https://gr-mg.yandex-team.ru"
graphite_time_window: "-5min"
graphite_timeout: 20

iptruler: False
do_unreachable: True
always_warning: False

limit_flags_cond: "%(aw)s is defined and %(cow)s is not defined and %(od)s is not defined or
  %(aw)s is not defined and %(cow)s is defined and %(od)s is not defined or
  %(aw)s is not defined and %(cow)s is not defined and %(od)s is defined"

flags_assert_msg: "'always_warning', 'only_daytime': only one must be defined"

disk_dev_resps:
  - robot-disk-java-mntr
  - shirankov
  - akinfold
  - kis8ya
  - sanya2013
  - yak-dmitriy
  - friendlyevil
  - c4et4uk
  - derovi

disk_front_resps:
  - robot-disk-duty-ufo
  - chestnov
  - km256
  - kri0-gen
  - turbokuzmich
  - yanann11
  - dmi3rm

sync_resps:
  - stewie
  - yoprst
  - ntatarinov
