본문 바로가기
WIKI 기술 지식 베이스

변수

원문 보기 위키 갱신

변수 (Variables)

알림 메시지에서 변수를 사용해 조건부 메시지를 표시하고 조건부 변수로 다른 팀에 알림을 라우팅하거나, 속성·태그 변수와 템플릿 변수를 사용해 콘텐츠를 풍부하게 만들 수 있어요.

출처: 문서

본문

조건부 변수 (Conditional variables)

조건부 변수는 if-else 로직을 사용해 모니터의 상태와 트리거된 방식의 세부 내용에 따라 다른 메시지를 표시해요. 이 변수들은 알림 메시지의 제목(subject)이나 본문(body)에서 사용할 수 있어요.

다음 조건부 변수를 사용할 수 있어요:

조건부 변수 (Conditional Variable) 다음 경우에 텍스트가 표시됨 (The text is displayed if)
{{#is_alert}} 모니터가 경보를 발생시킴 (The monitor alerts)
{{^is_alert}} 모니터가 경보를 발생시키지 않음
{{#is_match}} 컨텍스트가 제공된 하위 문자열과 일치함. 숫자 값이 사용되면 문자열로 변환됨.
{{^is_match}} 컨텍스트가 제공된 하위 문자열과 일치하지 않음
{{#is_exact_match}} 컨텍스트가 제공된 문자열과 정확히 일치함. 숫자가 사용되면 유형과 관계없이 숫자 값이 고려됨. 즉 두 숫자가 같은 값을 가진다면 함수는 이를 같다고 간주함.
{{^is_exact_match}} 컨텍스트가 제공된 문자열과 정확히 일치하지 않음
{{#is_no_data}} 데이터 누락으로 모니터가 트리거됨
{{^is_no_data}} 데이터 누락으로 모니터가 트리거되지 않음
{{#is_warning}} 모니터가 경고(warns)를 발생시킴
{{^is_warning}} 모니터가 경고를 발생시키지 않음
{{#is_recovery}} 모니터가 ALERT, WARNING, UNKNOWN, 또는 NO DATA에서 복구됨
{{^is_recovery}} 모니터가 ALERT, WARNING, UNKNOWN, 또는 NO DATA에서 복구되지 않음
{{#is_warning_recovery}} 모니터가 WARNING에서 OK로 복구됨
{{^is_warning_recovery}} 모니터가 WARNING에서 OK로 복구되지 않음
{{#is_alert_recovery}} 모니터가 ALERT에서 OK로 복구됨참고: ALERT에서 WARNING으로의 전환에서는 {{#is_alert_recovery}} 수신자가 메시지 본문 없이 알림을 받음. 메시지를 포함하려면 {{#is_alert_to_warning}}을 사용할 것
{{^is_alert_recovery}} 모니터가 ALERT에서 OK로 복구되지 않음
{{#is_alert_to_warning}} 모니터가 ALERT에서 WARNING으로 전환됨
{{^is_alert_to_warning}} 모니터가 ALERT에서 WARNING으로 전환되지 않음
{{#is_no_data_recovery}} 모니터가 NO DATA에서 복구됨
{{^is_no_data_recovery}} 모니터가 NO DATA에서 복구되지 않음
{{#is_priority 'value'}} 모니터의 우선순위가 value임. 값은 P1부터 P5까지.
{{#is_unknown}} 모니터가 unknown 상태임
{{^is_unknown}} 모니터가 unknown 상태가 아님
{{#is_renotify}} 모니터가 재알림 중임
{{^is_renotify}} 모니터가 재알림 중이 아님.

예시 (Examples)

조건부 변수는 텍스트와 @-알림을 사이에 둔 여는-닫는 쌍이 있어야 해요. is_alert나 is_warning 같은 모니터 상태 기반 변수는 자신만의 메시지 블록을 가져야 해요. 모니터는 동시에 하나의 상태만 될 수 있으므로 이것들을 결합할 수 없어요. 하지만 속성에 대해 일치하는 조건부를 중첩할 수는 있어요. is_renotify 예시를 참고하세요.

{% tab title="is_alert" %} 모니터가 경보를 발생시킬 때 알림 메시지를 보내려면 다음 형식을 사용해요:

{{#is_alert}}
  <ALERT_MESSAGE_TEXT> <@-NOTIFICATION>
{{/is_alert}}

{% /tab %}

{% tab title="is_warning" %} 모니터가 경고를 발생시킬 때 알림 메시지를 보내려면 다음 형식을 사용해요:

{{#is_warning}}
  <WARNING_MESSAGE_TEXT> <@-NOTIFICATION>
{{/is_warning}}

{% /tab %}

{% tab title="is_recovery" %} 모니터가 복구될 때 알림 메시지를 보내려면 다음 형식을 사용해요:

{{#is_recovery}}
  <RECOVERY_MESSAGE_TEXT> <@-NOTIFICATION>
{{/is_recovery}}

{% /tab %}

{% tab title="is_match" %} 태그 변수에서 하위 문자열을 검색하려면 다음 형식을 사용해요:

{{#is_match "<TAG_VARIABLE>.name" "<COMPARISON_STRING>"}}
  This displays if <COMPARISON_STRING> is included in <TAG_VARIABLE>.
{{/is_match}}

트리거한 호스트에 role:db_cassandra 또는 role:db_postgres 태그가 있다면 DB 팀에 알리려면 다음을 사용해요:

{{#is_match "host.role.name" "db"}}
  This displays if the host triggering the alert contains `db`
  in the role name. @[email protected]
{{/is_match}}

is_match 조건은 여러 문자열 일치도 지원해요:

{{#is_match "host.role.name" "db" "database"}}
  This displays if the host triggering the alert contains `db` or `database`
  in the role name. @[email protected]
{{/is_match}}

태그가 db를 포함하지 않으면 다른 알림을 보내려면 다음과 같이 조건의 부정(negation)을 사용해요:

{{^is_match "host.role.name" "db"}}
  This displays if the role tag doesn't contain `db`.
  @slack-example
{{/is_match}}

또는 첫 번째 예시에서 {{else}} 매개변수를 사용해요:

{{#is_match "host.role.name" "db"}}
  This displays if the host triggering the alert contains `db`
  in the role name. @[email protected]
{{else}}
  This displays if the role tag doesn't contain `db`.
  @slack-example
{{/is_match}}

참고: <TAG_VARIABLE>이 존재하지 않거나 비어 있는지 확인하려면 is_exact_match를 사용해요. 자세한 내용은 is_exact_match 탭을 참고하세요. {% /tab %}

{% tab title="is_exact_match" %} 태그 변수에서 정확한 문자열을 검색하려면 다음 형식을 사용해요:

{{#is_exact_match "<TAG_VARIABLE>.name" "<COMPARISON_STRING>"}}
  This displays if <COMPARISON_STRING> is exactly <TAG_VARIABLE>.
{{/is_exact_match}}

트리거한 호스트 이름이 production이면 dev 팀에 알리려면 다음을 사용해요:

{{#is_exact_match "host.name" "production"}}
  This displays if the host that triggered the alert is exactly
  named production. @[email protected]
{{/is_exact_match}}

is_exact_match 조건은 여러 문자열 일치도 지원해요:

{{#is_exact_match "host.name" "production" "staging"}}
  This displays if the host that triggered the alert is exactly
  named production or staging. @[email protected]
{{/is_exact_match}}

is_exact_match 조건부 변수는 {{value}} 템플릿 변수도 지원해요:

{{#is_exact_match "value" "<VALUE>"}}
  This displays if the value that breached the threshold of the monitor is exactly <VALUE>.
{{/is_exact_match}}

모니터의 임계값을 위반한 값이 5(또는 5.0)이면 dev 팀에 알리려면 다음을 사용해요:

{{#is_exact_match "value" "5"}}
  This displays if the value that breached the threshold of the monitor is 5. @[email protected]
{{/is_exact_match}}

is_exact_match 조건부 변수는 <COMPARISON_STRING>에 빈 문자열을 지원해 속성이나 태그가 비어 있거나 존재하지 않는지 확인할 수 있어요.

{{#is_exact_match "host.datacenter" ""}}
  This displays if the attribute or tag does not exist or if it's empty
{{/is_exact_match}}

{% /tab %}

{% tab title="is_renotify" %} production 환경에 대해서만 다른 대상으로 에스컬레이션 메시지를 보내려면:

{{#is_renotify}}
{{#is_match "env" "production"}}
  This is an escalation message sent to @[email protected]
{{/is_match}}
{{/is_renotify}}

원래 메시지 세부 내용을 포함하지 않는 다른 에스컬레이션 메시지를 보내려면 {{^is_renotify}}와 {{#is_renotify}} 블록을 조합해 사용해요:

{{^is_renotify}}
This monitor is alerting and sending a first message @[email protected]

To solve this monitor follow the steps:
1. Go there
2. Do this
{{/is_renotify}}

This part is generic and sent both for the first trigger and the escalation message.

{{#is_renotify}}
  This is the escalation message @[email protected]
{{/is_renotify}}

모니터 재알림 시 사용자는 다음 에스컬레이션 메시지를 받게 돼요:

This part is generic and sent both for the first trigger and the escalation message.

This is the escalation message @[email protected]

{% /tab %}

alert 또는 warning 조건으로의 상태 전환에 @-알림 핸들과 함께 조건부 블록을 구성한다면, 해당 핸들에 복구 알림을 보내도록 대응하는 recovery 조건도 구성할 것을 Datadog는 권장해요.

참고: 구성된 조건부 변수 밖에 배치된 텍스트나 알림 핸들은 모든 모니터 상태 전환에서 호출돼요. 구성된 조건부 변수 안에 배치된 텍스트나 알림 핸들은 모니터 상태 전환이 그 조건과 일치할 때만 호출돼요.

속성 및 태그 변수 (Attribute and tag variables)

속성 및 태그 변수를 사용해 커스터마이즈되고 유익하며 특정한 경보 메시지를 렌더링해 경보의 성격을 이해하는 데 도움을 줄 수 있어요. 예시와 사용 사례는 다음 섹션을 참고하세요:

  • Multi alert variables
  • Matching attribute/tag variables

{% dl %}

{% dt %} 태그 (Tags) {% /dt %}

{% dd %} 자동으로 첨부되거나(호스트 이름, 컨테이너 이름, 로그 파일 이름, 서버리스 함수 이름), 커스텀 태그로 추가된다(담당 팀, 환경, 애플리케이션, 버전). {% /dd %}

{% dt %} 속성 (Attributes) {% /dt %}

{% dd %} 로그 콘텐츠를 기반으로 파싱되거나 참조 테이블(예: geoip)의 조회로 추가된다. {% /dd %}

{% /dl %}

참고: 모니터가 no-data 조건에서 복구하도록 구성된 경우(예: 쿼리와 일치하는 이벤트가 없을 때), 복구 메시지에는 어떤 데이터도 포함되지 않아요. 복구 메시지에 정보를 유지하려면 {{tag.name}}으로 접근할 수 있는 추가 태그로 그룹화하세요.

멀티 알림 변수 (Multi alert variables)

멀티 알림 모니터 (multi alert monitors)에서 멀티 알림 그룹 상자에 선택된 차원에 따라 멀티 알림 변수를 구성해요. 각 경보에 그룹별 차원과 연결된 값을 동적으로 포함해 알림을 풍부하게 만들어요.

참고: 집계에 group_by 필드를 사용하면 모니터의 추가 태그와 경보가 자동으로 상속될 수 있어요. 따라서 모니터링되는 엔드포인트에 설정된 경보나 구성이 집계로 인해 생성된 각 그룹에 적용될 수 있어요. 예약된 태그 키 (Reserved tag keys)는 예외예요. 선택된 그룹별 차원과 관계없이 모든 경보에서 사용할 수 있어요.

{% tab title="Group by tag" %} 메트릭에 key:value 형식의 태그가 있고 모니터 쿼리가 이 태그로 그룹화되어 있다면, 다음 변수를 사용해요:

{{ key.name }}

이 변수는 key와 연결된 value를 각 경보 알림에 삽입해요. 예를 들어 모니터가 각 env에 대해 경보를 트리거한다면, 알림 메시지에서 {{env.name}} 변수를 사용할 수 있어요.

그룹이 같은 key와 연결된 여러 value를 가진다면, 경보 메시지는 모든 값을 사전순(lexicographic order)으로 콤마로 구분된 문자열로 표시해요.

마침표가 있는 태그 키 (Tag key with period)

태그의 키에 마침표가 있다면, 태그 변수를 사용할 때 전체 키에 대괄호를 포함하세요. 예를 들어 태그가 dot.key.test:five이고 모니터가 dot.key.test로 그룹화되어 있다면 다음을 사용해요:

{{[dot.key.test].name}}

{% /tab %}

{% tab title="Group by facet" %} Log 모니터, Trace Analytics 모니터, RUM 모니터, Event 모니터는 모니터가 facet으로 그룹화되어 있다면 facet을 변수로 사용할 수 있어요. 로그 모니터가 @facet_key로 그룹화되어 있다면 다음 변수를 사용해요:

{{ @facet_key.name }}

예시: 멀티 알림 로그 모니터를 @machine_id로 그룹화해 그룹별 정보를 포함하려면:

This alert was triggered on {{ @machine_id.name }}

facet에 마침표가 있다면 facet 주위에 대괄호를 사용해요. 예를 들어:

{{ [@network.client.ip].name }}

{% /tab %}

그룹에 따라 알림 커스터마이징하기 (Customize the notification based on the group)

쿼리가 특정 차원으로 그룹화되어 있다면, 그룹과 연결된 동적 메타데이터로 알림을 풍부하게 만들 수 있어요. 태그 선택에 기반한 태그 변수 목록을 보려면 Configure notifications & automations 섹션에서 Use message template variables를 클릭해요. 다음 예시를 참고하세요:

{% collapsible-section %}

Query group by host

모니터가 각 host에 대해 경보를 트리거한다면, {{host.name}}과 {{host.ip}} 태그 변수와 이 호스트에서 사용 가능한 모든 호스트 태그를 사용할 수 있어요.

특정 호스트 메타데이터 변수:

  • Agent Version: {{host.metadata_agent_version}}

  • Machine: {{host.metadata_machine}}

  • Platform: {{host.metadata_platform}}

  • Processor: {{host.metadata_processor}}

{% /collapsible-section %}

{% collapsible-section %}

Query group by kube_namespace and kube_cluster_name

모니터가 각 kube_namespace와 kube_cluster_name에 대해 경보를 트리거한다면, namespace의 모든 속성에 접근할 수 있어요.

Namespace 메타데이터 변수:

  • Cluster name: {{kube_namespace.cluster_name}}
  • Namespace name: {{kube_namespace.display_name}}
  • Namespace status: {{kube_namespace.status}}
  • Namespace labels: {{kube_namespace.labels}}

다음 테이블에는 사용 가능한 모든 속성이 포함돼요:

변수 구문 (Variable syntax) 1단계 속성 (First level attributes)
{{kube_namespace.key}} k8s_namespace_key, tags, annotations, cluster_id, cluster_name, creation_timestamp, deletion_timestamp, display_name, external_id, finalizers, first_seen_at, group_size, labels, name, namespace, status, uid

{% /collapsible-section %}

{% collapsible-section %}

Query group by pod_name and kube_namespace and kube_cluster_name

모니터가 각 pod_name, kube_namespace, kube_cluster_name에 대해 경보를 트리거한다면, pod의 모든 속성에 접근할 수 있어요.

Pod 메타데이터 변수:

  • Cluster name: {{pod_name.cluster_name}}
  • Pod name: {{pod_name.name}}
  • Pod phase: {{pod_name.phase}}

다음 테이블에는 사용 가능한 모든 속성이 포함돼요:

변수 구문 (Variable syntax) 1단계 속성 (First level attributes)
{{pod_name.key}} k8s_pod_key, tags, annotations, cluster_id, cluster_name, conditions, container_statuses, creation_timestamp, deletion_timestamp, display_name, external_id, finalizers, first_seen_at, host_id, host_key, hostname, init_container_statuses, ip, labels, name, namespace, node_name, nominated_node_name, phase, pod_scheduled_timestamp, priority_class_name, qosclass, resource_requirements, uid

{% /collapsible-section %}

{% collapsible-section %}

Query group by service

모니터가 각 service에 대해 경보를 트리거한다면, Catalog에 정의된 대로 서비스의 일부 속성에 접근할 수 있어요.

Service 메타데이터 변수:

  • Service name: {{service.name}}
  • Team name: {{service.team}}
  • Docs: {{service.docs}}
  • Links: {{service.links}}

Docs와 Links에는 다음 구문 [<name>]으로 특정 항목에도 접근할 수 있어요. 예를 들어, 이 예시에 정의된 것과 같은 정의 스키마를 가진 서비스의 경우, 다음 구문으로 "Runbook" 링크에 접근할 수 있어요

{{service.links[Runbook]}}

{% /collapsible-section %}

{% collapsible-section %}

Query group by device_ip and device_namespace

모니터가 각 device_ip와 device_namespace에 대해 경보를 트리거한다면, 네트워크 디바이스의 모든 속성에 접근할 수 있어요.

네트워크 디바이스 메타데이터 변수:

  • Canonical ID: {{network_device.canonical_id}}

  • Description: {{network_device.description}}

  • Device type: {{network_device.device_type}}

  • Device ID: {{network_device.device_id}}

  • ID tags: {{network_device.id_tags}}

  • Integrations: {{network_device.integrations}}

  • IP address: {{network_device.ip_address}}

  • location: {{network_device.location}}

  • model: {{network_device.model}}

  • name: {{network_device.name}}

  • namespace: {{network_device.namespace}}

  • OS hostname: {{network_device.os_hostname}}

  • OS name: {{network_device.os_name}}

  • OS version: {{network_device.os_version}}

  • Ping status: {{network_device.ping_status}}

  • Product name: {{network_device.product_name}}

  • Profile: {{network_device.profile}}

  • Serial number: {{network_device.serial_number}}

  • Status: {{network_device.status}}

  • Subnet: {{network_device.subnet}}

  • Sys object ID: {{network_device.sys_object_id}}

  • Tags: {{network_device.tags}}

  • Vendor: {{network_device.vendor}}

  • Version: {{network_device.version}}

{% /collapsible-section %}

일치하는 속성/태그 변수 (Matching attribute/tag variables)

모니터 쿼리와 일치하는 로그, 트레이스 스팬(trace span), RUM 이벤트, CI 파이프라인, CI 테스트 이벤트의 모든 속성이나 태그를 포함할 수 있어요. 다음 테이블은 다양한 모니터 유형에서 추가할 수 있는 속성과 변수의 예시를 보여줘요.

{% alert level="info" %} 모니터에서 사용 가능한 변수의 전체 목록을 보려면 알림 구성 하단에서 {{ Add Variable을 클릭하고 확장된 메뉴 옵션에서 선택하세요. {% /alert %}

모니터 유형 (Monitor type) 변수 구문 (Variable syntax)
Audit Trail {{audit.attributes.key}} 또는 {{audit.message}}
CI Pipeline {{cipipeline.attributes.key}}
CI Test {{citest.attributes.key}}
Database Monitoring {{databasemonitoring.attributes.key}}
Error Tracking {{issue.attributes.key}}
Log {{log.attributes.key}} 또는 {{log.tags.key}}
RUM {{rum.attributes.key}} 또는 {{rum.tags.key}}
Synthetic Monitoring {{synthetics.attributes.key}}
Trace Analytics {{span.attributes.key}} 또는 {{span.tags.key}}

{% collapsible-section %}

구문 사용 예시 (Example syntax usage)

{% /collapsible-section %}

중요 참고 사항 (Important notes)
  • 선택된 이벤트에 속성이나 태그 키가 포함되어 있지 않다면, 변수는 알림 메시지에서 비어 있게 렌더링돼요. 알림 누락을 방지하려면 {{#is_match}} 핸들로 알림을 라우팅할 때 이런 변수를 사용하지 마세요.
  • Formulas & Functions를 사용하는 쿼리의 모니터에서는 첫 번째 쿼리에서 추출된 이벤트를 기준으로 값이 해석돼요.
예약된 속성 (Reserved attributes)

Logs, Event Management, spans, RUM, CI Pipeline, CI Test 이벤트에는 일반적인 예약 속성이 있어요. 다음 구문으로 변수에서 사용할 수 있어요:

모니터 유형 (Monitor type) 변수 구문 (Variable syntax) 1단계 속성 (First level attributes)
Log {{log.key}} message, service, status, source, span_id, timestamp, trace_id, link, host
Trace Analytics {{span.key}} env, operation_name, resource_name, service, status, span_id, timestamp, trace_id, type, link
RUM {{rum.key}} service, status, timestamp, link
Event {{event.key}} attributes, host.name, id, link, title, text, tags
CI Pipeline {{cipipeline.key}} service, env, resource_name, ci_level, trace_id, span_id, pipeline_fingerprint, operation_name, ci_partial_array, status, timestamp, link
CI Test {{citest.key}} service, env, resource_name, trace_id, span_id, operation_name, status, timestamp, link

일치하는 이벤트가 정의에 해당 속성을 포함하지 않으면 변수는 비어 있게 렌더링돼요.

{{log.link}}, {{span.link}}, {{rum.link}}, {{issue.link}}을 사용해 쿼리와 일치하는 이벤트로 범위가 지정된 Log Explorer, Trace Explorer, RUM Explorer, Error Tracking 링크로 알림을 풍부하게 만들 수 있어요.

체크 모니터 변수 (Check monitor variables)

체크 모니터 변수(커스텀 체크와 통합 체크)의 경우 {{check_message}} 변수를 사용할 수 있고, 커스텀 체크나 통합 체크에 지정된 메시지를 렌더링해요.

복합 모니터 변수 (Composite monitor variables)

복합 모니터(Composite monitors)는 경보가 트리거되는 시점의 하위 모니터와 연결된 값과 상태에 접근할 수 있어요.

예를 들어 복합 모니터에 하위 모니터 a가 있다면, 다음으로 a의 값을 포함할 수 있어요:

{{ a.value }}

하위 모니터 a의 상태를 검색하려면 다음을 사용해요:

{{ a.status }}

상태의 가능한 값은 OK, Alert, Warn, No Data예요.

복합 모니터는 기반 모니터와 같은 방식으로 태그 변수도 지원해요. 기반 모니터가 같은 태그나 facet으로 그룹화되어 있다면 다른 모니터와 같은 형식을 따르지고 해요.

예를 들어, 복합 모니터에 Logs 모니터인 하위 모니터 a가 있다고 가정해요. 다음으로 a의 모든 태그나 facet의 값을 포함할 수 있어요:

{{ a.log.message }} or {{ a.log.my_facet }}

문자 이스케이프 (Character escape)

변수 콘텐츠는 기본적으로 HTML로 인코딩돼요. 원시(인코딩되지 않은) 콘텐츠를 출력하려면 이중 중괄호 대신 삼중 중괄호를 사용해요.

예를 들어 변수의 값이 쿼리 매개변수가 있는 URL을 포함할 때, 이중 중괄호를 사용하느냐 삼중 중괄호를 사용하느냐에 따라 &가 다르게 처리돼요:

구문 (Syntax) 출력 예시 (Example output)
{{template_variable}} (double braces) https://status.example.com/check?service=web&amp;region=us-east
{{{template_variable}}} (triple braces) https://status.example.com/check?service=web&region=us-east
구문 (Syntax) 출력 (Output)
{{variable}} HTML 인코딩됨 (기본값)
{{{variable}}} 원시, 인코딩되지 않음

예를 들어 체크 메시지를 HTML 인코딩 없이 렌더링하려면:

{{{check_message}}}

이는 {{check_message}}에 쿼리 매개변수가 있는 자동 생성 URL이 포함될 때 특히 관련돼요(예: HTTP Check 모니터). 그 URL의 & 문자는 기본적으로 HTML로 인코딩되므로 알림의 클릭 가능한 링크가 깨질 수 있어요. URL을 그대로 보존하려면 {{{check_message}}}를 사용하세요.

템플릿 변수 (Template variables)

템플릿 변수를 사용해 모니터 알림을 커스터마이징할 수 있어요. 내장 변수는 다음과 같아요:

변수 (Variable) 설명 (Description)
{{value}} 메트릭 기반 쿼리 모니터에서 경보를 위반한 값.
{{threshold}} 모니터 경보 조건에 설정된 경보 임계값.
{{warn_threshold}} 모니터 경보 조건에 설정된 경고 임계값.
{{alert_recovery_threshold}} 모니터를 ALERT 상태에서 복구시킨 값.
{{warn_recovery_threshold}} 모니터를 WARN 상태에서 복구시킨 값.
{{ok_threshold}} Service Check 모니터를 복구시킨 값.
{{comparator}} 모니터 경보 조건에 설정된 관계형 값.
{{first_triggered_at}}아래 섹션 참고 모니터가 처음 트리거된 UTC 날짜와 시간.
{{first_triggered_at_epoch}}아래 섹션 참고 모니터가 처음 트리거된 UTC 날짜와 시간(epoch 밀리초).
{{last_triggered_at}}아래 섹션 참고 모니터가 마지막으로 트리거된 UTC 날짜와 시간.
{{last_triggered_at_epoch}}아래 섹션 참고 모니터가 마지막으로 트리거된 UTC 날짜와 시간(epoch 밀리초).
{{triggered_duration_sec}} 모니터가 트리거된 상태에 있었던 초 수.

트리거 변수 (Triggered variables)

{{first_triggered_at}}, {{first_triggered_at_epoch}}, {{last_triggered_at}}, {{last_triggered_at_epoch}} 모니터 템플릿 변수는 모니터가 상태를 변경할 때의 값을 반영해요. 새 모니터 이벤트가 발생할 때가 아니라는 점에 주의하세요. 재알림 이벤트는 모니터 상태가 변경되지 않았다면 같은 템플릿 변수를 표시해요. {{triggered_duration_sec}}을 사용해 모니터 이벤트 시점의 지속 시간을 표시하세요.

{{first_triggered_at}}은 모니터 그룹이 OK에서 OK가 아닌 상태로 전환될 때, 또는 새 그룹이 OK가 아닌 상태로 나타날 때 설정돼요. {{last_triggered_at}}은 모니터 그룹이 이전 상태와 무관하게 OK가 아닌 상태로 전환될 때 설정돼요(WARN → ALERT, ALERT → WARN 포함). 또한 {{last_triggered_at}}은 새 그룹이 OK가 아닌 상태로 나타날 때도 설정돼요. 차이점은 {{last_triggered_at}}은 이전 상태와 무관하다는 점이에요.

{% image source="https://docs.dd-static.net/images/monitors/notifications/triggered_variables.003e427cd4c91c72ffdcabd55119573e.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/monitors/notifications/triggered_variables.003e427cd4c91c72ffdcabd55119573e.png?auto=format&fit=max&w=850&dpr=2 2x" alt="Showing four transitions with timestamps A: 1419 OK to WARN, B: 1427 WARN to ALERT, C: 1445 ALERT to NO DATA, D: 1449 NO DATA to OK" /%}

예시: 모니터가 OK → WARN으로 전환될 때 {{first_triggered_at}}와 {{last_triggered_at}}의 값은 모두 타임스탬프 A를 가져요. 아래 테이블은 모니터가 복구될 때까지의 값을 보여줘요.

전환 (Transition) first_triggered_at last_triggered_at triggered_duration_sec
OK → WARN A A 0
WARN → ALERT A B B - A
ALERT → NO DATA A C C - A
NO DATA → OK A C D - A

평가 (Evaluation)

숫자 값을 반환하는 템플릿 변수는 연산과 함수를 지원해요. 이를 통해 값에 수학 연산을 수행하거나 형식을 변경할 수 있어요. 전체적인 자세한 내용은 템플릿 변수 평가 (Template Variable Evaluation)을 참고하세요.

현지 시간 (Local time)

local_time 함수를 사용해 원하는 시간대의 다른 날짜를 알림에 추가할 수 있어요. 이 함수는 날짜를 현지 시간으로 변환해요: {{local_time 'time_variable' 'timezone'}}. 예를 들어 알림에 도쿄 시간대의 모니터 마지막 트리거 시간을 추가하려면 알림 메시지에 다음을 포함하세요:

{{local_time 'last_triggered_at' 'Asia/Tokyo'}}

결과는 ISO 8601 형식으로 표시돼요: yyyy-MM-dd HH:mm:ss±HH:mm. 예를 들어 2021-05-31 23:43:27+09:00처럼요. 사용 가능한 시간대 값 목록은 tz 데이터베이스 시간대 목록, 특히 TZ database name 열을 참고하세요.

고급 (Advanced)

동적 핸들 (Dynamic handles)

태그 변수를 사용해 알림 핸들을 동적으로 구성하고, 모니터가 감지한 문제 유형에 따라 알림을 올바른 팀이나 서비스로 라우팅할 수 있어요.

예시: 모니터가 메트릭을 쿼리하고 service 태그로 그룹화한다면, 실패하는 서비스에 따라 다른 Slack 채널로 알림을 라우팅할 수 있어요:

@slack-{{service.name}} There is an ongoing issue with {{service.name}}.

모니터가 service:ad-server 그룹에서 실패하기 시작하면, 알림은 다음 콘텐츠와 함께 #ad-server Slack 채널로 전송돼요:

@slack-ad-server There is an ongoing issue with ad-server.

항상 존재하지 않을 수 있는 속성으로 동적 핸들을 만들 때는 알림 전달 문제가 발생할 수 있어요. 속성이 없으면 변수가 알림 메시지에서 비어 있게 렌더링되어 유효하지 않은 핸들이 돼요.

이런 변수로 동적 핸들을 사용할 때 알림 누락을 피하려면 폴백(fallback) 핸들을 추가하세요:

{{#is_exact_match "kube_namespace.owner" ""}}
  @slack-example
  // This will notify @slack-example if the kube_namespace.owner variable is empty or does not exist.
{{/is_exact_match}}

태그 변수를 사용해 팀을 적절한 리소스로 연결하는 동적 URL 생성을 활성화할 수 있어요. 예를 들어 대시보드, 호스트 맵, 모니터 같은 Datadog 내부 페이지로 연결되는 링크를 제공할 수 있어요.

{% tab title="Dashboards" %} {{host.name}} 태그 변수를 사용해 시스템 대시보드로 연결되는 링크를 제공해요:

https://app.datadoghq.com/dash/integration/system_overview?tpl_var_scope=host:{{host.name}}

{{host.name}} 태그 변수와 <INTEGRATION_NAME>을 사용해 통합 대시보드로 연결되는 링크를 제공해요:

https://app.datadoghq.com/dash/integration/<INTEGRATION_NAME>?tpl_var_scope=host:{{host.name}}

{{last_triggered_at_epoch}} 템플릿 변수와 <DASHBOARD_ID>, <DASHBOARD_NAME>을 사용해 경보 발생 시점부터의 상대적 시간 범위로 대시보드에 연결할 수 있어요:

https://app.datadoghq.com/dashboard/<DASHBOARD_ID>/<DASHBOARD_NAME>?from_ts={{eval "last_triggered_at_epoch-10*60*1000"}}&to_ts={{eval "last_triggered_at_epoch+10*60*1000"}}&live=false

{% /tab %}

{% tab title="Host map" %} {{service.name}} 같은 태그 변수를 사용해 호스트 맵으로 연결되는 링크를 제공해요:

https://app.datadoghq.com/infrastructure/map?filter=service:{{service.name}}

호스트 맵 링크는 추가 매개변수로 커스터마이징할 수 있어요. 가장 흔한 것은:

매개변수 (Parameter) 정의 (Defined with) 결정 (Determines)
fillby fillby=avg:<METRIC_NAME> 호스트 육각형의 채우기 색.
groupby groupby=<TAG_KEY> 호스트 육각형의 그룹.
sizeby sizeby=avg:<METRIC_NAME> 호스트 육각형의 크기.

{% /tab %}

{% tab title="Monitors" %} {{host.name}} 태그 변수를 사용해 특정 호스트와 관련된 모든 모니터로 연결되는 링크를 제공해요:

https://app.datadoghq.com/monitors/manage?q=scope:host:{{host.name}}

모니터 링크는 추가 매개변수로 커스터마이징할 수 있어요. 가장 흔한 것은:

매개변수 (Parameter) 예시 (Example) 표시 내용 (Displays)
status status:Alert 경보 상태의 모니터(추가 상태: WARN, NO DATA, OK)
muted muted: true 음소거된 모니터(음소거되지 않은 모니터는 false 사용)
type type:log 로그 모니터(다른 모니터 유형 참고)

{% /tab %}

{% tab title="Logs" %} {{last_triggered_at_epoch}} 템플릿 변수를 사용해 경보 발생 시점에 발생한 모든 로그로 연결되는 링크를 제공해요.

https://app.datadoghq.com/logs?from_ts={{eval "last_triggered_at_epoch-10*60*1000"}}&to_ts={{eval "last_triggered_at_epoch+10*60*1000"}}&live=false

로그 링크는 추가 매개변수로 커스터마이징할 수 있어요. 가장 흔한 것은:

매개변수 (Parameter) 정의 (Defined with) 결정 (Determines)
service service=<SERVICE_NAME> 특정 서비스의 로그를 필터링.
host host=<HOST_NAME> 특정 호스트의 로그를 필터링
status status=<STATUS> 로그 상태: Error, Warn, Info 등.

{% /tab %}

주석 (Comments)

모니터 메시지에 주석을 포함하려면 다음 구문을 사용해요:

{{!-- this is a comment --}}
{{!-- this is a comment }}

원시 형식 (Raw format)

경보 메시지가 {{ <TEXT> }} 같은 이중 중괄호를 보내야 한다면 {{{{raw}}}} 형식을 사용해요. 예를 들어 다음은:

{{{{raw}}}}
{{ <TEXT_1> }} {{ <TEXT_2> }}
{{{{/raw}}}}

다음을 출력해요:

{{ <TEXT_1> }} {{ <TEXT_2> }}

조건부 변수에 사용되는 ^|# 헬퍼는 {{{{raw}}}} 형식과 함께 사용할 수 없으므로 제거해야 해요. 예를 들어 {{is_match}} 조건부 변수로 원시 텍스트를 출력하려면 다음 템플릿을 사용해요:

{{{{is_match "host.name" "<HOST_NAME>"}}}}
{{ .matched }} the host name
{{{{/is_match}}}}

host.name이 <HOST_NAME>과 일치하면 템플릿은 다음을 출력해요:

{{ .matched }} the host name

URL 인코딩 (URL Encode)

경보 메시지에 URL로 인코딩해야 할 정보가 포함되어 있다면(예: 리디렉션을 위한 경우), {{ urlencode "<variable>"}} 구문을 사용해요.

예시: 모니터 메시지에 특정 서비스로 필터링된 Catalog로 연결되는 URL이 포함되어 있다면, service 태그 변수를 사용하고 URL에 {{ urlencode "<variable>"}} 구문을 추가해요:

https://app.datadoghq.com/services/{{urlencode "service.name"}}

더 알아보기 (Learn more)