NerdGraphAPIを使用してアラート条件を管理できます。
ヒント
NerdGraphおよびNerdGraphエクスプローラーの使用を開始するためのヘルプについては、 NerdGraphの概要を参照してください。
NRQLの条件を作成する手順
以下の手順に従ってください。
- 作成する条件タイプを決定します( NRQL 条件しきい値タイプ を参照)。 
- 次のいずれかを実行して、関連する - policyIDを見つけます。- NerdGraphポリシーAPIを使用する.
- one.newrelic.com > All capabilities > Alerts > Alert conditions (Policies)に移動します。 ポリシーを選択します。 ポリシー名の下にある ID を見つけます。
 
- NRQL の条件タイプに適したミューテーションと関連する値を提供してください。 
ヒント
NerdGraph GraphiQLエクスプローラーは、NerdGraph NRQLConditionsAPIのフィールドごとの詳細に関する最新のドキュメントを見つけるのに最適な場所です。たとえば、「 valueFunctionフィールドは何を受け入れますか?」などの質問です。インラインのNerdGraphドキュメントで最もよく答えられます。
NRQLの静的条件
ここでは、静的な条件を作成する例を紹介します。
mutation {  alertsNrqlConditionStaticCreate(    accountId: YOUR_ACCOUNT_ID    policyId: YOUR_POLICY_ID    condition: {      name: "Low Host Count - Catastrophic"      enabled: true      nrql: {        query: "SELECT uniqueCount(host) FROM Transaction WHERE appName='my-app-name'"      }      signal: {        aggregationWindow: 60        aggregationMethod: EVENT_FLOW        aggregationDelay: 120      }      terms: {        threshold: 2        thresholdOccurrences: AT_LEAST_ONCE        thresholdDuration: 600        operator: BELOW        priority: CRITICAL      }      valueFunction: SINGLE_VALUE      violationTimeLimitSeconds: 86400    }  ) {    id    name  }}NRQLベースライン条件
ここでは、ベースラインの状態を作成する例を紹介します。
mutation {  alertsNrqlConditionBaselineCreate(    accountId: YOUR_ACCOUNT_ID    policyId: YOUR_POLICY_ID    condition: {      name: "Baseline Condition"      enabled: true      baselineDirection: UPPER_ONLY      nrql: { query: "SELECT average(duration) FROM Transaction" }      signal: {        aggregationWindow: 60        aggregationMethod: EVENT_FLOW        aggregationDelay: 120      }      terms: {        threshold: 13        thresholdDuration: 180        thresholdOccurrences: ALL        operator: ABOVE        priority: CRITICAL      }      violationTimeLimitSeconds: 86400    }  ) {    id    name    baselineDirection  }}クロスアカウント集計の作成
ここでは、静的な条件を作成する例を紹介します。
mutation {  alertsNrqlConditionStaticCreate(    accountId: YOUR_ACCOUNT_ID    policyId: YOUR_POLICY_ID    condition: {      name: "Low Host Count - Catastrophic"      enabled: true      nrql: {        query: "SELECT uniqueCount(host) FROM Transaction WHERE appName='my-app-name'"        dataAccountId: YOUR_DATA_ACCOUNT_ID      }      signal: {        aggregationWindow: 60        aggregationMethod: EVENT_FLOW        aggregationDelay: 120      }      terms: {        threshold: 2        thresholdOccurrences: AT_LEAST_ONCE        thresholdDuration: 600        operator: BELOW        priority: CRITICAL      }      violationTimeLimitSeconds: 86400    }  ) {    id    name  }}条件の更新
次の項目を完了します。
- 次のように - nrqlConditionsSearchクエリのタイプフィールドをリクエストして、既存の条件のタイプを判別します。{actor {account(id: YOUR_ACCOUNT_ID) {alerts {nrqlConditionsSearch {nrqlConditions {idtype}}}}}}- ヒント- 返される - typeは、更新ミューテーションに使用するものです。たとえば、返されるタイプが- STATICの場合、- alertsNrqlConditionStaticUpdateを使用します。返されるタイプが- BASELINEの場合は、- alertsNrqlConditionBaselineUpdateを使用します。
- 条件の - idを関連する条件タイプのミューテーションに提供します。更新できるのは、関連するタイプの条件のみであることに注意してください。
更新したいフィールドの更新変異のみを提供します。アップデートに提供していないフィールドはタッチされません。
変異点の更新
アップデートで指定したフィールドのみが変更されます。次の例では、 baselineDirectionは変更されずに返されますが、 nameは更新されます。
mutation {  alertsNrqlConditionBaselineUpdate(    id: YOUR_CONDITION_ID    accountId: YOUR_ACCOUNT_ID    condition: { name: "Your updated name" }  ) {    id    name    baselineDirection  }}NRQL条件のリストアップとフィルタリング
NRQL条件を一覧表示またはフィルタリングするには、NerdGraphでnrqlConditionsSearchクエリを使用します。
単数形のNRQL条件検索
NRQL条件APIを使用して、単一の条件を照会できます。 alert名前空間でnrqlConditionクエリを実行します。
nrqlConditionSearchクエリのタイプ固有のフィールドと同様に、これらのインラインフラグメントを使用して、NRQL条件タイプに制限されているフィールドをリクエストすることもできます。
{  actor {    account(id: YOUR_ACCOUNT_ID) {      alerts {        nrqlCondition(id: YOUR_CONDITION_ID) {          id          name          ... on AlertsNrqlStaticCondition {            valueFunction          }        }      }    }  }}説明文の更新
ここでは、NRQLのアラート条件に 説明文 を作成する手順を説明します。
- 保険契約の条件をすべて把握する。 {actor {account(id: YOUR_ACCOUNT_ID) {alerts {nrqlConditionsSearch(searchCriteria: { policyId: YOUR_POLICY_ID }) {nrqlConditions {idnamedescriptionenablednrql {query}signal {aggregationWindowaggregationMethodaggregationDelayaggregationTimer}policyIdrunbookUrlterms {operatorthresholdDurationthresholdprioritythresholdOccurrences}typeviolationTimeLimitSeconds}}}}}}
- 1つの条件の詳細を取得します。 {actor {account(id: YOUR_ACCOUNT_ID) {alerts {nrqlCondition(id: "YOUR_CONDITION_ID") {descriptionidenablednamenrql {query}signal {aggregationWindowaggregationMethodaggregationDelayaggregationTimer}policyIdrunbookUrlterms {operatorprioritythresholdthresholdDurationthresholdOccurrences}typeviolationTimeLimitSeconds}}}}}
- 説明文で変異を作成します。 - ここには空の変異テンプレートがあります。 mutation {alertsNrqlConditionStaticUpdate(accountId: YOUR_ACCOUNT_IDid: "YOUR_CONDITION_ID"condition: { description: "" }) {description}}- ここでは、記述例を含む変異の例を紹介します。 mutation {alertsNrqlConditionStaticUpdate(accountId: 123456id: "123456"condition: {description: "timestamp : {{timestamp}} \n accountId : {{accountId}} \n type : {{type}} \n event : {{event}} \n description : {{description}} \n policyId : {{policyId}} \n policyName: {{policyName}} \n conditionName : {{conditionName}} \n conditionId : {{conditionId}} \n product : {{product}} \n conditionType : {{conditionType}} \n RunbookUrl : {{runbookUrl}} \n nrqlQuery : {{nrqlQuery}} \n nrqlEventType : {{nrqlEventType}} \n targetID : {{targetId}} \n targetName : {{targetName}} \n commandLine : {{tag.commandLine}} \n entityGuid : {{tag.entityGuid}} \n entityName : {{tag.entityName}} \n fullHostname : {{tag.fullHostname}} \n instanceType : {{tag.instanceType}} \n processDisplayName : {{tag.processDisplayName}}"}) {description}}
条件の削除
alertsConditionDeleteミューテーションを使用して、任意のタイプの条件を削除できます。削除ミューテーションでのみidフィールドをリクエストできます。例えば:
mutation {  alertsConditionDelete(accountId: YOUR_ACCOUNT_ID, id: YOUR_CONDITION_ID) {    id  }}