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

Alerting API

원문 보기 위키 갱신

출처: 문서

본문

Alerting API

Alerting API를 사용하여 프로그래밍 방식으로 모니터와 알림을 생성, 업데이트 및 관리하세요. 복합 모니터를 지원하는 API에 대한 자세한 내용은 API로 복합 모니터 관리를 참조하세요.

쿼리 수준 모니터 생성

쿼리 수준 모니터는 쿼리를 실행하고 결과가 알림을 트리거해야 하는지 여부를 결정해요. 쿼리 수준 모니터는 한 번에 하나의 알림만 트리거할 수 있어요. 쿼리 수준 및 버킷 수준 모니터에 대한 자세한 내용은 모니터 생성을 참조하세요.

요청 예시

POST _plugins/_alerting/monitors
{
  "type": "monitor",
  "name": "test-monitor",
  "monitor_type": "query_level_monitor",
  "enabled": true,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [{
    "search": {
      "indices": ["movies"],
      "query": {
        "size": 0,
        "aggregations": {},
        "query": {
          "bool": {
            "filter": {
              "range": {
                "@timestamp": {
                  "gte": {% raw %}"{{period_end}}||-1h"{% endraw %},
                  "lte": {% raw %}"{{period_end}}"{% endraw %},
                  "format": "epoch_millis"
                }
              }
            }
          }
        }
      }
    }
  }],
  "triggers": [{
    "name": "test-trigger",
    "severity": "1",
    "condition": {
      "script": {
        "source": "ctx.results[0].hits.total.value > 0",
        "lang": "painless"
      }
    },
    "actions": [{
      "name": "test-action",
      "destination_id": "ld7912sBlQ5JUWWFThoW",
      "message_template": {
        "source": "This is my message body."
      },
      "throttle_enabled": true,
      "throttle": {
        "value": 27,
        "unit": "MINUTES"
      },
      "subject_template": {
        "source": "TheSubject"
      }
    }]
  }]
}

{% include copy-curl.html %}

대상에 사용자 정의 웹훅을 사용하고 메시지 본문에 JSON을 포함해야 하는 경우 따옴표를 이스케이프해야 해요:

{
  "message_template": {
    {% raw %}"source": "{ \"text\": \"Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue. - Trigger: {{ctx.trigger.name}} - Severity: {{ctx.trigger.severity}} - Period start: {{ctx.periodStart}} - Period end: {{ctx.periodEnd}}\" }"{% endraw %}
  }
}

{% include copy-curl.html %}

선택적으로 백엔드 역할을 지정하려면 rbac_roles 매개변수와 백엔드 역할 이름을 생성 모니터 요청 하단에 추가할 수 있어요.

다음 요청은 쿼리 수준 모니터를 생성하고 두 개의 백엔드 역할인 role1과 role2를 제공해요. 요청 하단의 섹션에는 "rbac_roles": ["role1", "role2"] 구문으로 역할을 지정하는 줄이 나와 있어요. 백엔드 역할을 사용하여 액세스를 제한하는 방법에 대한 자세한 내용은 (고급) 백엔드 역할로 액세스 제한을 참조하세요.

요청 예시

POST _plugins/_alerting/monitors
{
  "type": "monitor",
  "name": "test-monitor",
  "monitor_type": "query_level_monitor",
  "enabled": true,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [{
    "search": {
      "indices": ["movies"],
      "query": {
        "size": 0,
        "aggregations": {},
        "query": {
          "bool": {
            "filter": {
              "range": {
                "@timestamp": {
                  "gte": "{{period_end}}||-1h",
                  "lte": "{{period_end}}",
                  "format": "epoch_millis"
                }
              }
            }
          }
        }
      }
    }
  }],
  "triggers": [{
    "name": "test-trigger",
    "severity": "1",
    "condition": {
      "script": {
        "source": "ctx.results[0].hits.total.value > 0",
        "lang": "painless"
      }
    },
    "actions": [{
      "name": "test-action",
      "destination_id": "ld7912sBlQ5JUWWFThoW",
      "message_template": {
        "source": "This is my message body."
      },
      "throttle_enabled": true,
      "throttle": {
        "value": 27,
        "unit": "MINUTES"
      },
      "subject_template": {
        "source": "TheSubject"
      }
    }]
  }],
  "rbac_roles": ["role1", "role2"]
}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "_id": "vd5k2GsBlQ5JUWWFxhsP",
  "_version": 1,
  "_seq_no": 7,
  "_primary_term": 1,
  "monitor": {
    "type": "monitor",
    "schema_version": 1,
    "name": "test-monitor",
    "enabled": true,
    "enabled_time": 1562703611363,
    "schedule": {
      "period": {
        "interval": 1,
        "unit": "MINUTES"
      }
    },
    "inputs": [{
      "search": {
        "indices": [
          "movies"
        ],
        "query": {
          "size": 0,
          "query": {
            "bool": {
              "filter": [{
                "range": {
                  "@timestamp": {
                    "from": {% raw %}"{{period_end}}||-1h"{% endraw %},
                    "to": {% raw %}"{{period_end}}"{% endraw %},
                    "include_lower": true,
                    "include_upper": true,
                    "format": "epoch_millis",
                    "boost": 1
                  }
                }
              }],
              "adjust_pure_negative": true,
              "boost": 1
            }
          },
          "aggregations": {}
        }
      }
    }],
    "triggers": [{
      "id": "ud5k2GsBlQ5JUWWFxRvi",
      "name": "test-trigger",
      "severity": "1",
      "condition": {
        "script": {
          "source": "ctx.results[0].hits.total.value > 0",
          "lang": "painless"
        }
      },
      "actions": [{
        "id": "ut5k2GsBlQ5JUWWFxRvj",
        "name": "test-action",
        "destination_id": "ld7912sBlQ5JUWWFThoW",
        "message_template": {
          "source": "This is my message body.",
          "lang": "mustache"
        },
        "throttle_enabled": false,
        "subject_template": {
          "source": "Subject",
          "lang": "mustache"
        }
      }]
    }],
    "last_update_time": 1562703611363
  }
}

{% include copy-curl.html %}

시간대를 지정하려면 요청의 schedule 섹션에 시간대 이름이 포함된 cron 표현식을 포함하면 돼요. 다음 예시는 매월 첫째 날 오후 12:10 태평양 시간에 실행되는 모니터를 생성해요.

요청 예시

{
  "type": "monitor",
  "name": "test-monitor",
  "monitor_type": "query_level_monitor",
  "enabled": true,
  "schedule": {
    "cron" : {
        "expression": "10 12 1 * *",
        "timezone": "America/Los_Angeles"
    }
  },
  "inputs": [{
    "search": {
      "indices": ["movies"],
      "query": {
        "size": 0,
        "aggregations": {},
        "query": {
          "bool": {
            "filter": {
              "range": {
                "@timestamp": {
                  "gte": {% raw %}"{{period_end}}||-1h"{% endraw %},
                  "lte": {% raw %}"{{period_end}}"{% endraw %},
                  "format": "epoch_millis"
                }
              }
            }
          }
        }
      }
    }
  }],
  "triggers": [{
    "name": "test-trigger",
    "severity": "1",
    "condition": {
      "script": {
        "source": "ctx.results[0].hits.total.value > 0",
        "lang": "painless"
      }
    },
    "actions": [{
      "name": "test-action",
      "destination_id": "ld7912sBlQ5JUWWFThoW",
      "message_template": {
        "source": "This is a message body."
      },
      "throttle_enabled": true,
      "throttle": {
        "value": 27,
        "unit": "MINUTES"
      },
      "subject_template": {
        "source": "Subject"
      }
    }]
  }]
}

{% include copy-curl.html %}

전체 시간대 이름 목록은 tz 데이터베이스 시간대 목록을 참조하세요. Alerting 플러그인은 Java TimeZone 클래스를 사용하여 ZoneId를 유효한 시간대로 변환해요.


버킷 수준 모니터

버킷 수준 모니터는 결과를 필드별로 구분된 버킷으로 분류해요. 그런 다음 모니터는 각 버킷의 결과로 스크립트를 실행하고 알림을 트리거할지 여부를 평가해요. 버킷 수준 및 쿼리 수준 모니터에 대한 자세한 내용은 모니터 생성을 참조하세요.

요청 예시

POST _plugins/_alerting/monitors
{
  "type": "monitor",
  "name": "Demo bucket-level monitor",
  "monitor_type": "bucket_level_monitor",
  "enabled": true,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [
    {
      "search": {
        "indices": [
          "movies"
        ],
        "query": {
          "size": 0,
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "order_date": {
                      "from": {% raw %}"{{period_end}}||-1h"{% endraw %},
                      "to": {% raw %}"{{period_end}}"{% endraw %},
                      "include_lower": true,
                      "include_upper": true,
                      "format": "epoch_millis"
                    }
                  }
                }
              ]
            }
          },
          "aggregations": {
            "composite_agg": {
              "composite": {
                "sources": [
                  {
                    "user": {
                      "terms": {
                        "field": "user"
                      }
                    }
                  }
                ]
              },
              "aggregations": {
                "avg_products_base_price": {
                  "avg": {
                    "field": "products.base_price"
                  }
                }
              }
            }
          }
        }
      }
    }
  ],
  "triggers": [
    {
      "bucket_level_trigger": {
        "name": "test-trigger",
        "severity": "1",
        "condition": {
          "buckets_path": {
            "_count": "_count",
            "avg_products_base_price": "avg_products_base_price"
          },
          "parent_bucket_path": "composite_agg",
          "script": {
            "source": "params._count > 50 || params.avg_products_base_price < 35",
            "lang": "painless"
          }
        },
        "actions": [
          {
            "name": "test-action",
            "destination_id": "E4o5hnsB6KjPKmHtpfCA",
            "message_template": {
              "source": {% raw %}"""Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.   - Trigger: {{ctx.trigger.name}}   - Severity: {{ctx.trigger.severity}}   - Period start: {{ctx.periodStart}}   - Period end: {{ctx.periodEnd}}    - Deduped Alerts:   {{ctx.dedupedAlerts}}     * {{id}} : {{bucket_keys}}   {{ctx.dedupedAlerts}}    - New Alerts:   {{ctx.newAlerts}}     * {{id}} : {{bucket_keys}}   {{ctx.newAlerts}}    - Completed Alerts:   {{ctx.completedAlerts}}     * {{id}} : {{bucket_keys}}   {{ctx.completedAlerts}}"""{% endraw %},
              "lang": "mustache"
            },
            "throttle_enabled": false,
            "throttle": {
              "value": 10,
              "unit": "MINUTES"
            },
            "action_execution_policy": {
              "action_execution_scope": {
                "per_alert": {
                  "actionable_alerts": [
                    "DEDUPED",
                    "NEW"
                  ]
                }
              }
            },
            "subject_template": {
              "source": "The Subject",
              "lang": "mustache"
            }
          }
        ]
      }
    }
  ]
}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "_id" : "Dfxr63sBwex6DxEhHV5N",
  "_version" : 1,
  "_seq_no" : 3,
  "_primary_term" : 1,
  "monitor" : {
    "type" : "monitor",
    "schema_version" : 4,
    "name" : "Demo a bucket-level monitor",
    "monitor_type" : "bucket_level_monitor",
    "user" : {
      "name" : "",
      "backend_roles" : [ ],
      "roles" : [ ],
      "custom_attribute_names" : [ ],
      "user_requested_tenant" : null
    },
    "enabled" : true,
    "enabled_time" : 1631742270785,
    "schedule" : {
      "period" : {
        "interval" : 1,
        "unit" : "MINUTES"
      }
    },
    "inputs" : [
      {
        "search" : {
          "indices" : [
            "opensearch_dashboards_sample_data_flights"
          ],
          "query" : {
            "size" : 0,
            "query" : {
              "bool" : {
                "filter" : [
                  {
                    "range" : {
                      "order_date" : {
                        "from" : {% raw %}"{{period_end}}||-1h"{% endraw %},
                        "to" : {% raw %}"{{period_end}}"{% endraw %},
                        "include_lower" : true,
                        "include_upper" : true,
                        "format" : "epoch_millis",
                        "boost" : 1.0
                      }
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            },
            "aggregations" : {
              "composite_agg" : {
                "composite" : {
                  "size" : 10,
                  "sources" : [
                    {
                      "user" : {
                        "terms" : {
                          "field" : "user",
                          "missing_bucket" : false,
                          "order" : "asc"
                        }
                      }
                    }
                  ]
                },
                "aggregations" : {
                  "avg_products_base_price" : {
                    "avg" : {
                      "field" : "products.base_price"
                    }
                  }
                }
              }
            }
          }
        }
      }
    ],
    "triggers" : [
      {
        "bucket_level_trigger" : {
          "id" : "C_xr63sBwex6DxEhHV5B",
          "name" : "test-trigger",
          "severity" : "1",
          "condition" : {
            "buckets_path" : {
              "_count" : "_count",
              "avg_products_base_price" : "avg_products_base_price"
            },
            "parent_bucket_path" : "composite_agg",
            "script" : {
              "source" : "params._count > 50 || params.avg_products_base_price < 35",
              "lang" : "painless"
            },
            "gap_policy" : "skip"
          },
          "actions" : [
            {
              "id" : "DPxr63sBwex6DxEhHV5B",
              "name" : "test-action",
              "destination_id" : "E4o5hnsB6KjPKmHtpfCA",
              "message_template" : {
                "source" : {% raw %}"Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.   - Trigger: {{ctx.trigger.name}}   - Severity: {{ctx.trigger.severity}}   - Period start: {{ctx.periodStart}}   - Period end: {{ctx.periodEnd}}    - Deduped Alerts:   {{ctx.dedupedAlerts}}     * {{id}} : {{bucket_keys}}   {{ctx.dedupedAlerts}}    - New Alerts:   {{ctx.newAlerts}}     * {{id}} : {{bucket_keys}}   {{ctx.newAlerts}}    - Completed Alerts:   {{ctx.completedAlerts}}     * {{id}} : {{bucket_keys}}   {{ctx.completedAlerts}}"{% endraw %},
                "lang" : "mustache"
              },
              "throttle_enabled" : false,
              "subject_template" : {
                "source" : "The Subject",
                "lang" : "mustache"
              },
              "throttle" : {
                "value" : 10,
                "unit" : "MINUTES"
              },
              "action_execution_policy" : {
                "action_execution_scope" : {
                  "per_alert" : {
                    "actionable_alerts" : [
                      "DEDUPED",
                      "NEW"
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    ],
    "last_update_time" : 1631742270785
  }
}

{% include copy-curl.html %}


문서 수준 모니터

2.0에서 도입됨 {: .label .label-purple }

문서 수준 모니터는 인덱스의 개별 문서가 트리거 조건과 일치하는지 확인해요. 일치하는 경우 모니터는 알림을 생성해요. 문서 수준 모니터로 쿼리를 실행하면 트리거 조건과 일치하는 각 문서에 대한 결과가 반환돼요. 쿼리 이름, 쿼리 ID 또는 여러 쿼리를 결합하는 태그를 기반으로 트리거 조건을 생성할 수 있어요.

문서 수준 모니터 API와 유사하게 작동하는 문서별 모니터에 대한 자세한 내용은 모니터를 참조하세요.

결과 인덱스 검색

alerting 검색 API 작업을 사용하여 GET 요청으로 결과 인덱스 .opensearch-alerting-finding*에서 사용 가능한 문서 결과를 검색할 수 있어요. 기본적으로 경로 매개변수 없이 GET 요청을 보내면 모든 사용 가능한 결과가 반환돼요.

사용 가능한 결과를 검색하려면 다음과 같이 경로 매개변수 없이 GET 요청을 보내세요:

GET /_plugins/_alerting/findings/_search?

{% include copy-curl.html %}

개별 문서 결과 항목의 메타데이터를 검색하려면 다음과 같이 findingId로 결과를 검색할 수 있어요:

GET /_plugins/_alerting/findings/_search?findingId=gKQhj8WJit3BxjGfiOXC

{% include copy-curl.html %}

응답은 total_findings 필드에 개별 결과 항목의 수를 반환해요.

결과 검색에서 더 구체적인 결과를 얻으려면 다음 표에 정의된 선택적 경로 매개변수를 사용할 수 있어요.

경로 매개변수 설명 사용법
findingId 결과 항목의 식별자예요. 결과 ID는 초기 쿼리 응답에서 반환돼요.
sortString 이 필드는 Alerting 플러그인이 결과를 정렬하는 데 사용하는 문자열을 지정해요. 기본값은 id예요.
sortOrder 결과 목록을 정렬하는 순서로, 오름차순 또는 내림차순이에요. sortOrder=asc는 오름차순, sortOrder=desc는 내림차순을 나타내요.
size 응답에서 반환되는 최대 결과 수에 대한 선택적 제한이에요. 최소값이나 최대값은 없어요.
startIndex 페이지 매김 표시자예요. 기본값은 0이에요.
searchString 검색에서 반환하려는 결과 속성이에요. 특정 인덱스에서 검색하려면 요청 경로에 인덱스 이름을 지정하세요. 예를 들어 indexABC 인덱스에서 결과를 검색하려면 searchString=indexABC'를 사용하세요.

문서 수준 모니터 생성

POST 요청으로 요청 본문에 모니터 세부 정보를 제공하여 문서 수준 모니터를 생성할 수 있어요. 최소한 다음 세부 정보를 제공해야 해요: inputs 필드로 태그별 쿼리 또는 조합을 지정하고, 유효한 트리거 조건을 지정하고, action 필드에 알림 메시지를 제공해야 해요.

다음 표는 각 트리거 옵션에 사용할 구문을 제공해요.

트리거 옵션 정의 구문
태그 이 태그가 적용된 여러 쿼리와 일치하는 문서에 대한 알림을 생성해요. 여러 쿼리를 단일 태그로 그룹화하면 이 태그 이름으로 결과가 반환될 때 알림을 트리거하도록 설정할 수 있어요. query[tag=<tag-name>]
이름별 쿼리 이름이 지정된 쿼리와 일치하거나 반환된 문서에 대한 알림을 생성해요. query[name=<query-name>]
ID별 쿼리 식별된 쿼리에 의해 반환된 문서에 대한 알림을 생성해요. query[id=<query-id>]

요청 예시

POST _plugins/_alerting/monitors
{
  "type": "monitor",
  "monitor_type": "doc_level_monitor",
  "name": "Example document-level monitor",
  "enabled": true,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [
    {
      "doc_level_input": {
        "description": "Example document-level monitor for audit logs",
        "indices": [
          "audit-logs"
        ],
        "queries": [
        {
            "id": "nKQnFYABit3BxjGfiOXC",
            "name": "sigma-123",
            "query": "region:\"us-west-2\"",
            "tags": [
                "tag1"
            ]
        },
        {
            "id": "gKQnABEJit3BxjGfiOXC",
            "name": "sigma-456",
            "query": "region:\"us-east-1\"",
            "tags": [
                "tag2"
            ]
        },
        {
            "id": "h4J2ABEFNW3vxjGfiOXC",
            "name": "sigma-789",
            "query": "message:\"This is a SEPARATE error from IAD region\"",
            "tags": [
                "tag3"
            ]
        }
    ]
      }
    }
  ],
    "triggers": [ { "document_level_trigger": {
      "name": "test-trigger",
      "severity": "1",
      "condition": {
        "script": {
          "source": "(query[name=sigma-123] || query[tag=tag3]) && query[name=sigma-789]",
          "lang": "painless"
        }
      },
      "actions": [
        {
            "name": "test-action",
            "destination_id": "E4o5hnsB6KjPKmHtpfCA",
            "message_template": {
                "source": {% raw %}"""Monitor  just entered alert status. Please investigate the issue. Related Finding Ids: {{ctx.alerts.0.finding_ids}}, Related Document Ids: {{ctx.alerts.0.related_doc_ids}}"""{% endraw %},
                "lang": "mustache"
            },
            "action_execution_policy": {
                "action_execution_scope": {
                    "per_alert": {
                        "actionable_alerts": []
                    }
                }
            },
            "subject_template": {
                "source": "The Subject",
                "lang": "mustache"
            }
         }
      ]
  }}]
}

{% include copy-curl.html %}

제한 사항

인덱스가 재인덱싱되는 동안 문서 수준 쿼리를 실행하면 API 응답에 재인덱싱된 결과가 반환되지 않아요. 업데이트를 받으려면 재인덱싱 프로세스가 완료될 때까지 기다린 후 쿼리를 다시 실행하세요.


모니터 업데이트

모니터를 업데이트할 때 선택적으로 if_seq_no 및 if_primary_term 쿼리 매개변수를 포함할 수 있어요(예: ?if_seq_no=3&if_primary_term=1). 이 숫자가 기존 모니터와 일치하지 않거나 모니터가 존재하지 않으면 Alerting 플러그인에서 오류가 발생해요. OpenSearch는 버전 번호와 시퀀스 번호를 자동으로 증가시켜요(예시 응답 참조).

요청 예시

PUT _plugins/_alerting/monitors/{monitor_id}
{
  "type": "monitor",
  "name": "test-monitor",
  "enabled": true,
  "enabled_time": 1551466220455,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [{
    "search": {
      "indices": [
        "*"
      ],
      "query": {
        "query": {
          "match_all": {
            "boost": 1
          }
        }
      }
    }
  }],
  "triggers": [{
    "id": "StaeOmkBC25HCRGmL_y-",
    "name": "test-trigger",
    "severity": "1",
    "condition": {
      "script": {
        "source": "return true",
        "lang": "painless"
      }
    },
    "actions": [{
      "name": "test-action",
      "destination_id": "RtaaOmkBC25HCRGm0fxi",
      "subject_template": {
        "source": "My Message Subject",
        "lang": "mustache"
      },
      "message_template": {
        "source": "This is my message body.",
        "lang": "mustache"
      }
    }]
  }],
  "last_update_time": 1551466639295
}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "_id": "Q9aXOmkBC25HCRGmzfw-",
  "_version": 4,
  "_seq_no": 4,
  "_primary_term": 1,
  "monitor": {
    "type": "monitor",
    "name": "test-monitor",
    "enabled": true,
    "enabled_time": 1551466220455,
    "schedule": {
      "period": {
        "interval": 1,
        "unit": "MINUTES"
      }
    },
    "inputs": [{
      "search": {
        "indices": [
          "*"
        ],
        "query": {
          "query": {
            "match_all": {
              "boost": 1
            }
          }
        }
      }
    }],
    "triggers": [{
      "id": "StaeOmkBC25HCRGmL_y-",
      "name": "test-trigger",
      "severity": "1",
      "condition": {
        "script": {
          "source": "return true",
          "lang": "painless"
        }
      },
      "actions": [{
        "name": "test-action",
        "destination_id": "RtaaOmkBC25HCRGm0fxi",
        "subject_template": {
          "source": "My Message Subject",
          "lang": "mustache"
        },
        "message_template": {
          "source": "This is my message body.",
          "lang": "mustache"
        }
      }]
    }],
    "last_update_time": 1551466761596
  }
}

{% include copy-curl.html %}


모니터 가져오기

다음 요청을 사용하여 특정 모니터의 세부 정보를 검색하세요.

요청 예시

GET _plugins/_alerting/monitors/{monitor_id}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "_id": "Q9aXOmkBC25HCRGmzfw-",
  "_version": 3,
  "_seq_no": 3,
  "_primary_term": 1,
  "monitor": {
    "type": "monitor",
    "name": "test-monitor",
    "enabled": true,
    "enabled_time": 1551466220455,
    "schedule": {
      "period": {
        "interval": 1,
        "unit": "MINUTES"
      }
    },
    "inputs": [{
      "search": {
        "indices": [
          "*"
        ],
        "query": {
          "query": {
            "match_all": {
              "boost": 1
            }
          }
        }
      }
    }],
    "triggers": [{
      "id": "StaeOmkBC25HCRGmL_y-",
      "name": "test-trigger",
      "severity": "1",
      "condition": {
        "script": {
          "source": "return true",
          "lang": "painless"
        }
      },
      "actions": [{
        "name": "test-action",
        "destination_id": "RtaaOmkBC25HCRGm0fxi",
        "subject_template": {
          "source": "My Message Subject",
          "lang": "mustache"
        },
        "message_template": {
          "source": "This is my message body.",
          "lang": "mustache"
        }
      }]
    }],
    "last_update_time": 1551466639295
  }
}

{% include copy-curl.html %}


모니터 통계

alerting 기능에 대한 통계를 반환해요. _plugins/_alerting/stats를 사용하여 노드 ID와 메트릭을 찾으세요. 그런 다음 해당 값을 사용하여 드릴다운할 수 있어요.

요청 예시

GET _plugins/_alerting/stats
GET _plugins/_alerting/stats/{metric}
GET _plugins/_alerting/{node-id}/stats
GET _plugins/_alerting/{node-id}/stats/{metric}
예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "_nodes": {
    "total": 9,
    "successful": 9,
    "failed": 0
  },
  "cluster_name": "475300751431:alerting65-dont-delete",
  "plugins.scheduled_jobs.enabled": true,
  "scheduled_job_index_exists": true,
  "scheduled_job_index_status": "green",
  "nodes_on_schedule": 9,
  "nodes_not_on_schedule": 0,
  "nodes": {
    "qWcbKbb-TVyyI-Q7VSeOqA": {
      "name": "qWcbKbb",
      "schedule_status": "green",
      "roles": [
        "MASTER"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 207017,
        "full_sweep_on_time": true
      },
      "jobs_info": {}
    },
    "Do-DX9ZcS06Y9w1XbSJo1A": {
      "name": "Do-DX9Z",
      "schedule_status": "green",
      "roles": [
        "DATA",
        "INGEST"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 230516,
        "full_sweep_on_time": true
      },
      "jobs_info": {}
    },
    "n5phkBiYQfS5I0FDzcqjZQ": {
      "name": "n5phkBi",
      "schedule_status": "green",
      "roles": [
        "MASTER"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 228406,
        "full_sweep_on_time": true
      },
      "jobs_info": {}
    },
    "Tazzo8cQSY-g3vOjgYYLzA": {
      "name": "Tazzo8c",
      "schedule_status": "green",
      "roles": [
        "DATA",
        "INGEST"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 211722,
        "full_sweep_on_time": true
      },
      "jobs_info": {
        "i-wsFmkB8NzS6aXjQSk0": {
          "last_execution_time": 1550864912882,
          "running_on_time": true
        }
      }
    },
    "Nyf7F8brTOSJuFPXw6CnpA": {
      "name": "Nyf7F8b",
      "schedule_status": "green",
      "roles": [
        "DATA",
        "INGEST"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 223300,
        "full_sweep_on_time": true
      },
      "jobs_info": {
        "NbpoFmkBeSe-hD59AKgE": {
          "last_execution_time": 1550864928354,
          "running_on_time": true
        },
        "-LlLFmkBeSe-hD59Ydtb": {
          "last_execution_time": 1550864732727,
          "running_on_time": true
        },
        "pBFxFmkBNXkgNmTBaFj1": {
          "last_execution_time": 1550863325024,
          "running_on_time": true
        },
        "hfasEmkBNXkgNmTBrvIW": {
          "last_execution_time": 1550862000001,
          "running_on_time": true
        }
      }
    },
    "oOdJDIBVT5qbbO3d8VLeEw": {
      "name": "oOdJDIB",
      "schedule_status": "green",
      "roles": [
        "DATA",
        "INGEST"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 227570,
        "full_sweep_on_time": true
      },
      "jobs_info": {
        "4hKRFmkBNXkgNmTBKjYX": {
          "last_execution_time": 1550864806101,
          "running_on_time": true
        }
      }
    },
    "NRDG6JYgR8m0GOZYQ9QGjQ": {
      "name": "NRDG6JY",
      "schedule_status": "green",
      "roles": [
        "MASTER"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 227652,
        "full_sweep_on_time": true
      },
      "jobs_info": {}
    },
    "URMrXRz3Tm-CB72hlsl93Q": {
      "name": "URMrXRz",
      "schedule_status": "green",
      "roles": [
        "DATA",
        "INGEST"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 231048,
        "full_sweep_on_time": true
      },
      "jobs_info": {
        "m7uKFmkBeSe-hD59jplP": {
          "running_on_time": true
        }
      }
    },
    "eXgt1k9oTRCLmx2HBGElUw": {
      "name": "eXgt1k9",
      "schedule_status": "green",
      "roles": [
        "DATA",
        "INGEST"
      ],
      "job_scheduling_metrics": {
        "last_full_sweep_time_millis": 229234,
        "full_sweep_on_time": true
      },
      "jobs_info": {
        "wWkFFmkBc2NG-PeLntxk": {
          "running_on_time": true
        },
        "3usNFmkB8NzS6aXjO1Gs": {
          "last_execution_time": 1550863959848,
          "running_on_time": true
        }
      }
    }
  }
}

{% include copy-curl.html %}


모니터 삭제

다음 요청을 사용하여 모니터를 삭제하세요.

요청 예시

DELETE _plugins/_alerting/monitors/{monitor_id}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "_index": ".opensearch-scheduled-jobs",
  "_id": "OYAHOmgBl3cmwnqZl_yH",
  "_version": 2,
  "result": "deleted",
  "forced_refresh": true,
  "_shards": {
    "total": 2,
    "successful": 2,
    "failed": 0
  },
  "_seq_no": 11,
  "_primary_term": 1
}

{% include copy-curl.html %}


모니터 검색

다음 요청을 사용하여 모니터 이름과 같은 특정 기준에 따라 기존 모니터에 대한 정보를 쿼리하고 검색하세요.

요청 예시

GET _plugins/_alerting/monitors/_search
{
  "query": {
    "match" : {
      "monitor.name": "my-monitor-name"
    }
  }
}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "took": 17,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.6931472,
    "hits": [{
      "_index": ".opensearch-scheduled-jobs",
      "_type": "_doc",
      "_id": "eGQi7GcBRS7-AJEqfAnr",
      "_score": 0.6931472,
      "_source": {
        "type": "monitor",
        "name": "my-monitor-name",
        "enabled": true,
        "enabled_time": 1545854942426,
        "schedule": {
          "period": {
            "interval": 1,
            "unit": "MINUTES"
          }
        },
        "inputs": [{
          "search": {
            "indices": [
              "*"
            ],
            "query": {
              "size": 0,
              "query": {
                "bool": {
                  "filter": [{
                    "range": {
                      "@timestamp": {
                        "from": {% raw %}"{{period_end}}||-1h"{% endraw %},
                        "to": {% raw %}"{{period_end}}"{% endraw %},
                        "include_lower": true,
                        "include_upper": true,
                        "format": "epoch_millis",
                        "boost": 1
                      }
                    }
                  }],
                  "adjust_pure_negative": true,
                  "boost": 1
                }
              },
              "aggregations": {}
            }
          }
        }],
        "triggers": [{
          "id": "Sooi7GcB53a0ewuj_6MH",
          "name": "Over",
          "severity": "1",
          "condition": {
            "script": {
              "source": "_ctx.results[0].hits.total > 400000",
              "lang": "painless"
            }
          },
          "actions": []
        }],
        "last_update_time": 1545854975758
      }
    }]
  }
}

{% include copy-curl.html %}


모니터 실행

선택적 ?dryrun=true 매개변수를 URL에 추가하여 작업이 메시지를 보내지 않고 실행 결과를 표시할 수 있어요.

요청 예시

POST _plugins/_alerting/monitors/{monitor_id}/_execute

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "monitor_name": "logs",
  "period_start": 1547161872322,
  "period_end": 1547161932322,
  "error": null,
  "trigger_results": {
    "Sooi7GcB53a0ewuj_6MH": {
      "name": "Over",
      "triggered": true,
      "error": null,
      "action_results": {}
    }
  }
}

{% include copy-curl.html %}


알림 가져오기

모든 알림의 배열을 반환해요.

경로 매개변수

다음 표는 사용 가능한 경로 매개변수를 나열해요. 모든 경로 매개변수는 선택 사항이에요.

매개변수 데이터 타입 설명
sortString String 결과를 정렬하는 방법을 정의해요. 기본값은 monitor_name.keyword예요.
sortOrder String 결과의 순서를 정의해요. 옵션은 asc 또는 desc예요. 기본값은 asc예요.
missing String 응답에 누락된 데이터를 포함할지 여부를 지정해요.
size String 반환될 요청의 크기를 정의해요. 기본값은 20이에요.
startIndex String 시작할 인덱스를 정의해요. 결과 페이지 매김에 사용돼요. 기본값은 0이에요.
searchString String 특정 알림을 검색하는 데 사용할 검색 문자열을 정의해요. 기본값은 빈 문자열이에요.
severityLevel String 필터링할 심각도 수준을 정의해요. 기본값은 ALL이에요.
alertState String 필터링할 알림 상태를 정의해요. 기본값은 ALL이에요.
monitorId String 모니터 ID로 필터링해요.
workflowIds String 단일 대시보드 내에서 여러 워크플로의 체인 알림 상태를 모니터링할 수 있어요. OpenSearch 2.9 이상에서 사용 가능해요.

요청 예시

GET _plugins/_alerting/monitors/alerts

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "alerts": [
    {
      "id": "eQURa3gBKo1jAh6qUo49",
      "version": 300,
      "monitor_id": "awUMa3gBKo1jAh6qu47E",
      "schema_version": 2,
      "monitor_version": 2,
      "monitor_name": "Example_monitor_name",
      "monitor_user": {
        "name": "admin",
        "backend_roles": [
          "admin"
        ],
        "roles": [
          "all_access",
          "own_index"
        ],
        "custom_attribute_names": [],
        "user_requested_tenant": null
      },
      "trigger_id": "bQUQa3gBKo1jAh6qnY6G",
      "trigger_name": "Example_trigger_name",
      "state": "ACTIVE",
      "error_message": null,
      "alert_history": [
        {
          "timestamp": 1617314504873,
          "message": "Example error message"
        },
        {
          "timestamp": 1617312543925,
          "message": "Example error message"
        }
      ],
      "severity": "1",
      "action_execution_results": [
        {
          "action_id": "bgUQa3gBKo1jAh6qnY6G",
          "last_execution_time": 1617317979908,
          "throttled_count": 0
        }
      ],
      "start_time": 1616704000492,
      "last_notification_time": 1617317979908,
      "end_time": null,
      "acknowledged_time": null
    }
  ],
  "totalAlerts": 1
}

{% include copy-curl.html %}


알림 확인

알림을 가져온 후 한 번의 호출로 여러 활성 알림을 확인할 수 있어요. 알림이 이미 ERROR, COMPLETED 또는 ACKNOWLEDGED 상태인 경우 failed 배열에 나타나요.

요청 예시

POST _plugins/_alerting/monitors/{monitor-id}/_acknowledge/alerts
{
  "alerts": ["eQURa3gBKo1jAh6qUo49"]
}

{% include copy-curl.html %}

예시 응답을 보려면 선택하세요 {: .text-delta}

예시 응답

{
  "success": [
  "eQURa3gBKo1jAh6qUo49"
  ],
  "failed": []
}

{% include copy-curl.html %}


Destinations

Destinations는 OpenSearch 2.0에서 더 이상 사용되지 않게 되었고, notification channels로 대체되었어요. destinations를 생성, 업데이트, 삭제하는 작업은 같은 릴리스에서 제거되었고, 기존 destinations는 자동으로 notification channels로 마이그레이션되었어요. 알림이 전달될 위치를 구성하려면 Notifications API를 사용하세요. 마이그레이션되지 않은 destinations를 검색하기 위해 다음 읽기 작업을 계속 사용할 수 있어요. {: .warning}

Get destination

다음 요청을 사용하여 하나의 destination을 검색해요.

요청 예시

GET _plugins/_alerting/destinations/{destination-id}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "totalDestinations": 1,
  "destinations": [{
      "id": "1a2a3a4a5a6a7a",
      "type": "slack",
      "name": "sample-destination",
      "user": {
        "name": "psantos",
        "backend_roles": [
          "human-resources"
        ],
        "roles": [
          "alerting_full_access",
          "hr-role"
        ],
        "custom_attribute_names": []
      },
      "schema_version": 3,
      "seq_no": 0,
      "primary_term": 6,
      "last_update_time": 1603943261722,
      "slack": {
        "url": "https://example.com"
      }
    }
  ]
}

{% include copy-curl.html %}

Get destinations

다음 요청을 사용하여 모든 destinations를 검색해요.

요청 예시

GET _plugins/_alerting/destinations

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "totalDestinations": 1,
  "destinations": [{
      "id": "1a2a3a4a5a6a7a",
      "type": "slack",
      "name": "sample-destination",
      "user": {
        "name": "psantos",
        "backend_roles": [
          "human-resources"
        ],
        "roles": [
          "alerting_full_access",
          "hr-role"
        ],
        "custom_attribute_names": []
      },
      "schema_version": 3,
      "seq_no": 0,
      "primary_term": 6,
      "last_update_time": 1603943261722,
      "slack": {
        "url": "https://example.com"
      }
    }
  ]
}

{% include copy-curl.html %}

Get email account

다음 요청을 사용하여 알림 목적으로 구성된 특정 이메일 계정의 세부 정보를 검색해요.

요청 예시

GET _plugins/_alerting/destinations/email_accounts/{email_account_id}
{
  "name": "example_account",
  "email": "[email protected]",
  "host": "smtp.email.com",
  "port": 465,
  "method": "ssl"
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "_id" : "email_account_id",
  "_version" : 2,
  "_seq_no" : 8,
  "_primary_term" : 2,
  "email_account" : {
    "schema_version" : 2,
    "name" : "test_account",
    "email" : "[email protected]",
    "host" : "smtp.test.com",
    "port" : 465,
    "method" : "ssl"
  }
}

{% include copy-curl.html %}

Search email account

다음 요청을 사용하여 이메일 기반 알림에 사용되는 구성된 이메일 계정에 대한 정보를 검색해요.

요청 예시

POST _plugins/_alerting/destinations/email_accounts/_search
{
  "from": 0,
  "size": 20,
  "sort": { "email_account.name.keyword": "desc" },
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      }
    }
  }
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : ".opendistro-alerting-config",
        "_type" : "_doc",
        "_id" : "email_account_id",
        "_seq_no" : 8,
        "_primary_term" : 2,
        "_score" : null,
        "_source" : {
          "schema_version" : 2,
          "name" : "example_account",
          "email" : "[email protected]",
          "host" : "smtp.email.com",
          "port" : 465,
          "method" : "ssl"
        },
        "sort" : [
          "example_account"
        ]
      },
      ...
    ]
  }
}

{% include copy-curl.html %}

Get email group

다음 요청을 사용하여 특정 이메일 그룹 destination의 세부 정보를 검색해요. 가져오려는 이메일 그룹의 ID를 전달해요.

요청 예시

GET _plugins/_alerting/destinations/email_groups/{email_group_id}
{
  "name": "example_email_group",
  "emails": [{
    "email": "[email protected]"
  }]
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "_id" : "email_group_id",
  "_version" : 4,
  "_seq_no" : 17,
  "_primary_term" : 2,
  "email_group" : {
    "schema_version" : 2,
    "name" : "example_email_group",
    "emails" : [
      {
        "email" : "[email protected]"
      }
    ]
  }
}

{% include copy-curl.html %}

Search email group

다음 요청을 사용하여 알림 목적으로 사용되는 기존 이메일 그룹에 대한 정보를 쿼리하고 검색해요. 다양한 기준에 따라 결과를 필터링하고 정렬할 수 있어요. 예시는 다음 요청에 나와 있어요.

요청 예시

POST _plugins/_alerting/destinations/email_groups/_search
{
  "from": 0,
  "size": 20,
  "sort": { "email_group.name.keyword": "desc" },
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      }
    }
  }
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 5,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : ".opendistro-alerting-config",
        "_type" : "_doc",
        "_id" : "email_group_id",
        "_seq_no" : 10,
        "_primary_term" : 2,
        "_score" : null,
        "_source" : {
          "schema_version" : 2,
          "name" : "example_email_group",
          "emails" : [
            {
              "email" : "[email protected]"
            }
          ]
        },
        "sort" : [
          "example_email_group"
        ]
      },
      ...
    ]
  }
}

{% include copy-curl.html %}

Create comment

다음 요청을 사용하여 특정 알림에 댓글을 추가해요. 해당 알림과 관련된 추가 컨텍스트나 메모를 제공해요.

요청 예시

POST _plugins/_alerting/comments/{alert-id}
{
  "content": "sample comment"
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "_id": "0U6aBJABVWc3FrmWer9s",
  "_seq_no": 7,
  "_primary_term": 2,
  "comment": {
    "entity_id": "vCZkA5ABWTh3kzuBEL_9",
    "entity_type": "alert",
    "content": "sample comment",
    "created_time": 1718064151148,
    "last_updated_time": null,
    "user": "admin"
  }
}

{% include copy-curl.html %}

Update comment

다음 요청을 사용하여 알림과 연결된 이전에 추가된 댓글의 내용을 수정해요.

요청 예시

PUT _plugins/_alerting/comments/{comment-id}
{
  "content": "sample updated comment"
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "_id": "0U6aBJABVWc3FrmWer9s",
  "_seq_no": 8,
  "_primary_term": 3,
  "comment": {
    "entity_id": "vCZkA5ABWTh3kzuBEL_9",
    "entity_type": "alert",
    "content": "sample updated comment",
    "created_time": 1718064151148,
    "last_updated_time": 1718064745485,
    "user": "admin"
  }
}

{% include copy-curl.html %}

Search comment

다음 요청을 사용하여 알림과 연결된 기존 댓글을 쿼리하고 검색해요.

요청 예시

GET _plugins/_alerting/comments/_search
{
  "query": {
    "match_all" : {}
  }
}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "took": 14,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": ".opensearch-alerting-comments-history-2024.06.10-1",
        "_id": "xE5tBJABVWc3FrmWRL5i",
        "_version": 1,
        "_seq_no": 3,
        "_primary_term": 2,
        "_score": 1,
        "_source": {
          "entity_id": "vCZkA5ABWTh3kzuBEL_9",
          "entity_type": "alert",
          "content": "a different sample comment",
          "created_time": 1718061188191,
          "last_updated_time": null,
          "user": "admin"
        }
      },
      {
        "_index": ".opensearch-alerting-comments-history-2024.06.10-1",
        "_id": "0U6aBJABVWc3FrmWer9s",
        "_version": 3,
        "_seq_no": 9,
        "_primary_term": 3,
        "_score": 1,
        "_source": {
          "entity_id": "vCZkA5ABWTh3kzuBEL_9",
          "entity_type": "alert",
          "content": "sample updated comment",
          "created_time": 1718064151148,
          "last_updated_time": 1718064745485,
          "user": "admin"
        }
      }
    ]
  }
}

{% include copy-curl.html %}

Delete comment

다음 요청을 사용하여 알림과 연결된 특정 댓글을 제거해요.

요청 예시

DELETE _plugins/_alerting/comments/{comment-id}

{% include copy-curl.html %}

예시 응답을 보려면 펼쳐보세요 {: .text-delta}

응답 예시

{
  "_id": "0U6aBJABVWc3FrmWer9s"
}

{% include copy-curl.html %}

더 알아보기 (Learn more)