# 알러트 및 오류

## 개요

Panther API는 다음 알러트 처리 작업을 지원합니다:

* 선택적 필터를 사용하여 알러트와 오류를 나열하기
* 특정 알러트의 세부 정보를 가져오기
* 알러트와 연결된 로그 이벤트를 가져오기
* 하나 이상의 알러트 상태를 업데이트하기
* 알러트에 댓글을 추가하기
* 다음을 제공하여 하나 이상의 알러트에 사용자를 할당하거나 할당 해제하기:
  * 사용자의 ID
  * 사용자의 이메일 주소

콘솔의 API Playground 또는 GraphQL-over-HTTP API를 사용하여 Panther의 API를 호출할 수 있습니다. 이러한 방법에 대해 자세히 알아보려면 [Panther API](/ko/panther/api.md#step-1-choose-a-method-for-invoking-the-api).

핵심 알러트 및 오류 작업에 대한 GraphQL 쿼리, 변이, 엔드투엔드 워크플로 예시는 아래 섹션을 참조하세요.

## 일반적인 알러트 및 오류 작업

다음은 Panther에서 가장 일반적인 GraphQL 알러트 및 오류 작업 중 일부입니다. 이 예시는 GraphQL 클라이언트(또는 `curl`)를 사용하여 Panther의 GraphQL API를 호출할 때 전송해야 하는 문서를 보여줍니다.

#### 알러트 목록 보기

The `알러트` 쿼리에는 `입력` 객체가 필요하며 `createdAtAfter` 및 `createdAtBefore`.

{% tabs %}
{% tab title="모든 알러트의 첫 페이지" %}

```graphql
# `FirstPageOfAllAlerts`는 작업의 별칭입니다
query FirstPageOfAllAlerts {
    알러트(input: { 
      createdAtAfter: "2022-01-01T00:00:00.000Z"
      createdAtBefore: "2023-01-01T00:00:00.000Z"
    }) {
      edges {
        node { # 여기에서 더 많은 알러트 관련 필드를 요청할 수 있습니다
          id
          title
          severity
          status
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
```

{% endtab %}

{% tab title="알림의 다음 페이지" %}

```graphql
# `AnotherPageOfAllAlerts`는 작업의 별칭입니다
query AnotherPageOfAllAlerts {
    알러트(input: { 
      createdAtAfter: "2022-01-01T00:00:00.000Z",
      createdAtBefore: "2023-01-01T00:00:00.000Z",
      cursor: "{\"creationTime\":{\"B\":null,\"BOOL\":null,\"BS\":null,\"L\":null,\"M\":null,\"N\":null,\"NS\":null,\"NULL\":null,\"S\":\"2022-08-11T21:16:12Z\",\"SS\":null},\"id\":{\"B\":null,\"BOOL\":null,\"BS\":null,\"L\":null,\"M\":null,\"N\":null,\"NS\":null,\"NULL\":null,\"S\":\"6472742357f3488aeb3f48a9c5da9262\",\"SS\":null},\"alertMonthPartition\":{\"B\":null,\"BOOL\":null,\"BS\":null,\"L\":null,\"M\":null,\"N\":null,\"NS\":null,\"NULL\":null,\"S\":\"202208\",\"SS\":null}}"
    }) {
      edges {
        node { # 여기에서 더 많은 알러트 관련 필드를 요청할 수 있습니다
          id
          title
          severity
          status
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
```

{% endtab %}

{% tab title="필터링된 알림 페이지" %}

```graphql
# `FilteredPageOfAlerts`는 작업의 별칭입니다
query FilteredPageOfAlerts {
    알러트(input: { 
      createdAtAfter: "2022-01-01T00:00:00.000Z",
      createdAtBefore: "2023-01-01T00:00:00.000Z",
      심각도: [낮음], 
      상태: [OPEN] 
    }) { 
      edges {
        node { # 여기에서 더 많은 알러트 관련 필드를 요청할 수 있습니다
          id
          title
          severity
          status
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
```

{% endtab %}
{% endtabs %}

#### 알러트를 설명하기

```graphql
쿼리 AlertDetails {
    알러트(id: "FAKE_ALERT_ID") {
       id
       title
       severity
       status
    }
  }
```

#### 알러트에서 디택션 또는 시스템 오류 정보를 가져오기

```graphql
쿼리 AlertDetails {
    알러트(id: "FAKE_ALERT_ID") {
       id
       title
       severity
       원점 {
         ... 디택션 {
           id
           name
         }
         ... SystemError에서 {
           relatedComponent
           유형
         }
       }
    }
  }
```

#### 알러트와 연결된 로그 이벤트를 가져오기

```graphql
query FirstPageOfAlertEvents {
  알러트(id: "FAKE_ALERT_ID") {
    id,
    events(input: {
      cursor: "",
      pageSize: 25
    }) {
      edges {
        node
      }
      pageInfo {
        endCursor
      }
    }
  }
}
```

#### 하나 이상의 알림 상태를 업데이트하는 중

```graphql
mutation UpdateAlertStatus {
    updateAlertStatusById(
       input: {
          ids: ["FAKE_알러트_ID_1","FAKE_알러트_ID_2"]
          상태: CLOSED # 하드코딩될 때 이것이 문자열이 아니라는 점에 주목하세요(이것은 `enum`입니다)
       }
    ) {
       알림 {
         id
         status
       }
    }
  }
```

#### 알러트에 댓글을 추가하기

```graphql
mutation CreateAlertComment {
    createAlertComment(
       input: {
          알러트Id: "FAKE_ALERT_ID"
          body: "<p>이것은 HTML입니다</p>"
          형식: HTML # HTML 파싱을 비활성화하려면 PLAIN_TEXT로도 설정할 수 있습니다
       }
    ) {
       주석 {
         id
       }
    }
 
```

#### 사용자 ID를 제공하여 하나 이상의 알림에 사용자를 할당하거나 할당 해제하기

```graphql
mutation UpdateAlertsAssigneeById {
  updateAlertsAssigneeById(
    input: {
      assigneeId: "FAKE_USER_ID"
      ids: ["FAKE_알러트_ID_1","FAKE_알러트_ID_2"]
    }
  ) {
    알림 {
      assignee {
        email
        givenName
        familyName
        id
      }
    }
  }
}
```

#### 사용자 이메일 주소를 제공하여 하나 이상의 알림에 사용자를 할당하거나 할당 해제하기

```graphql
mutation UpdateAlertsAssigneeByEmail {
  updateAlertsAssigneeByEmail(
    input: {
      assigneeEmail: "fake@email.com"
      ids: ["FAKE_알러트_ID_1","FAKE_알러트_ID_2"]
    }
  ) {
    알림 {
      assignee {
        email
        givenName
        familyName
        id
      }
    }
  }
}
```

## 엔드투엔드 예제

아래에서는 [일반적인 작업](#common-operations) 예제를 바탕으로 엔드투엔드 흐름을 보여드리겠습니다.

#### 특정한 알림 집합을 찾아 다음으로 표시하기 *해결됨:*

{% tabs %}
{% tab title="NodeJS" %}

```javascript
// npm install graphql graphql-request

import { GraphQLClient, gql } from 'graphql-request';

const client = new GraphQLClient(
  'YOUR_PANTHER_API_URL', 
  { headers: { 'X-API-Key': 'YOUR_API_KEY' } 
});

// `FindAlerts`는 쿼리의 별칭입니다. 완전히 생략해도 됩니다.
const findAlerts = gql`
  query FindAlerts($input: AlertsInput!) {
  alerts(input: $input) {
    edges {
      node {
        id
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
`;

// `UpdateAlerts`는 쿼리의 별칭입니다. 완전히 생략할 수 있습니다.
const updateAlerts = gql`
  mutation UpdateAlerts($input: UpdateAlertStatusByIdInput!) {
    updateAlertStatusById(input: $input) {
      알림 {
        id
      }
    }
  }
`;

(async () => {
  try {
    
    // 모든 페이지에서 가져온 모든 알림을 담는 누산기
    let allAlerts = [];
    // 루프를 언제 종료할지 알기 위한 헬퍼
    let hasMore = true;
    // 페이지네이션 커서
    let cursor = null;

    // 더 이상 남아 있는 페이지가 없을 때까지 페이지를 계속 가져옵니다
    do {
      const queryData = await client.request(findAlerts, {
        input: {
          severities: ["LOW"],
          createdAtAfter: "2022-02-01T00:00:00.000Z",
          createdAtBefore: "2022-03-01T00:00:00.000Z",
          cursor
        }
      });

      allAlerts = [
        ...allAlerts,
        ...queryData.alerts.edges.map((edge) => edge.node)
      ];
      
      hasMore = queryData.알러트.pageInfo.hasNextPage;
      cursor = queryData.알러트.pageInfo.endCursor;
    } while (hasMore);

    // 이제 알러트를 업데이트합니다
    if (!all알러트.length) {
      console.log("해결할 알러트를 찾을 수 없습니다");
      return;
    }
    const mutationData = await client.request(updateAlerts, {
      input: {
        ids: all알러트.map((알러트) => 알러트.id),
        status: "RESOLVED"
      }
    });

    console.log(
      `${mutationData.updateAlertStatusById.alerts.length}개 알러트가 해결되었습니다!`
    );
  } catch (err) {
    console.error(err.response);
  }
})();

```

{% endtab %}

{% tab title="Python" %}

```python
# pip install gql aiohttp

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

transport = AIOHTTPTransport(
  url="YOUR_PANTHER_API_URL",
  headers={"X-API-Key": "YOUR_API_KEY"}
)

client = Client(transport=transport, fetch_schema_from_transport=True)

# `FindAlerts`는 쿼리의 닉네임입니다. 완전히 생략해도 됩니다.
find_alerts = gql(
    """
    query FindAlerts($input: AlertsInput!) {
      alerts(input: $input) {
        edges {
          node {
            id
          }
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
    """
)

# `UpdateAlerts`는 쿼리의 닉네임입니다. 완전히 생략해도 됩니다.
update_alerts = gql(
    """
    mutation UpdateAlerts($input: UpdateAlertStatusByIdInput!) {
      updateAlertStatusById(input: $input) {
        알림 {
          id
        }
      }
    }
    """
)

# 우리가 모든 페이지를 가져올 때 가져오는 모든 알러트를 보관하는 누산기
all_alerts = []
# 루프를 종료해야 할 때를 알기 위한 도우미
has_more = True
# 페이지네이션 커서
cursor = None

# 더 이상 남아 있지 않을 때까지 페이지를 계속 가져옵니다
while has_more:
    query_data = client.execute(
        find_alerts,
        variable_values={
            "input": {
                "severities": ["LOW"],
                "createdAtAfter": "2022-02-01T00:00:00.000Z",
                "createdAtBefore": "2022-03-01T00:00:00.000Z",
                "cursor": cursor
            }
        }
    )

    all_alerts.extend([edge["node"] for edge in query_data["alerts"]["edges"]])
    has_more = query_data["alerts"]["pageInfo"]["hasNextPage"]
    cursor = query_data["alerts"]["pageInfo"]["endCursor"]

# 이제 알림을 업데이트합니다
if not len(all_alerts):
    print("해결할 알림을 찾을 수 없습니다")
else:
    mutation_data = client.execute(
        update_알러트s,
        variable_values={
            "input": {
                "ids": [알러트["id"] for 알러트 in all_알러트s],
                "status": "RESOLVED"
            }
        }
    )

    print(f'완료된 {len(mutation_data["updateAlertStatusById"]["알러트"])} 알러트(s)!')
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.panther.com/ko/panther/api/graphql/alerts-and-errors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
